Created
June 26, 2015 19:42
-
-
Save cindygis/f37339349c5ea00bd9bc to your computer and use it in GitHub Desktop.
Creates centroids from closed lines by creating temporary polygons.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# @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