logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Login


Options
View
Go to last post Go to first unread
Maurice  
#1 Posted : Monday, May 14, 2012 9:56:54 PM(UTC)
Maurice

Rank: Member

Groups: Registered
Joined: 7/16/2011(UTC)
Posts: 15

Thanks: 1 times
I am looking for a way to recreate the headsign attribute we get in GetDeparturesByStop from data in the GTFS feed (or GetStopTimesByStop).
Interestingly trip_headsign is not the same as headsign in departures and other attributes like route_id are inconsistent. What are the suggested way so I can reconstruct the nice, consistent headsign from data in the GTFS?
Ryan  
#2 Posted : Tuesday, May 15, 2012 11:50:00 AM(UTC)
Ryan

Rank: Administration

Groups: Administrators, Registered
Joined: 6/1/2011(UTC)
Posts: 88
United States
Location: Urbana

Thanks: 1 times
Was thanked: 6 time(s) in 6 post(s)
Oh boy, that's a tough one. There is no single field in the GTFS feed that contains the data for the trip headsign as you would normally think of it. The way I would construct it is as follows. You will need the trip and the route information. Given a trip you should be able to find the route based on the route_id listed for the trip. So, to get the headsign you would do:

Code:
[route_short_name] [direction_id] [route_long_name]


route_short_name and route_long_name are in routes.txt. direction_id is in trips.txt.

You'll notice that direction_id is a single bit (0 or 1). This is required by the GTFS standard, but is not very meaningful for our system. It requires us to do a bit of an ugly hack to get a meaningful direction. We have to map the bit for each route to a meaningful direction. This is done behind the scenes with the API and there is currently no publicly available way to replicate it. The only way I can see for you to duplicate this is to do some hard coding. I can share what zero and one map to for each route type, but the dificult part is deciding which routes corospond with which direction type. This, I think, will have to be hard coded. The current direction mappings are as follows:

Code:
Zero       One

North      South
East       West
A          B
Champaign  Urbana


The Grey route for instance is an east/west route. So, a zero on a grey trip would be east and a 1 would be west.

I think perhaps an example would help. For trip_id: GN5SATPO__GN5SA we see that it has a the route_id GREY WEEKEND. This allows us to reference the appropriate row in the route file.

So we have the following values

Code:

route_short_name (routes.txt): 70
route_long_name (routes.txt):  Grey Weekend
Direction (trips.txt):         1


We see that 1 corosponds with West so the full headsign would be 70 West Grey Weekend.

I hope this helps. The GTFS standard can be a bit confusing at first and is a lot to wrap your head around. There's really no good way to get the direction for a route without doing some hard coding yourself. I hope this helps to clairify and let me know if you have any other questions.
thanks 1 user thanked Ryan for this useful post.
Maurice on 5/15/2012(UTC)
Maurice  
#3 Posted : Tuesday, May 15, 2012 1:02:25 PM(UTC)
Maurice

Rank: Member

Groups: Registered
Joined: 7/16/2011(UTC)
Posts: 15

Thanks: 1 times
What about trip_headsign? It seems to be prefixed by the direction except for Brown, Plum and Yellow Evening as far as I can see. Will that be a better way to get the direction than the direction_id + hard coding?
Ryan  
#4 Posted : Wednesday, May 16, 2012 1:50:41 PM(UTC)
Ryan

Rank: Administration

Groups: Administrators, Registered
Joined: 6/1/2011(UTC)
Posts: 88
United States
Location: Urbana

Thanks: 1 times
Was thanked: 6 time(s) in 6 post(s)
I believe that trip_headsign is what actually shows on the front of the bus when it is in service. I need to check with our data guy to verify this, but I'm fairly certain. This is legacy information from before we had an API or GTFS feed and is not as rigidly structured as other parts of our data. Hence, some of the trip_headsign values having a direction and some not. Given that there is no defined structure for how this information appears I think you would find it difficult to extract reliable direction information from that field. I'll have to have have a discussion with our data guys to see if there's a way we can make that field more consistent in the future, but that would be a long to medium term solution.

Sorry that there's not really a good way to do this. Although, keep in mind that you can always get relevant direction information from the GetTrip methods of the API.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.