3

I'm still pretty new to arcpy and am still learning. I'm working on a script that has a polyline as its input. I'm able to traverse the polyline and get points at certain intervals. These intervals are represented as segments If I have segment AB, where A and B are points on the polyline, how can I traverse the points on the polyline in between A and B and grab those points to add to a shapefile?

Thanks in advance

user1898629
  • 471
  • 1
  • 5
  • 16
  • 1
    This question is similar to yours, http://gis.stackexchange.com/questions/26542/get-a-point-on-a-polyline-from-end-points-given-distance-along-poly-line – artwork21 Mar 05 '13 at 16:53

2 Answers2

2

Here is a script from a class I took that traverses a polyline and gets the XY of each point

infc = 'Polygon.shp'
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 multipoint'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):
        if pnt:
            # Print x,y coordinates of current point
            print pnt.X, pnt.Y #Here is the point
            #Add the point to your shapefile
        else:
            # If pnt is None, this represents an interior ring
            #
            print "Interior Ring:"
    partnum += 1
EmdyP
  • 300
  • 3
  • 8
1

You could write a script as per EmdyP's nice example or, alternatively you have a couple of options if you don't like scripting:

  1. If you have ArcInfo you can use the Feature Vertices To Points tool from the Data Management toolbox.
  2. If you don't have an ArcInfo licence then you can use ET_GeoWizards. You will find a Polyline to point tool in the free conversion tools set.

ET_GeoWizards (and of course the "feature vertices to points" tool) can be used in Model Builder, so if you need to extract the vertices as part of a larger process, you can pull the tool into model builder and export to Python is required.

MappaGnosis
  • 33,857
  • 2
  • 66
  • 129