I would like to convert polyline shapefile into point shapefile using Python.
First I shall create a list of polyline points from polyline shapefile and second write point shapefile from previous list.
There is a lot of pieces of code for first and second step apart but not put together.
I think problem is because of list formatting.
1 step:
fc = "polyline.shp"
array = arcpy.Array()
with arcpy.da.UpdateCursor(fc, ("OID@", "SHAPE@")) as curs:
for point in row [1].getPart(0):
# Make some points
point = arcpy.Point(point.X, point.Y)
# Put the points in the array
array.add(point)
2 step:
for x, y in array:
point= arcpy.Point(x,y)
pointGeometry = arcpy.PointGeometry(point)
array.append(pointGeometry)
arcpy.CopyFeatures_management(pointGeometry, "point.shp")
I am using Pytohn only sometimes so any help would be appreciated.
Solved! Go to Solution.
Hi Franci,
Here is an example on how to convert a polyline to a single point using python:
import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
fc = "railroads"
spatial_ref = arcpy.Describe(fc).spatialReference
pointGeometryList = []
with arcpy.da.SearchCursor(fc, ("OID@", "SHAPE@")) as curs:
for row in curs:
point = arcpy.Point(row[1].centroid.X, row[1].centroid.Y)
pointGeometry = arcpy.PointGeometry(point, spatial_ref)
pointGeometryList.append(pointGeometry)
arcpy.CopyFeatures_management(pointGeometryList, "railroadPoints")
Hi Franci,
Here is an example on how to convert a polyline to a single point using python:
import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
fc = "railroads"
spatial_ref = arcpy.Describe(fc).spatialReference
pointGeometryList = []
with arcpy.da.SearchCursor(fc, ("OID@", "SHAPE@")) as curs:
for row in curs:
point = arcpy.Point(row[1].centroid.X, row[1].centroid.Y)
pointGeometry = arcpy.PointGeometry(point, spatial_ref)
pointGeometryList.append(pointGeometry)
arcpy.CopyFeatures_management(pointGeometryList, "railroadPoints")
Thank you very much.
This is what I was looking for.
What the beauty of the Python code.
You really are a true master.
I still have to dive a lot into Python.