Last active
August 29, 2015 14:18
-
-
Save cindygis/6a8b574eae7e388c0d98 to your computer and use it in GitHub Desktop.
Creates a point feature class for points derived from polyline methods
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 01/04/2015 | |
# @author Cindy Williams | |
# | |
# Creates a point feature class for points derived from | |
# various polyline methods. This example uses polyline.firstPoint | |
# but can be replaced with any of the polyline methods which | |
# generate points. | |
# | |
# For use as a standalone script. | |
# | |
import arcpy | |
from arcpy import env | |
env.workspace = r"C:\Some\Arb\Folder\work.gdb" | |
lyr_line = arcpy.management.MakeFeatureLayer("ftr_line") | |
# Get spatial reference of line feature class | |
sr = arcpy.Describe(lyr_line).spatialReference.exporttostring() | |
pts = [] # List to hold points | |
fields = ["SHAPE@", "FTR_ID", "FTR_NAME"] | |
# Create a point feature class based on line feature class | |
arcpy.management.CreateFeatureclass(env.workspace, "ftr_point", "POINT", lyr_line, "#","#", sr) | |
lyr_pnt = arcpy.management.MakeFeatureLayer("ftr_point") | |
# Loop over line features using a search cursor | |
with arcpy.da.SearchCursor(lyr_line, fields, "#", sr) as cursor: | |
for row in cursor: | |
pts.append([arcpy.PointGeometry(row[0].firstPoint, sr, row[1], row[2]]) | |
print("Appended first point for " + row[2]) | |
# Insert points into point feature class using an insert cursor | |
curs = arcpy.da.InsertCursor(lyr_pnt, fields) | |
for pt in pts: | |
curs.insertRow(pt) | |
del curs | |
print("Script complete.") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment