Skip to main content
added 113 characters in body
Source Link
nanunga
  • 533
  • 2
  • 11

I have a layer of points and a layer of lines (shapefiles), that have been split so the lines have 2 vertices.

If a line touches one of the points I need I would require to change the direction of the line of those lines (flip), Ionly if they touch (intersect) one point. There are no lines with more than 2 vertices, There are no 2 or more points in the same position. I have seen several codes but in this site and I have not been abletried to actually flipadapt them to my lines although I am sure most lines are touching the pointscase, but not succeed. This This code runs without error but it does nothing.

I am using ArcMap 10.6.1. Standard License

enter image description here

points = []
with arcpy.da.SearchCursor(layerP, "SHAPE@") as p_cur:
    for row in p_cur:
        points.append(row[0])

lines_to_flip = []
sr = arcpy.Describe(layerD).spatialReference
##try:
with arcpy.da.UpdateCursor(layerD, ['OID@', 'SHAPE@']) as dropCursor:
    for dropRow in dropCursor:
        print str(dropRow[0])
        shpLine = dropRow[1]      
        shpLinePart = shpLine.getPart(0)
        
        first_point = shpLine.firstPoint
        last_point = shpLine.lastPoint
        for pt in points:
            if pt == first_point: # or pt == last_point:
                rPnts=arcpy.Array()
                for i in range(len(shpLinePart)): rPnts.append(shpLinePart[len(shpLinePart)-i-1])
                rPoly =arcpy.Polyline(rPnts)
                dropRow[1].shape= rPoly
                dropCursor.updateRow(dropRow)
                print "Updated"

I have a layer of points and a layer of lines (shapefiles), that have been split so the lines have 2 vertices.

If a line touches one of the points I need to change the direction of the line, I have seen several codes but I have not been able to actually flip my lines although I am sure most lines are touching the points. This code runs without error but it does nothing.

I am using ArcMap 10.6.1.

enter image description here

points = []
with arcpy.da.SearchCursor(layerP, "SHAPE@") as p_cur:
    for row in p_cur:
        points.append(row[0])

lines_to_flip = []
sr = arcpy.Describe(layerD).spatialReference
##try:
with arcpy.da.UpdateCursor(layerD, ['OID@', 'SHAPE@']) as dropCursor:
    for dropRow in dropCursor:
        print str(dropRow[0])
        shpLine = dropRow[1]      
        shpLinePart = shpLine.getPart(0)
        
        first_point = shpLine.firstPoint
        last_point = shpLine.lastPoint
        for pt in points:
            if pt == first_point: # or pt == last_point:
                rPnts=arcpy.Array()
                for i in range(len(shpLinePart)): rPnts.append(shpLinePart[len(shpLinePart)-i-1])
                rPoly =arcpy.Polyline(rPnts)
                dropRow[1].shape= rPoly
                dropCursor.updateRow(dropRow)
                print "Updated"

I have a layer of points and a layer of lines (shapefiles), that have been split so the lines have 2 vertices. I would require to change the direction of those lines (flip), only if they touch (intersect) one point. There are no lines with more than 2 vertices, There are no 2 or more points in the same position. I have seen several codes but in this site and I have tried to adapt them to my case, but not succeed. This code runs without error but it does nothing.

I am using ArcMap 10.6.1. Standard License

enter image description here

points = []
with arcpy.da.SearchCursor(layerP, "SHAPE@") as p_cur:
    for row in p_cur:
        points.append(row[0])

lines_to_flip = []
sr = arcpy.Describe(layerD).spatialReference
##try:
with arcpy.da.UpdateCursor(layerD, ['OID@', 'SHAPE@']) as dropCursor:
    for dropRow in dropCursor:
        print str(dropRow[0])
        shpLine = dropRow[1]      
        shpLinePart = shpLine.getPart(0)
        
        first_point = shpLine.firstPoint
        last_point = shpLine.lastPoint
        for pt in points:
            if pt == first_point: # or pt == last_point:
                rPnts=arcpy.Array()
                for i in range(len(shpLinePart)): rPnts.append(shpLinePart[len(shpLinePart)-i-1])
                rPoly =arcpy.Polyline(rPnts)
                dropRow[1].shape= rPoly
                dropCursor.updateRow(dropRow)
                print "Updated"
