Saturday, July 18, 2015

Module 8 - Working with Geometries

This week's lab used Python scripting to copy specific data variables from an existing polyline shapefile to a text file.

Screenshot of a portion of the printed text file.
The screenshot above shows the following variables extracted from a polyline shapefile (called "rivers.shp"): OID number, Vertex ID number, X coordinates, Y coordinates, and the part name. There are multiple values with the same OID and part name - that is because the polyline file contains an array of points that are connected together to form the polyline. So each part/OID number represents a vertex along each grouped polyline.

The script was short, but the syntax was a bit tricky to get the necessary variables to print correctly. In the end it was a matter of how many parenthesis were being used and recalling which variable was associated with each row called. A quick run down of the pseudocode used is as follows:


Start
    Import arcpy
    Set workspace environments
           Define workspace file path
           Enable overwriteOutput
           Define "fc" as "rivers.shp"
     Define "rivers.shp" variables to extract using SearchCursor
     Cursor in SearchCursor will look for data in the OID, SHAPE, and NAME fields
     Create text file
            Populate text file with rivers.shp data
            Define a vertex id variable
            For Search Cursor results, define the row:
                  For the Search Cursor row results.getPart():
                  print the OID, vertexid, (x, y coordinates), and NAME fields
                  write the OID, vertexid, (x, y coordinates), and NAME fields to the text file
      Close the text file
      Close the Search Cursor row
      Close the Search Cursor
END
 

No comments:

Post a Comment