-1

This question already has an answer here:

I have a simple point feature class and line feature class. Each point has an ID. The Line feature class has a "Start Point ID" and "End Point ID" field, both of which are currently empty. The line start/end points are snapped to points.

I'd like to do some sort of spatial join to populate the Start Point ID and End Point ID fields of the line based on what points the line is touching.

Each line feature is a simple two-vertex line, no polylines.

Any ideas on how to accomplish this without just copying and pasting ids?

enter image description here

marked as duplicate by FelixIP, PolyGeo arcgis-desktop May 16 '18 at 19:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

By postgres, tried:

create table test.point
as select (st_dumppoints(geom)).geom
from test.base a;

Then in Qgis insert $id on a new column. That must do put a serial number to each point in order that was create

0

You can use Python and arcpy:

import arcpy

#Change to match your data and field names
arcpy.env.workspace = r'C:\database.gdb'

lines = 'Lines'
startfield = 'StartID'
endfield = 'EndID'

points = 'Points'
pointidfield = 'PointID'

arcpy.MakeFeatureLayer_management(points,'plyr')
with arcpy.da.UpdateCursor(lines,['SHAPE@',startfield,endfield]) as cursor:
    for row in cursor:
        for part in row[0]:
            startpoint = arcpy.PointGeometry(part[0])
            endpoint = arcpy.PointGeometry(part[-1])
            for i in [[startpoint,1],[endpoint,2]]:
                arcpy.SelectLayerByLocation_management(in_layer='plyr',select_features=i[0])
                row[i[1]] = [f[0] for f in arcpy.da.SearchCursor('plyr',pointidfield)][0]
        cursor.updateRow(row)

enter image description here

  • Thank you! That looks like exactly what I want, but I'm getting an error: "RuntimeError: Array: Error in getting object from array'' on the line "endpoint = arcpy.PointGeometry(part[-1])" Any ideas? – DCooper May 16 '18 at 23:29

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