Select to view content in your preferred language

lines z value

1973
8
09-15-2016 10:29 AM
IanBasford
Deactivated User

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.

0 Kudos
8 Replies
NeilAyres
MVP Alum

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

IanBasford
Deactivated User

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

Ian

0 Kudos
NeilAyres
MVP Alum

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.

0 Kudos
ÁkosHalmai
Frequent 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

IanBasford
Deactivated User

Thank you Akos, much appreciated.

Ian

XanderBakker
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. 

IanBasford
Deactivated User

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

0 Kudos
NeilAyres
MVP Alum

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

0 Kudos