added 91 characters in body
Source Link
nanunga
  • 533
  • 2
  • 11

I have a layer of points and a layer of lines (shapefiles), that have been split so the lines have 2 vertices.

If a line touches one of the points I need to change the direction of the line, I have seen several codes but I have not been able to actually flip my lines although I am sure most lines are touching the points. This code runs without error but it does nothing.

I am using ArcMap 10.6.1.

enter image description here

points = []
with arcpy.da.SearchCursor(layerP, "SHAPE@") as p_cur:
    for row in p_cur:
        points.append(row[0])

lines_to_flip = []
sr = arcpy.Describe(layerD).spatialReference
##try:
with arcpy.da.UpdateCursor(layerD, ['OID@', 'SHAPE@']) as dropCursor:
    for dropRow in dropCursor:
        print str(dropRow[0])
        shpLine = dropRow[1]      
        shpLinePart = shpLine.getPart(0)
        
        first_point = shpLine.firstPoint
        last_point = shpLine.lastPoint
        for pt in points:
            if pt == first_point: # or pt == last_point:
                rPnts=arcpy.Array()
                for i in range(len(shpLinePart)): rPnts.append(shpLinePart[len(shpLinePart)-i-1])
                rPoly =arcpy.Polyline(rPnts)
                dropRow[1].shape= rPoly
                dropCursor.updateRow(dropRow)
                print "Updated"

I have a layer of points and a layer of lines (shapefiles), that have been split so the lines have 2 vertices.

If a line touches one of the points I need to change the direction of the line, I have seen several codes but I have not been able to actually flip my lines although I am sure most lines are touching the points. This code runs without error but it does nothing.

I am using ArcMap 10.6.1.

points = []
with arcpy.da.SearchCursor(layerP, "SHAPE@") as p_cur:
    for row in p_cur:
        points.append(row[0])

lines_to_flip = []
sr = arcpy.Describe(layerD).spatialReference
##try:
with arcpy.da.UpdateCursor(layerD, ['OID@', 'SHAPE@']) as dropCursor:
    for dropRow in dropCursor:
        print str(dropRow[0])
        shpLine = dropRow[1]      
        shpLinePart = shpLine.getPart(0)
        
        first_point = shpLine.firstPoint
        last_point = shpLine.lastPoint
        for pt in points:
            if pt == first_point: # or pt == last_point:
                rPnts=arcpy.Array()
                for i in range(len(shpLinePart)): rPnts.append(shpLinePart[len(shpLinePart)-i-1])
                rPoly =arcpy.Polyline(rPnts)
                dropRow[1].shape= rPoly
                dropCursor.updateRow(dropRow)
                print "Updated"

I have a layer of points and a layer of lines (shapefiles), that have been split so the lines have 2 vertices.

If a line touches one of the points I need to change the direction of the line, I have seen several codes but I have not been able to actually flip my lines although I am sure most lines are touching the points. This code runs without error but it does nothing.

I am using ArcMap 10.6.1.

enter image description here

points = []
with arcpy.da.SearchCursor(layerP, "SHAPE@") as p_cur:
    for row in p_cur:
        points.append(row[0])

lines_to_flip = []
sr = arcpy.Describe(layerD).spatialReference
##try:
with arcpy.da.UpdateCursor(layerD, ['OID@', 'SHAPE@']) as dropCursor:
    for dropRow in dropCursor:
        print str(dropRow[0])
        shpLine = dropRow[1]      
        shpLinePart = shpLine.getPart(0)
        
        first_point = shpLine.firstPoint
        last_point = shpLine.lastPoint
        for pt in points:
            if pt == first_point: # or pt == last_point:
                rPnts=arcpy.Array()
                for i in range(len(shpLinePart)): rPnts.append(shpLinePart[len(shpLinePart)-i-1])
                rPoly =arcpy.Polyline(rPnts)
                dropRow[1].shape= rPoly
                dropCursor.updateRow(dropRow)
                print "Updated"
deleted 113 characters in body; edited tags; edited title
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Flip Flipping line that touches certain points using Python and ArcGIS Desktop 10.6.1ArcPy

