Skip navigation
All People > Dan_Patterson > Py... blog > 2014 > September
2014

The attached pdf gives examples of how to use the somewhat hidden recfunctions module which is buried in the depths of NumPy.  To make a long story short... it facilitates working with tabular data:  This includes adding and removing fields etc etc. 

When combined with:

 NumPy , you have an incredible set of tools to perform operations and calculations on geometry and attribute data.

 

The example in the attached document outlines the process of converting a shapefile's table to a structured array.  From there, two new fields are added to contain the results of a radial sort of points about a determined center point within the point data set.  The other field contains the results of the distance to the center point from each individual point.

 

What could this be used for?  Well, in conjunction with numpy array functions...a lot.  Here are some of the things I have dabbled with.

  • sorting points: in a variety of fashions including
    • flipping them,
    • sort by X or Y, sort lexicographically,
    • sort by distance (closest/farthest),
    • radial sort etcetera
  • order points to another point order prior to forming them into polylines or polygons (ie. to form a variant of the concave hull)
  • determine the nearest/farthest-N points to a point of interest
  • produce origin-destination pairs from points
  • re-order fields
  • plus more...

The attached script reads a folder and acquires information in layer files (ie *.lyr) (select the Permalink button if the script is not visible). 
The current paths are hardcoded.  This has been changed as part of the mxd_Info.tbx toolbox
for future dissemination once ArcScripts 2.0 comes on live.

A textfile is optional output which contains the project information.

 

 

Below is some sample output:

 

Source workspace: c:\!AV_10\Toolboxes\mxd_Information\Layers

Source Layer: c:\!AV_10\Toolboxes\mxd_Information\Layers\Agriculture.lyr
  Group Layer: Agricultural  
     layer, source: AgrCap               c:\Data_Files\CarpArea\CarpAgrCap.shp

Source Layer: c:\!AV_10\Toolboxes\mxd_Information\Layers\AOI.lyr
  Feature Layer: CarpAOI       
     layer, Source: CarpAOI              c:\Data_Files\CarpArea\CarpAOI.shp

Source Layer: c:\!AV_10\Toolboxes\mxd_Information\Layers\Municipal.lyr
  Group Layer: Municipal Data
     layer, source: Official Plan        c:\Data_Files\CarpArea\CarpOfficialPlan.shp
     layer, source: Zoning               c:\Data_Files\CarpArea\CarpZoning.shp
     layer, source: Landuse 2005         c:\Data_Files\CarpArea\CarpLanduse2005.shp

....

Source Layer: c:\!AV_10\Toolboxes\mxd_Information\Layers\Transportation.lyr
  Group Layer: Transportation
     layer, source: Railroad             c:\Data_Files\CarpArea\CarpRailroad.shp
     layer, source: Roads                c:\Data_Files\CarpArea\CarpRoads.shp

Output text file created: c:\!AV_10\Toolboxes\mxd_Information\Layers\LayerInfo.txt