1

I have a river shapefile and need to ensure every vertice has a lower elevation that the previous uphill vertice.

I have converted the polylineZ to points using ET GeoWizards.

This gives me a Z value for every vertice.

I have added a field called ElevDiff.

I need to calculate the difference in elevation values from the previous vertice to the next in the attribute table.

If the value is negative, I know the line does not flow downhill at this point.

This is an easy task in Excel but I am wondering if there is a python script or easy way to calculate this using ArcGIS.

I do not have any extensions (i.e. Spatial Analyst, 3D Analyst, Newtwork Analyst).

  • Have you considered using slope for the river segments instead? A python script could do it the way you are asking (row 2 - row 1) using cursors but I would be cautious since you have to be clear which vertice is upstream/downstream, for example if you have a confluence you have two upstream points. Do you have a field for upstream ID? What version of arc are you using? – jbosq Nov 17 '14 at 21:48
  • I had thought of using slope but I didn't know how to access the vertices along a line. I am using the basic version of Arc 10.2.2. I have been trying to piece together python codes with no luck as I do not have much experience doing that. I can find where the river segment flows uphill in Excel, but would like to do this in Arc using Python. I received the lines from a fellow employee who generated them in MicroStation. I do not have a field for upstream ID. – Ashleigh Nov 18 '14 at 15:40
1

I would be extremely cautious assuming the order of the vertices (FID) in the table goes in the order of your river flow. If you had an order_ID this could be set up to use that instead. I'm not familiar with ET Geo Wizard, if your points have the elevations in a field rather than as z values replace "SHAPE@Z" with that field name.

import arcpy
from arcpy import da
vertices = "File_Name.shp"
elev1=0
with arcpy.da.UpdateCursor(vertices, ["FID", "SHAPE@Z", "ElevDiff"]) as cursor:
     for row in cursor:
          elev2 = float(row[1])
          row[2] = (elev1 - elev2)
          elev1 = elev2
          cursor.updateRow(row)
  • That worked! Thank you. ET GeoWizards is a free extension for Arc. It did add an order_ID along the line field I was able to use for the calculation. For "File_Name.shp" I had to remove the ".shp" in order for the tool to run. I am now attempting to build this as a script/tool in ArcToolbox in order to put this in a larger model. I have created a new toolbox, added the script from above, but cannot figure out how to make the "File_Name.shp" a variable. I need it to match the name of the input parameter in the script GUI. Do you have any more suggestions? – Ashleigh Nov 19 '14 at 1:42
  • Glad to hear it worked, make sure to accept the answer to show it as solved. Are you using arcpy.GetParameterAsText(0)? Or parameters[0].valueAsText in a .pyt? If its not a quick fix you might want to post your code as a new question. – jbosq Nov 19 '14 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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