I am trying to create an array of Z and M values for vertices from a polyline (Z and M enabled) feature class. Some of the vertices do no have M values/geometry and I wish to exclude them from the array.
import arcpy from arcpy import env ##import math #another way I was testing....commented-out import numpy as np print "Modules imported." # Set environment settings arcpy.env.overwriteOutput = True arcpy.env.workspace = r"E:\Projects\HaulRd\SpatialData" arcpy.env.scratchWorkspace = r"E:\Projects\HaulRd\SpatialData\Scratch" arcpy.env.outputZFlag = "Same As Input" arcpy.env.outputMFlag = "Same As Input" print "Workspaces and environments set." # Set local variables infc = "HaulRd_XS_linesZM_test.shp" ##x=float('nan') # another way I was testing.....commented out # Identify the geometry field # desc = arcpy.Describe(infc) shapefieldname = desc.ShapeFieldName # Create search cursor # rows = arcpy.SearchCursor(infc) # Enter for loop for each feature/row # for row in rows: # Create the geometry object # feat = row.getValue(shapefieldname) # Print the current feature's ID # print "Feature %i:" % row.getValue(desc.OIDFieldName) partnum = 0 # Step through each part of the feature # for part in feat: # Print the part number # print "Part %i:" % partnum # Step through each vertex in the feature # for pnt in feat.getPart(partnum): #exclude records with 'nan' (i.e. null) if pnt[~np.isnan(pnt).any(1)] # Print z,m coordinates of current point # print pnt.Z, pnt.M else: # If pnt is None, this represents an interior ring # print "Interior Ring:" partnum += 1
I have made a number of attempts based on content I found in:
But I can't seem to figure-out how the syntax (could also be a logical problem) fits into my code.
Eventually, my temporary array will be be used to feed creation of vertical line graphs (see related post:
I am using Python v2.6.5.