Extracting number of vertices in each polygon?
The easiest way to do this is to add a new integer field to the attribute table of the parcels layer. Then, run field calculator with the following expression:
!Shape!.pointCount-!Shape!.partCount
The !Shape!.pointCount
returns the total number of vertices in the feature. However, the first vertex of each part is repeated at the end, in order to close the feature. To handle this, subtract one vertex for each part using -!Shape!.partCount
.
Note that you will have to use the Python parser for this expression to work.
dmahr provided a good solution to count vertices. For a non-programmatic way to label each point with the XY coords, try the following workflow:
- Feature Vertices to Points
- Add two new fields (type: double) in the new point FC "X", "Y"
- Calculate geometry. Right click field > Calculate Geometry... > X Coordinate of Point (repeat for Y field)
- Add another field "XY" (type: Text)
Calculate "XY" field in field calculator, where XY =
str(!x!) + " , " + str(!y!)
Label features. Right click layer > Labels > Label Field: XY
This produces the following results:
You can also perform these actions programmatically using explode_to_points
with a search cursor (as a start).
Deconstruct a feature into its individual points or vertices. If explode_to_points is set to True, a multipoint feature with five points, for example, is represented by five rows.
(The default value is False)
arcpy.da.SearchCursor (in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {sql_clause})
The code below combines the other answers and adds a bit to number the vertices.
import arcpy
arcpy.env.workspace = "in_memory"
#paths
fc = r"...\polygons"
fc_out = r"...\vertices"
arcpy.MakeFeatureLayer_management(fc, "lyr")
# add fields if needed
for FIELD in ["DRAW_ORDER", "COUNT"]:
if FIELD not in [field.name for field in arcpy.ListFields(fc)]:
try:
arcpy.AddField_management("lyr", FIELD, "SHORT")
except Exception as e:
print e
# get the number of points minus overlapping (@dmahr - GSE)
arcpy.CalculateField_management("lyr", "COUNT", "!Shape!.pointCount-!Shape!.partCount", "PYTHON")
# dict to iterate and check count
OIDS = {}
for row in arcpy.da.SearchCursor("lyr", ["OBJECTID", "COUNT"]):
OIDS[row[0]] = row[1]
del row
# get vertices as points and add XY (@Aaron - GSE)
arcpy.FeatureVerticesToPoints_management("lyr", fc_out)
arcpy.AddXY_management(fc_out)
# start adding a number to the points
for OID in OIDS:
order_count = 1
rows = arcpy.da.UpdateCursor(fc_out, ["DRAW_ORDER", "COUNT"], "ORIG_FID = %d"%OID)
for row in rows:
# will leave the overlapping as NULL
if order_count <= OIDS[OID]:
row[0] = order_count
rows.updateRow(row)
order_count += 1
## # this can set the overlapping to 0 or some unique value (999)
## else:
## row[0] = 0
## rows.updateRow(row)
The points are labelled in drawing order. The last point (under the first) will have no label and can be deleted by selecting all points that have Null, or unique, "DRAW_ORDER" values if not needed for reconstruction. A definition query can be used to remove the overlapping points from display.
XY data is present, but I will leave that to your labeling/displaying desires. See Aaron's answer about adding a XY field for labeling.
I was also toying with FeatureClass to numpy array, but I finished this first.