I'm writing a Python code to read the points in a polygon shapefile and save them to a point shapefile.
I'm not sure about my approach so if you have a better idea (even if it is totally different from mine) please let me know.
So first I made a text file and stored the points' (x,y) in that .txt file. then I tried to make a point shapefile from the text file but it gave an error.
Here is the code (just the last part):
creat point shape-file from text file import fileinput import string import os env.overwriteOutput=True outpath="C:/roadpl" newfc="newpoint.shp" arcpy.CreateFeatureclass_management(outpath, newfc, "Point") infile="C:/roadpl/roadL5.txt" cursor=arcpy.da.InsertCursor(newfc, ["SHAPE@"]) array=arcpy.Array() for line in fileinput.input(infile): point.X, point.Y = line.split() line_array.add(point) cursor.insertRow([arcpy.Point(array)]) fileinput.close() del cursor
Here is the error:
Traceback (most recent call last): File "C:\roadpl\P_Code_L5", line 49, in <module> point.X, point.Y = line.split() File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\_base.py", line 87, in _set return setattr(self._arc_object, attr_name, cval(val)) RuntimeError: Point: Input value is not numeric
I made the input file (.txt file) from a polygon shapefile using:
cur = arcpy.SearchCursor("C:/roadpl/L5P.shp", ["SHAPE@"]) f=open("C:/roadpl/roadL5.txt", "w") for row in cur: geom = row.shape row = geom.getPart() for part in row: for point in part: print >>f, (point.X, point.Y) f.close()