Select to view content in your preferred language

Measuring routes in python

702
1
11-19-2013 12:58 AM
stuartwilson
Deactivated User
Is it possble to measure a route for an M enabled polyline feature class using python. I want to measure a route cosisting of river sections. Each arc is from one river confluence to the next. I want to measure all arcs that make up a river. The rivers have a unique number for each river including all arcs from the river source to the coast. I have written a script using the CreateRoutes tool (from linear referencing) but this merges all the river arcs. I tried using this tool in a loop using a cursor to measure each arc individually which was successful but it does not retain the attributes of the input feature class. Is there another way of measuring or setting the M values for a line?
Tags (2)
0 Kudos
1 Reply
RichardFairhurst
MVP Alum
Is it possble to measure a route for an M enabled polyline feature class using python. I want to measure a route cosisting of river sections. Each arc is from one river confluence to the next. I want to measure all arcs that make up a river. The rivers have a unique number for each river including all arcs from the river source to the coast. I have written a script using the CreateRoutes tool (from linear referencing) but this merges all the river arcs. I tried using this tool in a loop using a cursor to measure each arc individually which was successful but it does not retain the attributes of the input feature class. Is there another way of measuring or setting the M values for a line?


If you really want an arc by arc route system, then calculate the ObjectID of the arcs into a new field and build your routes with that field as the RouteID.  Then transfer all of the attributes from the arcs with a Join of the original arc new field/ObjectID to the RouteID field.  It could be a text field concatenation of the RiverID and ObjectID if you want.  You can then either use the Field Calculator to transfer the arc attributes or perform an Export to make a copy with the attributes appended.  Then you can select all of the route arcs the same way you would select the original arcs and calculate their measures, which will have been built according to their length.  The disadvantage of this method is that the measure will restart with each arc, which may not be what you want.

An alternative approach is to build the full river route as you already have done and then use the Locate Features Along Route tool to create a set of events from your original river arcs.  This tool creates fields with the measures of each arc for you that will align to the full route.  You should still create a copy of the ObjectID in a new field if you do not have a unique ID for each arc individually.  The event table has the advantage that it will let you sort the arcs by measure, which will be in the order that they built the full route.  You can then make a Route Event Layer and export the events to a feature class to convert them to real route arcs.

You probably will have branches.  Normally my routes do not have branches, since they are roads.  Branches can complicate the use of events, depending on what you want the measures to represent.  If they just represent distance from the headwaters down any branch they should be OK (although lines will duplicate when measures overlap on multiple branches).  If you want separate measure systems on minor branches that do not overlap your main river, you would have to manually correct the measures at the branches to make minor branches have measures that did not interleave with the main river measures or with other branches.

Your RiverID can only really act as a RouteID for the full river route.  Multiple uses of the same RouteID for different routes will probably cause problems, depending on what you want to do.
0 Kudos