I'm pretty sure someone has done this before, but I'm having no luck. I'm using ArcGIS Standard version 10.2.1 and I want to convert all the vertices of a polyline or polygon to points. Essentially, I want to emulate the Feature Vertices to Points tool (which I can't use due to my ArcGIS license). I'm writing a python tool, so any answers should reflect a python/arcpy solution. Therefore, nothing like ET Geowizards, etc.
I want to maintain the fields of the original data and in addition, add X and Y fields as well as a point identifier. So, if the input fields look like this:
LABEL | TYPE | CODE abc | type1 | 3 def | type2 | 4
Then the resulting output points might look like this:
LABEL | TYPE | CODE | LONG | LAT | ID abc | type1 | 3 | 153 | -27.5 | 1 abc | type1 | 3 | 150 | -27.5 | 2 def | type2 | 4 | 151 | -30 | 1 def | type2 | 4 | 151 | -29.5 | 2 def | type2 | 4 | 151 | -30.7 | 3 def | type2 | 4 | 151 | -30 | 4
I've looked at this solution, which is fantastic and quick, but it doesn't maintain the fields of the original data. I've also looked at modifying this blog post which seems to be the most promising, but again, I can't figure out how to keep the original fields.
My code looks something like this:
fields = arcpy.ListFields(input_fc) arcpy.CreateFeatureclass_management(destination_workspace, point_file_name, "POINT") for field in fields: fieldnames.append(field.name) if field.type in ('TEXT', 'FLOAT', 'DOUBLE', 'SHORT', 'LONG', 'DATE', 'BLOB', 'RASTER', 'GUID'): arcpy.AddField_management(point_file_name, field.name, field.type, field.precision, field.scale, field.length, field.aliasName, field.isNullable) fieldnames.append("SHAPE@JSON") cursor = arcpy.da.InsertCursor(output_fc, fieldnames) with arcpy.da.SearchCursor(input_fc, fieldnames) as c: for row in c: geom = json.loads(row[-1]) for path in geom['paths']: for pt in path: cursor.insertRow(row[0:-1],pt)
It's failing with the insert cursor. The error message I'm getting is:
Traceback (most recent call last):
File "H:\Python\CreatePoints_v0_2.py", line 60, in cursor.insertRow(row[0:-1],pt) RuntimeError: Cannot find field 'LABEL'
The input feature class has a field called "LABEL". However, it's not adding that label to the created feature class.
Note, I want to convert vertices, not centroids.
I'm probably going about this the wrong way, so if anyone has ideas on how to either modify my code, or point me in another direction, I'd be appreciative.