Visualizing Nairobi Transit(GTFS) with WorldWind in JavaFX
The geographic information is what i wanted ,reading through the GTFS guidelines i was set to first look around for an API .
OneBusWay came recommended but i decided to go with this google code project i found ,it isn't complete ,so you will have to create a shape class and add this lines of code to the GtfsReader class and GtfsSpec class.
Setting up WorldWind check my previous post.
Nairobi GTFS and Nairobi boundaries |
Shape Class
public class Shape {
private final String id;
private final String shape_lat;
private final String shape_lon;
public Shape(String id,String shape_lat,String shape_lon){
this.id=id;
this.shape_lat=shape_lat;
this.shape_lon=shape_lon;
public String getID(){
return id;
}
public String getShapeLat(){
return shape_lat;
}
public String getShapeLon(){
return shape_lon;
}
}
add this code to the GtfsReader class just after the routes else if
else if(filename.equals("shapes.txt")){
List<Map<String, String>> lines = readCsv(zip);
for (Map<String, String> line : lines) {
shapes.add(new Shape(line.get("shape_id"), line.get("shape_pt_lat"),
line.get("shape_pt_lon")
));
}
}
reading the gtfs file
GtfsReader gtfs=new GtfsReader();
GtfsSpec spec=gtfs.readGtfsFile(new FileInputStream("google_transit.zip"));
Drawing the Polyline
List<Position> pos=new ArrayList<>();
for (Shape a : spec.shapes) { pos.add(Position.fromDegrees(Double.valueOf(a.getShapeLat()),Double.valueOf(a.getShapeLon())));
}
Polyline line=new Polyline(pos,3e4);
line.setColor(java.awt.Color.red);
line.setLineWidth(1);
renderableLayer.addRenderable(line);
Results
Nairobi Matatu GTFS |
Nairobi GTFS |
Comments
Post a Comment