Select to view content in your preferred language

Code that Generates 3D Lengths for Route M Values

2919
10
10-27-2011 04:26 PM
RichardFairhurst
MVP Honored Contributor
In the Desktop forum this thread has code I have written to assign 3D Lengths to the M values of polylines that are both Z and M aware.  The code works but it is very skelatal and basic at this point.

I am looking for others interested in testing the code and offering comments on what user options should be added to the code.  For example, I could rewrite the code to work on a Feature Selection, or allow a user specified offset to the beginning measure, or give options for how gaps will be handled on multi-part routes.  Also the code needs a user interface.  I was thinking about an Add-In or if someone could help me do the basic function in Python it could be a geoprocessing script tool.

Please lend me your thoughts on how best to expand this functionality and more fully integrate the complete spectrum of a Route feature's geometry for analysis and real world uses.
Tags (1)
0 Kudos
10 Replies
RichardFairhurst
MVP Honored Contributor
I have been rewriting my code as an Add-In and testing the behavior of Linear Referencing on Polylines that are Z and M aware.  I am pleased to say that Points and Lines exported from Route Event layers preserved the Z information at the point and along the line, and automatically interpolates Z values for those points or line end points that occur between vertices.  This even occurs on polylines with true curved segments and vertical only polylines.

Based on my testing so far, it appears that an event table could fairly easily be created that could produce a segmented 3D copy of the 3D line broken into equal parts as measured by 3D length for lines that have the M values calculated based on the 3D length of the line.  This includes segentation of vertical only polylines.

After 3D Length Measure values are assigned the user can look at the Sketch of the line and easily determine the 3D length between any two vertices (just subtract the lower M value from the higher M value to get the 3D length between the points).

I tested the code on a multi-part line with a gap and by default the code adds no distance between the vertices on either side of the gap.  I think I know how to operate on the parts to interpolate a straight line 3D distance between polyline parts, so I should be able to add that as an option.

The code in my post does not handle lines with true curved segments and throws an error for such lines.  I believe I have figured out a way to approximate the 3D length values for true curves without altering the curve's geometry or using the I3DCurve interface, provided I assume that the elevation change between the endpoints of the curved segment is linearly distributed over the curve and the curve is not trying to follow an elevation surface.

So a curve with equal elevations at each end will just have M values based on the 2D curve length of the segment, but if there is an elevation change at the ends of the curve, I will treat the segment curve length as though it was a straight 2D line changing in elevation and use the formula SQRT([curve_length)^2 + (z1 - z2)^2]).  I think this is how the Route Event layer handles its interpolation of Z values on true curves, but I may be wrong.  I still have to do some tests of a new subroutine that uses this formula and correctly applies Spatial Reference units for XY and Z, but I expect that the distortion in measures using this method will be no more than what results from Densifying a curve into small linear segments.  (Someone with more math skills than me is welcome to point out any mathimatical logic flaws with the above formula, but if the errors it produces are reasonably low it may be good enough for most uses).

So is anybody interested enough to comment on this?  Please let me know.
0 Kudos
JeffreyOwen1
Occasional Contributor
I am indeed interested in such a tool since (in my opinion) linear referencing for large-scale real world conditions is pretty much worthless without taking into account elevation. I can see the point of calibrating a route with observations (time consuming), but for regional analysis it would be great to merge the M and Z functionality.

Let me know if you want someone to test your Add-In because I have a State-wide layer and I would like to see how it changes when Z-values are considered.
0 Kudos
RichardFairhurst
MVP Honored Contributor
I am indeed interested in such a tool since (in my opinion) linear referencing for large-scale real world conditions is pretty much worthless without taking into account elevation. I can see the point of calibrating a route with observations (time consuming), but for regional analysis it would be great to merge the M and Z functionality.

Let me know if you want someone to test your Add-In because I have a State-wide layer and I would like to see how it changes when Z-values are considered.


Jeffrey:

Thank you for showing an interest in this.  If you look at some of my other posts in the ArcObjects for All Languages forum you will see that I have begun creating an Add-In for ArcGIS 10.  I have figured out how to deal with polylines that contain curved segments (circular, bezier, ellipise).  I have also incorporated options to allow a user to assign an offset beginning measure and a measure multiplier for unit conversion.

Where I am now struggling is with standardizing units of length.  The code only works at the moment for Projected Coordinate Systems with Linear units that are the all same for X/Y and Z.  Standarizing Projected Coordinate Systems with mixed units should not be that hard, since all units are Linear and referenced to meters in the Spatial Reference.  So if your data has a Projected Coordinate System I should have working code fairly soon that should also be able to project measure offsets across multi-part polyline gaps as an option.

However, I have not figured out how to standarize mixed Angular and Linear Geographic Coordinate Systems to a single unit of length measures.  Until I can figure out all of the unit standardizations subroutines involved the base code and projections of 3D straight line measure values across gaps will not work for Geographic Coordinate Systems.  I just have not had much input on the forums and not a lot of time to reasearch that just yet.

