1

Background:

I have a polyline feature class of about 4000 street centerline segments for which I would like to add data on what streets the segments intersect with.

I would like to add some new fields to my dataset that capture information on what street the polyline segment begins at and what street the polyline segment ends at (essentially the intersections)

What I have so far:

I wrote a quick Python script to calculate these values by doing Select By Location -> Boundary Touches:

# Import arcpy and set path to data
import arcpy
arcpy.env.workspace = "c:\Users\me\Documents\ArcGIS\Default.gdb"

#create a master search layer to encompass all streets. 
searchLayer = arcpy.MakeFeatureLayer_management('StreetsCP', 'searchLayer') 
#set the fields that we are going to be updating
fields = ('FULL_NAME', 'OBJECTID', 'StreetFrom', 'StreetTo')
#create a cursor to encompass all rows in streets
with arcpy.da.UpdateCursor('StreetsCP', fields) as uCursor:
        #loop over every row in streets
        for uRow in uCursor:
            #set where clause to create a feature layer from the row  
            whereClause = '"OBJECTID" = ' + str(uRow[1])
            #create feature layer consisting of just the row we are on
            inputLayer = arcpy.MakeFeatureLayer_management('StreetsCP', 'inputLayer', whereClause) 

            #select the streets that touch the boundary of the street we are on
            arcpy.SelectLayerByLocation_management(searchLayer, "BOUNDARY_TOUCHES", inputLayer, "", "NEW_SELECTION")

            touchingStreets = []
            uniqueStreets = []

            #populate the unique streets list
            with arcpy.da.SearchCursor(searchLayer, 'FULL_NAME') as sCursor:
                for sRow in sCursor:
                    if sRow[0] != uRow[0]:
                        touchingStreets.append(sRow[0])
                #eliminate duplicate street values
                uniqueStreets = list(set(touchingStreets))
            if len(uniqueStreets) <= 2:  
                i = 2
                for street in uniqueStreets:   
                     uRow[i] = street
                     i += 1  
                uCursor.updateRow(uRow)

            arcpy.Delete_management("inputLayer")

The Problem:

The issue I am running into is the directionality of the street. In my street data I have address directionality using Left From/Left To/Right From/Right To, like in the below table:

Example Table

The Street From and Street To should reflect this same directionality. What are some ideas for capturing the directionality of the street?

Some ideas I've been exploring:

  • Is there something exposed through ArcObjects that stores the endpoint and beginning point of a polyline using these metrics that I can use to select by location?

  • Can I somehow determine the directionality just in ArcPy?

  • As a last resort, Network Analyst might be able to offer me this functionality, but due to not having used Network Analyst before the ramp up time may be too much for my purposes.

  • If there is functionality that may help me in GRASS/QGIS I'd be willing to explore that as well.

  • I also have an "intersections" point file that could be used.

2
  • If you have digitized your streets in the correct direction - you can convert the line ends (either or both start and end) to points - then do a select by location analysis to get the from and to streets.
    – dklassen
    Commented May 7, 2014 at 16:08
  • They are in fact digitized in the correct direction - I think I am going to use ArcPy's geometry reader currently to pass in the array of points that make up the polyline. Not sure if I will have to create a whole new feature layer just for each point for ArcPy's Select by Location though.
    – Conor
    Commented May 7, 2014 at 16:20

1 Answer 1

3

I would loop through the line features - and on each of them use:

arcpy.FeatureVerticesToPoints_management (in_features, out_feature_class, "START")
arcpy.FeatureVerticesToPoints_management (in_features, out_feature_class, "END")

then when I have the start point - I would use the arcpy.SelectByLocation_management() tool to find out the line segements touching the point - from here - you can loop through and get the name or ID of a touching line. This can all be done with an "in_memory" dataset as opposed to writing them out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.