Solved! Go to Solution.
dist_along_route = lineGeom.measureOnLine(ptGeom)
dist_along_route = lineGeom.measureOnLine(ptGeom)
Hello, Sui Tao.
I will try to help you out with this. What version of ArcGIS are you running?
There's a new python method in ArcGIS 10.2.1 that would be perfect for what you're trying to do. It allows you to quickly find the distance along a line that a point falls. You could find the distance that each stop falls along the route they're assigned to and sort by that distance to determine the order. You have to create a Polyline geometry object for your route line and a Point geometry object for each stop. Then use the measureOnLine() method. You would end up with something like:dist_along_route = lineGeom.measureOnLine(ptGeom)
See http://resources.arcgis.com/en/help/main/10.2/index.html#//018z00000070000000.
Unfortunately, this simple method isn't available in ArcGIS versions prior to 10.2.1.
If you don't have 10.2.1 yet, you could accomplish the same thing using the linear referencing tools. See http://resources.arcgis.com/en/help/main/10.2/index.html#//003m00000002000000. You would first use the Create Routes tool on your polyline routes. This just generates measures along those route lines so you can return the distance along the lines later. Then, you would use Locate Features Along Routes to determine the distance along each route that each stop falls. You could then extract the distance from the resulting table and sort it to determine your stop sequence. You would want to run the tool separately for each route in your system. If you have a lot of routes, this will likely be time consuming, as the linear referencing tools tend to run a bit slowly. The 10.2.1 Geometry method I mentioned above is much faster.
Let me know if this doesn't answer your question or if I can provide any further assistance.
Not a stupid question at all! You need to read in your shapefile or feature class using a search cursor (arcpy.da.SearchCursor). You can read in the shape geometry using the SHAPE@ keyword, and that should give you a point or a line geometry object. You then feed the point and line geometry objects to the measureOnLine method. There are some SearchCursor examples here: http://resources.arcgis.com/en/help/main/10.2/index.html#//018w00000011000000