3

So far I've filled out the MTA online registration form for a Developer's API Key. Then in my android project, I implemented the gtfs realtime bindings dependecy from one of Google's github repositories,

compile group: 'com.google.transit', name: 'gtfs-realtime-bindings', version: '0.0.4'

Using their Java class, I tried this following code to print out all the gtfs data from the link given by MTA,

try {
    String urlString = "http://datamine.mta.info/mta_esi.php?key=insertmykeyhere";
    URL url = new URL(urlString.toString());
    GtfsRealtime.FeedMessage feed = GtfsRealtime.FeedMessage.parseFrom(url.openStream());
    for (GtfsRealtime.FeedEntity entity : feed.getEntityList()) {
        if (entity.hasTripUpdate()) {
            Log.d("stuff", entity.getTripUpdate().toString());
        } 
    }

} catch (IOException e) {
            e.printStackTrace();
}

However, I'm now having trouble interpreting the data printed out. I understand that there are static data feeds from http://web.mta.info/developers/developer-data-terms.html, which I used to interpret some of the data. Here is one of the trip updates printed out,

stuff: trip {
    trip_id: "036000_GS.N01R"
    start_date: "20170218"
    route_id: "GS"
    1001: "\n\0200S 0600  GCS/TSS\020\001\030\001"
}     
stop_time_update {
    departure {
        time: 1487415600
    }
    stop_id: "901N"
    1001: "\n\0011\022\0011"
}
stop_time_update {
    arrival {
        time: 1487415690
    }
    stop_id: "902N"
    1001: "\n\0011"
}

I understand some parts such as trip_id, start_date, and stop_id. But parts such as trip_id, time, and 1001 I'm still unsure about it and the text files from the static feed don't do the best job of explaining them.

1 Answer 1

1

The MTA Subway GTFS-RT feeds are a little different than most others.

Typically, GTFS-RT refers directly back to a static GTFS' via trip_id/stop_id/etc. Since in NYC there is usually a deviation from normal service ("2 Train via the 5 Line"), the RT feed retains the option to create new trips that do not exist in the static feed.

To answer your immediate questions, you need to add the realtime extensions. That should solve the empty 1001: field.

To do so, either compile the proto file, or just import the onebusaway-gtfs-realtime-api library, which has the extensions pre-compiled in:

    ExtensionRegistry registry = ExtensionRegistry.newInstance();
    registry.add(GtfsRealtimeNYCT.nyctFeedHeader);
    registry.add(GtfsRealtimeNYCT.nyctStopTimeUpdate);
    registry.add(GtfsRealtimeNYCT.nyctTripDescriptor);

   GtfsRealtime.FeedMessage feed = GtfsRealtime.FeedMessage.parseFrom(url.openStream(), registry);

This gives a result like:

trip {
  trip_id: "B20170217WKD_132800B..S"
  start_date: "2017-02-17 22:08:00"
  route_id: "B"
  [transit_realtime.nyct_trip_descriptor] {
    train_id: "1B 2208 145/BBC"
    is_assigned: true
    direction: SOUTH
  }
}
stop_time_update {
  arrival {
    time: 1487390920
  }
  departure {
    time: 1487390920
  }
  stop_id: "D39"
  schedule_relationship: SCHEDULED
  [transit_realtime.nyct_stop_time_update] {
    scheduled_track: "A3"
    actual_track: "A3"
  }
}
stop_time_update {
  arrival {
    time: 1487391130
  }
  departure {
    time: 1487391130
  }
  stop_id: "D40"
  schedule_relationship: SCHEDULED
  [transit_realtime.nyct_stop_time_update] {
    scheduled_track: "A3"
    actual_track: "A3"
  }
}
4
  • what is the result of the code using the onebusaway api? I'm not too familiar with the library.
    – Chris Gong
    Commented Feb 19, 2017 at 0:50
  • the onebusaway library is just the protobuf compiled with the required extension. See the trip_descriptor is now filled in. github.com/laidig/nyct-gtfs-rt-example has a working Maven project to try out with. Commented Feb 19, 2017 at 2:51
  • hello, it's been a while since i've seen this answer so I just noticed the edit. I'm kinda new to Maven so how would I install the github repo? Would I just download the repo and then upload it in some IDE like Eclipse?
    – Chris Gong
    Commented Feb 25, 2017 at 18:34
  • If you have eclipse and the Maven plugin installed, just file->import>Maven Commented Feb 26, 2017 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.