Solved! Go to Solution.
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)
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)