Skip to main content
Turned title into question
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

How to check if a verticevertex exists (on a polyline) based on the location of a point layer using ArcPy? (using arcpy...)

Adjusted psuedo code
Source Link
Jason Miller
  • 1.5k
  • 1
  • 12
  • 25

Using ArcGIS for Desktop Advanced 10.1 (with all extensions)

I am building a centerline network that will be used by a MapObjects program to do routing based on "turns at any vertex" (as opposed to turns only at endpoints...) What I am trying to do is identify overpasses/underpasses that have a shared vertex with the road that crosses it (but is not considered an intersection) If there is a shared vertex, then the mapping program will (incorrectly) make a turn where there is not one physically possible. What I've done so far is build a topology using the "Must not intersect (Line)" rule. I export the errors to a feature class, and now I have a bunch of points at intersections that I need to check. What I'm wondering is if there is a way to cycle through each point and check to see if a vertex exists where the centerline intersects the point. Here's what I've come up with so far...

import arcpy

fcPoints = "C:/MyPointLayer..."
fcCenterlines = "C:/MyCenterlineLayer..."

rows = arcpy.UpdateCursor(fcPoints)
for row in rows:
    # For each point, select the centerlines that touch (intersect) that point
    arcpy.SelectLayerByAttribute_management(fcPoints, "NEW_SELECTION", "\"OBJECTID\" = " + str(row.getValue("OBJECTID")))
    arcpy.SelectLayerByLocation_management(fcCenterlines, "INTERSECT", fcPoints)
    # Need code here to cycle through each selected centerline and determine if a vertex exists at the point's SHAPE@XY location?
    #PSEUDO CODE:
    for each line in selection:
        vertexExists = False
        for each vertex in line:
            if vertex.xy == point.xy:
                vertexExists === trueTrue
 
        # If there is a matching vertice, then update a field in the point fc to "FLAG" it...
        if vertexExists == True:
            row.setValue("FLAG", "CHECK THIS INTERSECTION")
            cursor.updateRow(row)
        

Or.... is there an easier way...? I would be looking at about 2000 points to check...

Using ArcGIS for Desktop Advanced 10.1 (with all extensions)

I am building a centerline network that will be used by a MapObjects program to do routing based on "turns at any vertex" (as opposed to turns only at endpoints...) What I am trying to do is identify overpasses/underpasses that have a shared vertex with the road that crosses it (but is not considered an intersection) If there is a shared vertex, then the mapping program will (incorrectly) make a turn where there is not one physically possible. What I've done so far is build a topology using the "Must not intersect (Line)" rule. I export the errors to a feature class, and now I have a bunch of points at intersections that I need to check. What I'm wondering is if there is a way to cycle through each point and check to see if a vertex exists where the centerline intersects the point. Here's what I've come up with so far...

import arcpy

fcPoints = "C:/MyPointLayer..."
fcCenterlines = "C:/MyCenterlineLayer..."

rows = arcpy.UpdateCursor(fcPoints)
for row in rows:
    # For each point, select the centerlines that touch (intersect) that point
    arcpy.SelectLayerByAttribute_management(fcPoints, "NEW_SELECTION", "\"OBJECTID\" = " + str(row.getValue("OBJECTID")))
    arcpy.SelectLayerByLocation_management(fcCenterlines, "INTERSECT", fcPoints)
    # Need code here to cycle through each selected centerline and determine if a vertex exists at the point's SHAPE@XY location?
    #PSEUDO CODE:
    for each line in selection:
        vertexExists = False
        for each vertex in line:
            if vertex.xy == point.xy:
                vertexExists == true
 
        # If there is a matching vertice, then update a field in the point fc to "FLAG" it...
        row.setValue("FLAG", "CHECK THIS INTERSECTION")
        cursor.updateRow(row)
        

Or.... is there an easier way...? I would be looking at about 2000 points to check...

Using ArcGIS for Desktop Advanced 10.1 (with all extensions)

I am building a centerline network that will be used by a MapObjects program to do routing based on "turns at any vertex" (as opposed to turns only at endpoints...) What I am trying to do is identify overpasses/underpasses that have a shared vertex with the road that crosses it (but is not considered an intersection) If there is a shared vertex, then the mapping program will (incorrectly) make a turn where there is not one physically possible. What I've done so far is build a topology using the "Must not intersect (Line)" rule. I export the errors to a feature class, and now I have a bunch of points at intersections that I need to check. What I'm wondering is if there is a way to cycle through each point and check to see if a vertex exists where the centerline intersects the point. Here's what I've come up with so far...

import arcpy

fcPoints = "C:/MyPointLayer..."
fcCenterlines = "C:/MyCenterlineLayer..."

rows = arcpy.UpdateCursor(fcPoints)
for row in rows:
    # For each point, select the centerlines that touch (intersect) that point
    arcpy.SelectLayerByAttribute_management(fcPoints, "NEW_SELECTION", "\"OBJECTID\" = " + str(row.getValue("OBJECTID")))
    arcpy.SelectLayerByLocation_management(fcCenterlines, "INTERSECT", fcPoints)
    # Need code here to cycle through each selected centerline and determine if a vertex exists at the point's SHAPE@XY location?
    #PSEUDO CODE:
    for each line in selection:
        vertexExists = False
        for each vertex in line:
            if vertex.xy == point.xy:
                vertexExists = True
 
        # If there is a matching vertice, then update a field in the point fc to "FLAG" it...
        if vertexExists == True:
            row.setValue("FLAG", "CHECK THIS INTERSECTION")
            cursor.updateRow(row)
        

Or.... is there an easier way...? I would be looking at about 2000 points to check...

edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
Source Link
Jason Miller
  • 1.5k
  • 1
  • 12
  • 25
Loading