Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am working on a small script using ArcMap10/arcpy to generate a upstream-downstream uniqueid for a polyline feature class using point id's that fall on the starting point and ending point of a line.

For example, if pt with an id of DEIRS00120 is located at the starting point of a line and if a pt with an id of DEIRS00125 is located at the end point of the line, I would like to assign the line the uniqueid of DEIRS00120-DEIRS00125.

My problem is that I need some ideas on how to accomplish this.

Here's what I thought would work: 1. Generate a python dictionary using the point id's as a value and the XY location as key: {'123456.765,827393.613737': 'DEIRS00120' } 2: Generate another python dictionary containing the XY Start Point location of the polyline as a key and the objectid as a field: {'123456.765,827393.613737': 1} Do the same for the XY End Point. 3: Call the ids of the points using the start and end location of the line.

What flubbed this thinking up is that if line branches, the start points (or end points) are the same at the branch and cannot be used as a python key.

Any ideas on how I could accomplish this?

Thanks

share|improve this question

1 Answer 1

The solution to this situation depends on your point feature class. Are there only points at the beginning and end of lines, or are there other points in the feature class as well?

If there are only points at the ends of lines, then iterating through your line feature class with an UpdateCursor and performing selections will do the trick. Try something like this:

from arcpy import *

#Line feature class
InLineFC = r"Line\feature\class\full\path" 
KeyFieldName = "KEY" #Name of field in line feature class to be
                     #populated with key value

#Point feature class
InPointFC = r"Point\feature\class\full\path"
PointIDfld = "ID" #Name of field in point feature class that
                  #has ID value


#Make feature layers to allow selection
MakeFeatureLayer_management (InLineFC, "linelyr")
MakeFeatureLayer_management (InPointFC, "pntlyr")

#Get OID Field Name of line layer
OIDFldName = Describe ("linelyr").OIDFieldName

#Iterate through line features
cursor = da.UpdateCursor ("linelyr", ["OID@", KeyFieldName])
for row in cursor:

    ###Make Selection

    #SQL to select individual line features
    sql = '"{0}" = {1}'.format (OIDFldName, str(row[0]))
    #Select feature with sql
    SelectLayerByAttribute_management ("linelyr", "", sql)
    #One line feature is now selected. Select intersecting points
    SelectLayerByLocation_management ("pntlyr", "", "linelyr")

    ###Get point IDs

    #End points should now be selected. Iterate through points and obtain IDs
    #Empty list for point IDs
    pntIDs = []
    pntcursor = da.SearchCursor ("pntlyr", [PointIDfld])
    for pntrow in pntcursor:
        #Add point ID to list
        pntIDs.append (pntrow[0])
    del pntcursor

    ###Create unique ID based on point IDs

    lineID = "-".join (pntIDs)

    ###Update line ID

    row[1] = lineID
    cursor.updateRow(row)

del cursor

If you don't have exactly two points per line, you will need to first perform a FeatureVerticesToPoints. Use DANGLE as your point location, and then perform a similar geoprocess, selecting input points by your dangle points to determine those that represent start and end points.

I hope this helps!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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