So let me know if the code I have now or soon for Projected Coordinate Systems would work for you or if you need the code to work with a Geographic Coordinate System before you could apply it.
0 Kudos
JeffreyOwen1
Occasional Contributor
Code for Projected Coordinate Systems should work fine for me. I will double-check that my data has linear units instead of angular, if not I am fine projecting them to try out the tool. Also, my routes are all continuous and do not contain any gaps, so I won't need to worry about that functionality for now.

Thanks for all of your work on this. I am very curious to try it out!
0 Kudos
RichardFairhurst
MVP Honored Contributor
Code for Projected Coordinate Systems should work fine for me. I will double-check that my data has linear units instead of angular, if not I am fine projecting them to try out the tool. Also, my routes are all continuous and do not contain any gaps, so I won't need to worry about that functionality for now.

Thanks for all of your work on this. I am very curious to try it out!


Just giving an update on where I am at on this tool.  The code is working on Projected Systems where all Z values are assigned (no NaN values) and the X/Y and Z units are defined.  It recognizes how to convert units to the X/Y standard when Z uses a different unit type (which I found out the ICurve3D interface provided by ESRI does not do).  It also is able to optionally project a straight line 3D length value across gaps in multi-part lines and apply a user specified Measure multiplier and/or an initial Measure offset.

For the interface I am sticking with building an Add-In.  I plan on building an Extension to listen to map events so that the toolbar can populate a combobox list of qualifying layers.  The rest of the toolbar will be enabled if at least one layer qualifies for the tool.  I will have two other comboboxes where the measure multiplier and measure offset will be initialized to 1 and 0 respectively and allow user input.  Three additional buttons will also be on the toolbar.  One will allow the user to toggle if they want 3D distances projected across gaps in multi-part lines, the second will toggle the operation so that it occurs only on selected features or on all features (without having to change the current feature selection), and the third will execute the operation.  By default the operation will occur on selected features only and the tool will always respect a layer's definition query even when it is allowed to process all layer features, whether selected or not. 

The code currently works inside or outside of an edit session with non-SDE features.  I need to add code to detect when a layer is an SDE feature class and only allow the operation to process if an edit session has been initiated for the layer and it is editable.  I also need to add more error trapping in case something unexpected got by me to avoid nasty ArcMap crashes (which are very easy to cause).

I plan on releasing it with the known limitation that it will not initially work on GCS feature classes and it will be using a simple NaN Z interpolation method.  If NaN Z values occur on any vertice of the line I plan on treating the Z value as if it held the preceeding Z value the tool last read and where the Z value of the first vertice is NaN I will assume an elevation of 0.  NaN Z values will not be changed by the tool, they will will just take on assumed values during the tool operation for the purposes of assigning M values.  I plan on reporting how many lines required NaN Z interpolation when the tool finishes if any Z interpolation was required.

After I get some feedback on the user friendliness of the design and the effectiveness of the tool with PCS feature classes I will try to enhance the tool to deal with the above limitations.  At that point I also will consider offering a variety of Z interpolation options for processing NaN Z values and give the user an option to update the NaN Z values at the same time that the tool assigns the M values.

I hope this sounds good to anybody watching this thread (like Jeffrey).
0 Kudos
RichardFairhurst
MVP Honored Contributor
I have posted my Add-In tool here in the Galleries.  It optionally assigns Measures to existing Route features with accumulated 3D or 2D length values.  3D Lengths Measures can only be assigned to layers with XYZM coordinates that use a Projected Coordinate System.  2D Measures can be assigned to any layer. 

All of the options of the Create Route tool are available, but edits take place on existing Routes rather than creating a new Feature Class.  One or more Routes can be processed by the tool at once, including up to all of the features of the layer.  The tool always observes layer Definition Query restrictions.

Please give the tool a try and look at the README.txt file that comes with it to contact me directly if you encounter any bugs or have questions, comments or would like to see additional tool enhancements.
0 Kudos
NarminaLovely
Emerging Contributor
Richard, I have downloaded your tool and tried to use it, but clicking on the button interface of the tool, greyed out the tool and did not bring up an iterface window. I am using ArcGIS10 SP3.

Thanks,
Narmina
0 Kudos
RichardFairhurst
MVP Honored Contributor
Richard, I have downloaded your tool and tried to use it, but clicking on the button interface of the tool, greyed out the tool and did not bring up an iterface window. I am using ArcGIS10 SP3.

Thanks,
Narmina


You must enable the extension in the Customize | Extension Manager.  The behavior is expected if the extension is disabled.  The readme file lists the set up steps in more detail as well as the expected tool behaviors and limitations.  Let me know if there is still a problem after the extension is enabled.
0 Kudos
ScottMcCulloch
Emerging Contributor
Richard,

Thank you for contributing this add-in, however I cannot use it.  Have installed it, turned on extension, and turned on dialog no problem.  But the "Z and M Enabled Projected Layers" dropdown list remains consistently empty, even when I have perfectly good PolylineZM layers in my map that I would like to re-measure honouring the z values (i.e. in 3D).  Any idea why this is happening?  Using ArcGIS 10.0.5 at ArcInfo license level.  Have tried polylineZM input layers that are both file GDB feature classes and shapefiles.
0 Kudos