How can I take a shapefile that has road segments and read it into a data structure in Python that I can use to get begin and end points with?
For example x, y to x2, y2.
It's not a large shapefile, just a one with roads for my county. I've previously worked with argisscripting at ArcGIS 9.3 but that was a couple years ago and now I'm rusty and using ArcGIS 10.1.
import arcpy
infc = "C:\\Users\\Jeff\\Downloads\\tl_2013_30063_edges\\tl_2013_30063_edges.shp"
for row in arcpy.da.SearchCursor(infc, ["OID@", "SHAPE@"]):
# Print the current line ID
print("Feature {0}:".format(row[0]))
#Set start point
startpt = row[1].firstPoint
#Set Start coordinates
startx = startpt.X
starty = startpt.Y
#Set end point
endpt = row[1].lastPoint
#Set End coordinates
endx = endpt.X
endy = endpt.Y
This is what one of the features looks like.
FID 16992
Shape Polyline
STATEFP 30
COUNTYFP 063
TLID 205238472
TFIDL 217915003
TFIDR 217914215
MTFCC S1400
FULLNAME S 9th St W
infc = r"C:\temp\test.shp"
- the example code is from when writing a Python script tool that takes the input feature class as a parameter from the tool dialog.