I have been struggling with something that should be simple: I have a layer of points and a layer of lines (shapefiles), that have been split so the lines have 2 vertices.

If a line touches one of the points I need to change the direction of the line, I have seen several codes but I have not been able to actually flip my lines although I am sure most lines are touching the points. This code runs without error but it does nothing.

I am using ArcGis DesktopArcMap 10.6.1. I really appreciate if someone can help me

points = []
with arcpy.da.SearchCursor(layerP, "SHAPE@") as p_cur:
    for row in p_cur:
        points.append(row[0])

lines_to_flip = []
sr = arcpy.Describe(layerD).spatialReference
##try:
with arcpy.da.UpdateCursor(layerD, ['OID@', 'SHAPE@']) as dropCursor:
    for dropRow in dropCursor:
        print str(dropRow[0])
        shpLine = dropRow[1]      
        shpLinePart = shpLine.getPart(0)
        
        first_point = shpLine.firstPoint
        last_point = shpLine.lastPoint
        for pt in points:
            if pt == first_point: # or pt == last_point:
                rPnts=arcpy.Array()
                for i in range(len(shpLinePart)): rPnts.append(shpLinePart[len(shpLinePart)-i-1])
                rPoly =arcpy.Polyline(rPnts)
                dropRow[1].shape= rPoly
                dropCursor.updateRow(dropRow)
                print "Updated"

Flip line that touches certain points using Python and ArcGIS Desktop 10.6.1

I have been struggling with something that should be simple: I have a layer of points and a layer of lines (shapefiles), that have been split so the lines have 2 vertices.

If a line touches one of the points I need to change the direction of the line, I have seen several codes but I have not been able to actually flip my lines although I am sure most lines are touching the points. This code runs without error but it does nothing.

I am using ArcGis Desktop 10.6.1. I really appreciate if someone can help me

points = []
with arcpy.da.SearchCursor(layerP, "SHAPE@") as p_cur:
    for row in p_cur:
        points.append(row[0])

lines_to_flip = []
sr = arcpy.Describe(layerD).spatialReference
##try:
with arcpy.da.UpdateCursor(layerD, ['OID@', 'SHAPE@']) as dropCursor:
    for dropRow in dropCursor:
        print str(dropRow[0])
        shpLine = dropRow[1]      
        shpLinePart = shpLine.getPart(0)
        
        first_point = shpLine.firstPoint
        last_point = shpLine.lastPoint
        for pt in points:
            if pt == first_point: # or pt == last_point:
                rPnts=arcpy.Array()
                for i in range(len(shpLinePart)): rPnts.append(shpLinePart[len(shpLinePart)-i-1])
                rPoly =arcpy.Polyline(rPnts)
                dropRow[1].shape= rPoly
                dropCursor.updateRow(dropRow)
                print "Updated"

Flipping line that touches certain points using ArcPy

I have a layer of points and a layer of lines (shapefiles), that have been split so the lines have 2 vertices.

If a line touches one of the points I need to change the direction of the line, I have seen several codes but I have not been able to actually flip my lines although I am sure most lines are touching the points. This code runs without error but it does nothing.

I am using ArcMap 10.6.1.

points = []
with arcpy.da.SearchCursor(layerP, "SHAPE@") as p_cur:
    for row in p_cur:
        points.append(row[0])

lines_to_flip = []
sr = arcpy.Describe(layerD).spatialReference
##try:
with arcpy.da.UpdateCursor(layerD, ['OID@', 'SHAPE@']) as dropCursor:
    for dropRow in dropCursor:
        print str(dropRow[0])
        shpLine = dropRow[1]      
        shpLinePart = shpLine.getPart(0)
        
        first_point = shpLine.firstPoint
        last_point = shpLine.lastPoint
        for pt in points:
            if pt == first_point: # or pt == last_point:
                rPnts=arcpy.Array()
                for i in range(len(shpLinePart)): rPnts.append(shpLinePart[len(shpLinePart)-i-1])
                rPoly =arcpy.Polyline(rPnts)
                dropRow[1].shape= rPoly
                dropCursor.updateRow(dropRow)
                print "Updated"
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
Loading
Source Link
nanunga
  • 533
  • 2
  • 11
Loading