Skip to main content
Readability
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Reversing polyline direction based on raster value using ArcPy?

I am trying to create an arcpyArcPy script that will read a raster cell value at the start point and end point of a polyline, and flip the line based on those values. I

I do not want to create another feature class, I just want to edit a feature class in a gdban existing file geodatabase. I

I am able to get the cell values at the nodes, however, the lines are not flipping direction, so I think the problem lies within the second for loop. Is

Is there a way to do this without writing the geometries to a list and reversing the order because I have had more trouble trying to do jusjust that? Any insight is appreciated and thanks for your help! 

The code is as follows:

import arcpy

inFeatures = "Lines"
shapeName = arcpy.Describe(inFeatures).shapeFieldName
rows = arcpy.SearchCursor(inFeatures)

Raster = 'srtm2f.tif'

for row in rows:
    feat = row.getValue(shapeName)
    xy1 = feat.firstPoint
    xy2 = feat.lastPoint
    resultSTART = arcpy.GetCellValue_management(Raster, str((xy1)), "1")
    CellValueSTART = float(resultSTART.getOutput(0))
    resultEND = arcpy.GetCellValue_management(Raster, str((xy2)), "1")
    CellValueEND = float(resultEND.getOutput(0))

for features in inFeatures:
    if CellValueSTART < CellValueEND:
         arcpy.FlipLine_edit(inFeatures)
    elif CellValueSTART > CellValueEND:
        print 'Feature was correctly digitized'
    elif CellValueSTART == CellValueEND:
        print 'Feature had same elevation'

Reversing polyline direction based on raster value

I am trying to create an arcpy script that will read a raster cell value at the start point and end point of a polyline, and flip the line based on those values. I do not want to create another feature class, I just want to edit a feature class in a gdb. I am able to get the cell values at the nodes, however, the lines are not flipping direction, so I think the problem lies within the second for loop. Is there a way to do this without writing the geometries to a list and reversing the order because I have had more trouble trying to do jus that? Any insight is appreciated and thanks for your help! The code is as follows:

import arcpy

inFeatures = "Lines"
shapeName = arcpy.Describe(inFeatures).shapeFieldName
rows = arcpy.SearchCursor(inFeatures)

Raster = 'srtm2f.tif'

for row in rows:
    feat = row.getValue(shapeName)
    xy1 = feat.firstPoint
    xy2 = feat.lastPoint
    resultSTART = arcpy.GetCellValue_management(Raster, str((xy1)), "1")
    CellValueSTART = float(resultSTART.getOutput(0))
    resultEND = arcpy.GetCellValue_management(Raster, str((xy2)), "1")
    CellValueEND = float(resultEND.getOutput(0))

for features in inFeatures:
    if CellValueSTART < CellValueEND:
         arcpy.FlipLine_edit(inFeatures)
    elif CellValueSTART > CellValueEND:
        print 'Feature was correctly digitized'
    elif CellValueSTART == CellValueEND:
        print 'Feature had same elevation'

Reversing polyline direction based on raster value using ArcPy?

I am trying to create an ArcPy script that will read a raster cell value at the start point and end point of a polyline, and flip the line based on those values.

I do not want to create another feature class, I just want to edit a feature class in an existing file geodatabase.

I am able to get the cell values at the nodes, however, the lines are not flipping direction, so I think the problem lies within the second for loop.

Is there a way to do this without writing the geometries to a list and reversing the order because I have had more trouble trying to do just that? 

The code is as follows:

import arcpy

inFeatures = "Lines"
shapeName = arcpy.Describe(inFeatures).shapeFieldName
rows = arcpy.SearchCursor(inFeatures)

Raster = 'srtm2f.tif'

for row in rows:
    feat = row.getValue(shapeName)
    xy1 = feat.firstPoint
    xy2 = feat.lastPoint
    resultSTART = arcpy.GetCellValue_management(Raster, str((xy1)), "1")
    CellValueSTART = float(resultSTART.getOutput(0))
    resultEND = arcpy.GetCellValue_management(Raster, str((xy2)), "1")
    CellValueEND = float(resultEND.getOutput(0))

for features in inFeatures:
    if CellValueSTART < CellValueEND:
         arcpy.FlipLine_edit(inFeatures)
    elif CellValueSTART > CellValueEND:
        print 'Feature was correctly digitized'
    elif CellValueSTART == CellValueEND:
        print 'Feature had same elevation'
edited tags
Link
Chris W
  • 15.8k
  • 2
  • 29
  • 47
Source Link

Reversing polyline direction based on raster value

I am trying to create an arcpy script that will read a raster cell value at the start point and end point of a polyline, and flip the line based on those values. I do not want to create another feature class, I just want to edit a feature class in a gdb. I am able to get the cell values at the nodes, however, the lines are not flipping direction, so I think the problem lies within the second for loop. Is there a way to do this without writing the geometries to a list and reversing the order because I have had more trouble trying to do jus that? Any insight is appreciated and thanks for your help! The code is as follows:

import arcpy

inFeatures = "Lines"
shapeName = arcpy.Describe(inFeatures).shapeFieldName
rows = arcpy.SearchCursor(inFeatures)

Raster = 'srtm2f.tif'

for row in rows:
    feat = row.getValue(shapeName)
    xy1 = feat.firstPoint
    xy2 = feat.lastPoint
    resultSTART = arcpy.GetCellValue_management(Raster, str((xy1)), "1")
    CellValueSTART = float(resultSTART.getOutput(0))
    resultEND = arcpy.GetCellValue_management(Raster, str((xy2)), "1")
    CellValueEND = float(resultEND.getOutput(0))

for features in inFeatures:
    if CellValueSTART < CellValueEND:
         arcpy.FlipLine_edit(inFeatures)
    elif CellValueSTART > CellValueEND:
        print 'Feature was correctly digitized'
    elif CellValueSTART == CellValueEND:
        print 'Feature had same elevation'