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.
Good luck. Reasoned questions always accepted.....
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
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.
Thank you Akos, much appreciated.
Replace "InvalidLine" to your featureclass' name. It's dirty but working.
<SPAN class="comment token">#For singlepart polylines only!</SPAN> <SPAN class="comment token">#Polyline must be digitised downstream! (StartPoint's Z value must be higher than End Point's Z value!)</SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"InvalidLine"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SHAPE@"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> features<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> feature <SPAN class="keyword token">in</SPAN> features<SPAN class="punctuation token">:</SPAN> newarray <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> lastZ <SPAN class="operator token">=</SPAN> <SPAN class="number token">9999999.99</SPAN> <SPAN class="keyword token">for</SPAN> part <SPAN class="keyword token">in</SPAN> feature<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> points <SPAN class="keyword token">in</SPAN> part<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> point <SPAN class="keyword token">in</SPAN> points<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">if</SPAN> point<SPAN class="punctuation token">.</SPAN>Z <SPAN class="operator token"><=</SPAN> lastZ<SPAN class="punctuation token">:</SPAN> newarray<SPAN class="punctuation token">.</SPAN>add<SPAN class="punctuation token">(</SPAN>point<SPAN class="punctuation token">)</SPAN> lastZ <SPAN class="operator token">=</SPAN> point<SPAN class="punctuation token">.</SPAN>Z newpoly <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Polyline<SPAN class="punctuation token">(</SPAN>newarray<SPAN class="punctuation token">,</SPAN> None<SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN> features<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>newpoly<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Ákos Halmai
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.
Thanks Neil, unfortunately I do not have access to the DEM, so I am looking for a vector solution.
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
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.