dist_along_route = lineGeom.measureOnLine(ptGeom)
Glad you figured it out. Yes, the SearchCursor returns items in a tuple. You could have chosen to return more than one field (in addition to SHAPE@), and it would have returned something like (SHAPE@, Field, Field), so it makes sense that you have to use a [0] to get the first item in the tuple (even if there is only one item in it).The distance is, I believe, the distance along the route in the units of the coordinate system used by the route. If it's in a geographic coordinate system, you should probably project it into something appropriate for the area you're studying.Do your stops have a route ID associated with them? If so, you can use a loop to loop through the routes. For each route, you can use MakeFeatureLayer on the stops to select only the stops associated with the route ID, and then do the SearchCursor on the feature layer and loop through those stops to calculate the distance along the line.Something like this (which I didn't test, so it might not be perfect):cursorRoute = arcpy.da.SearchCursor(fcRoute,['SHAPE@', 'RouteID']) for route in cursorRoute: RouteID = route[1] routeGeom = route[0] where = '"RouteID" = %s' % str(RouteID) arcpy.management.MakeFeatureLayer(fcStop, "Stops", where) cursorStop = arcpy.da.SearchCursor(fcStop,['STOP_ID','SHAPE@']) for stop in cursorStop: stopGeom = stopGeom[1] # Looks like the geometry is the second item in your tuple here dist_along_route = routeGeom.measureOnLine(stopGeom,FALSE)
cursorRoute = arcpy.da.SearchCursor(fcRoute,['SHAPE@', 'RouteID']) for route in cursorRoute: RouteID = route[1] routeGeom = route[0] where = '"RouteID" = %s' % str(RouteID) arcpy.management.MakeFeatureLayer(fcStop, "Stops", where) cursorStop = arcpy.da.SearchCursor(fcStop,['STOP_ID','SHAPE@']) for stop in cursorStop: stopGeom = stopGeom[1] # Looks like the geometry is the second item in your tuple here dist_along_route = routeGeom.measureOnLine(stopGeom,FALSE)
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
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.
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.