lines z value

928
8
09-15-2016 10:29 AM
Highlighted
New Contributor II

I have lines representing streams that have z values, unfortunately not all the z values flow downhill, there are points within the line that flow uphill, is there a way in python to find these points and flatten them out?

Thank You.

Reply
0 Kudos
8 Replies
Highlighted
MVP Frequent Contributor

Do you have access to the original dem from which these stream lines were derived?

Because I think the best solution would be to create a hydrologically correct dem first, then derive the stream lines, using the work flow outlined here :

an-overview-of-the-hydrology-tools

Highlighted
New Contributor II

Thanks Neil, unfortunately I do not have access to the DEM, so I am looking for a vector solution.

Ian

Reply
0 Kudos
Highlighted
MVP Frequent Contributor

Tricky....

A python approach would be fraught with difficulties like Z this side and that of a particular point. Which is "correct"?

Do the lines at least go in the correct direction ie down stream? Not saying that you would get a programmatic solution here though.

Would be difficult in my estimation.

Reply
0 Kudos
Highlighted
Occasional Contributor

Replace "InvalidLine" to your featureclass' name. It's dirty but working.

#For singlepart polylines only!
#Polyline must be digitised downstream! (StartPoint's Z value must be higher than End Point's Z value!)
with arcpy.da.UpdateCursor("InvalidLine", "SHAPE@") as features:
     for feature in features:
          newarray = arcpy.Array()
          lastZ = 9999999.99
          for part in feature:
               for points in part:
                    for point in points:
                         if point.Z <= lastZ:
                              newarray.add(point)
                              lastZ = point.Z
          newpoly = arcpy.Polyline(newarray, None, True)
          features.updateRow([newpoly])‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Ákos Halmai

Highlighted
New Contributor II

Thank you Akos, much appreciated.

Ian

Highlighted
Esri Esteemed Contributor

This approach will not correct Z values of existing points, but "remove" those points that have a Z value that is not below the previous Z value. This means that your output XY locations of the line will be different (it will loose details).

You may want to use a different approach as outlined here: https://community.esri.com/thread/181945-interpolate-missing-z-values-in-polyline 

It interpolates the invalid Z values using the M position of the vertice on the line and using the valid Z values. You will need to adapt it a bit to recognize and mark the invalid z values. 

Highlighted
New Contributor II

Thank you all for your input, the code scripts are helpful, I had started editing Akos code to address deleting vertices, I'm not fast at python, but when I get it working will post code here. 

Ian

Reply
0 Kudos
Highlighted
MVP Frequent Contributor

Good luck. Reasoned questions always accepted.....

Reply
0 Kudos