0

I would like to convert the vertices of an existing Polyline-Shapefile into a Point Shapefile, but I have a problem with reading out the geometries of the polylines (getPart()).

    outpath = os.path.split(SHPInput)
    Temp_PointShp = gp.CreateFeatureclass(outpath[0],"SohlPoint_temp.shp", "POINT",None, "ENABLED", "ENABLED") # empty PointShapefile
    gp.addfield_management(Temp_PointShp, "Z_Value", "DOUBLE")
    gp.addfield_management(Temp_PointShp, "M_Value", "DOUBLE")


    Srows = gp.SearchCursor(SHPInput)   # Cursor 
    Irows = gp.InsertCursor(Temp_PointShp)

    row = Srows.next()
    while row: # for every row of the Polyline-Shapefile
        Geom = row.shape # Geometry     
        OArray = Geom.getPart() # Array with Array

        PArray = OArray.getPart(0) # Array with Points


        Points = OArray.next()
        while Points: # for all vertices...

            row = Irows.NewRow() # create new row in Point-Shapefile


            row.X = Points.X
            row.Y = Points.Y
            row.Z = Points.Z
            row.M = Points.M
            Irows.InsertRow(row)

            Points = PArray.next()


        row = Srows.next()
1
  • 1
    What version and license level of ArcGIS Desktop are you using? What happens when you run this code?
    – PolyGeo
    Aug 12, 2016 at 7:18

1 Answer 1

1

You can use the "Feature Vertices to Points" tool, which will convert all vertices of the polyline into points. There are a number of "Point Type" options, which you can find out more about here: http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/feature-vertices-to-points.htm

In order to get the coordinates of your points, you can add a lat and long field within your new point shapefile and calculate geometry. Go to the attribute table > add fields > lat/long > right click the field > calculate geometry. Here, Lat = Y coordinate of point, and Long = X coordinate of point.

Using arcpy you might use:

import arcpy
arcpy.env.workspace = r"path/to/workspace"

polyline = r"path/to/polyline"
polyline_vertices = arcpy.FeatureVerticesToPoints_management(polyline, "polyline_vertices", "ALL")

latfield = arcpy.AddField_management(polyline_vertices, "Lat", "DOUBLE")
arcpy.CalculateField_management(polyline_vertices, "Lat", "!Shape.Centroid.X!", "PYTHON_9.3")

longfield = arcpy.AddField_management(polyline_vertices, "Long", "DOUBLE")
arcpy.CalculateField_management(polyline_vertices, "Long", "!Shape.Centroid.Y!", "PYTHON_9.3")
2
  • webhelp.esri.com/arcgisdesktop/9.3/… suggests that the license level being used by the asker may affect whether this will provide a solution.
    – PolyGeo
    Aug 12, 2016 at 7:38
  • True. Lets see what the OP comes back with re: Desktop version and license.
    – MacroZED
    Aug 12, 2016 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.