Skip to content

Instantly share code, notes, and snippets.

@cindygis
Created June 26, 2015 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cindygis/f37339349c5ea00bd9bc to your computer and use it in GitHub Desktop.
Save cindygis/f37339349c5ea00bd9bc to your computer and use it in GitHub Desktop.
Creates centroids from closed lines by creating temporary polygons.
#
# @date 26/06/2015
# @author Cindy Williams
#
# Creates centroids from closed lines by creating temporary
# polygons.
#
# For use as as a standalone script.
#
import arcpy
arcpy.env.workspace = r"C:\Some\Arb\Folder\work.gdb"
lyr_line = "ftr_line"
lyr_point = "ftr_point"
fields = ["SHAPE@", "Name"]
cursor_ins = arcpy.da.InsertCursor(lyr_point, fields)
with arcpy.da.SearchCursor(lyr_line, fields) as cursor:
for row in cursor:
poly = arcpy.Polygon(row[0].getPart())
centroid = arcpy.PointGeometry(poly.centroid)
cursor_ins.insertRow([centroid, row[1]])
del cursor_ins
print("Script complete.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment