Skip to main content
deleted 36 characters in body; edited tags; edited title; edited tags
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

How to read Reading shapefile of road segments into Python data structure to get begin and end point coordinates?

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.

Any and all help is appreciated.

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

How to read shapefile of road segments into Python data structure to get begin and end point coordinates?

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.

Any and all help is appreciated.

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

Reading shapefile of road segments into Python data structure to get begin and end point coordinates

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

corrected spelling, removed thanks
Source Link
nmtoken
  • 13.6k
  • 5
  • 38
  • 89

How can I take a shape fileshapefile that has road segments and read it into a data structure in pythonPython that I can use to get begin and end points with? 

For example x, y to x2, y2.

It's not a large shape fileshapefile, 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.

Any and all help is appreciated. Thanks.

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

How can I take a shape file 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 shape file, 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.

Any and all help is appreciated. Thanks.

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

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.

Any and all help is appreciated.

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

added 578 characters in body
Source Link
Jeff
  • 103
  • 3

How can I take a shape file 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 shape file, 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.

Any and all help is appreciated. Thanks.

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

How can I take a shape file 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 shape file, 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.

Any and all help is appreciated. Thanks.

How can I take a shape file 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 shape file, 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.

Any and all help is appreciated. Thanks.

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

Post Closed as "Duplicate" by PolyGeo, Paul, Fezter, Ian Turton
Capitalization; tags included; title readability; edited tags
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
Loading
Source Link
Jeff
  • 103
  • 3
Loading