Closed MvdW123 closed 9 months ago
Hi, I've also had this problem, did you solve it?
No I haven't yet, working on a solution, any insights would be great!
When i filtered the gtfs file down to only bus routes this function then ran for me, so maybe it is something to do with a difference between bus and other routes types. I have also been making a similar version to the cut segment function that does not extract the shape data as this is then a whole lot faster and I don't think she shape data is always needed. Perhaps I can share this back
That sounds very possible, how did you filter the data to isolate the bus routes? If its too hard to explain maybe you could attach the filtered data that ran for you? Thanks
buy routes have route type in the seven hundreds so i used the following code
bus_routes = routes.loc[(routes.route_type>=700) & (routes.route_type<800)].reset_index()
That's perfect, but my dataset still runs into trouble as the shapes, stops and stop_times data frames still includes all of the various modes of transport. How does one remove these unwanted modal data points from all of the data frames?
ahh yep sorry here is the rest
sydney_bus_routes = routes.loc[routes.route_desc=='Sydney Buses Network']
sydney_bus_route_ids = sydney_bus_routes['route_id'].unique()
then we can cut down the trips based on the route ids
sydney_bus_trips = trips.loc[trips.route_id.isin(sydney_bus_route_ids)]
cut down on stop times based on trip id
sydney_bus_stop_times = stop_times.loc[stop_times.trip_id.isin(sydney_bus_trips['trip_id'])]
cut down on stops based on stop id
sydney_bus_stops = stops.loc[stops.stop_id.isin(sydney_bus_stop_times['stop_id'])]
and finally cut down on shapes based on shape id from trips
sydney_bus_shapes = shapes.loc[shapes.shape_id.isin(sydney_bus_trips['shape_id'])]
I ran into this exact error message with Vancouver's Translink feed and removing rail routes did not resolve the issue. It seems to be an error in the logic for the cut shapes with loops portion of the cut_gtfs function. Any movement on resolving this?
I've done some digging on the Sydney ferry GTFS network where this problem occurs. What happens is when looking for the first segment to cut, it can't find a result. Hence in the subsequent middle segment searches the last_point
is not set and the referenced before assignment
error occurs.
The reason for this is that the line that gets created to cut the shapes does not intersect with the shapes. See image below.
A fairly simple solution I can see is to apply a very small buffer to the segments. This will now result in an intersection for the first segment.
i.e.
511: if segment.buffer(0.00001).intersects(cut_lines[0]):
(same on line 532 and 595)
@Bondify I'm happy to create a pull request for this, just need collaborator rights.
This works great! Thanks a lot @TheJAG!
sorry for the (very) late response everyone and thanks @TheJAG for digging into this. I had been out of this project for a while.
The latest version of the package should fix this problems with no need to get modify the code.
I am trying to run this code with the GTFS data as you used but get a UnboundLocalError when trying to run segment_gdf. It says that in line 508 of gtfs_functions last_point is referenced before assignment. Please advise on how to resolve this issue. Thanks :)