Search in sources :

Example 1 with Location

use of org.onebusaway.gtfs.model.Location in project onebusaway-gtfs-modules by OneBusAway.

the class LocationsGeoJSONReader method read.

public Collection<Location> read() throws IOException {
    FeatureCollection featureCollection = new ObjectMapper().readValue(reader, FeatureCollection.class);
    Collection<Location> locations = new ArrayList<>(featureCollection.getFeatures().size());
    for (Feature feature : featureCollection.getFeatures()) {
        Location location = new Location();
        location.setId(new AgencyAndId(this.defaultAgencyId, feature.getId()));
        location.setGeometry(feature.getGeometry());
        location.setName((String) feature.getProperties().get("stop_name"));
        location.setDescription((String) feature.getProperties().get("stop_description"));
        location.setUrl((String) feature.getProperties().get("stop_url"));
        location.setZoneId((String) feature.getProperties().get("zone_id"));
        locations.add(location);
    }
    return locations;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) FeatureCollection(org.geojson.FeatureCollection) ArrayList(java.util.ArrayList) Feature(org.geojson.Feature) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Location(org.onebusaway.gtfs.model.Location)

Example 2 with Location

use of org.onebusaway.gtfs.model.Location in project onebusaway-gtfs-modules by OneBusAway.

the class LocationsGeoJSONReaderTest method read.

@Test
public void read() throws IOException {
    Collection<Location> locations = new LocationsGeoJSONReader(new InputStreamReader(new FileInputStream(GtfsTestData.getLocationsGeojson())), "").read();
    assertEquals(locations.size(), 1);
    Location location = locations.iterator().next();
    assertEquals("si_Wendenschlossstrasse", location.getId().getId());
    assertEquals("Wendenschlossstrasse", location.getName());
    assertEquals("A nice description", location.getDescription());
    assertTrue(location.getGeometry() instanceof Polygon);
    assertEquals(new Polygon(new LngLatAlt(13.576526641845703, 52.44413508398945), new LngLatAlt(13.575839996337889, 52.429169943434495), new LngLatAlt(13.590774536132812, 52.4105872618342), new LngLatAlt(13.60879898071289, 52.43225757383383), new LngLatAlt(13.576526641845703, 52.44413508398945)), location.getGeometry());
    assertEquals("fare-zone-A", location.getZoneId());
    assertEquals("http://example.com", location.getUrl());
}
Also used : InputStreamReader(java.io.InputStreamReader) Polygon(org.geojson.Polygon) FileInputStream(java.io.FileInputStream) LngLatAlt(org.geojson.LngLatAlt) Location(org.onebusaway.gtfs.model.Location) Test(org.junit.Test)

Aggregations

Location (org.onebusaway.gtfs.model.Location)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Feature (org.geojson.Feature)1 FeatureCollection (org.geojson.FeatureCollection)1 LngLatAlt (org.geojson.LngLatAlt)1 Polygon (org.geojson.Polygon)1 Test (org.junit.Test)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1