Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

Reversing polyline direction based on raster value using ArcPy?

$
0
0

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'

Viewing all articles
Browse latest Browse all 767

Latest Images

Trending Articles



Latest Images