Search in sources :

Example 61 with CoordinateBounds

use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.

the class ShapeGeospatialIndexTaskTest method test.

@Test
public void test() throws IOException, ClassNotFoundException {
    ShapeGeospatialIndexTask task = new ShapeGeospatialIndexTask();
    File path = File.createTempFile(ShapeGeospatialIndexTaskTest.class.getName(), ".tmp");
    path.delete();
    path.deleteOnExit();
    FederatedTransitDataBundle bundle = Mockito.mock(FederatedTransitDataBundle.class);
    Mockito.when(bundle.getShapeGeospatialIndexDataPath()).thenReturn(path);
    task.setBundle(bundle);
    RefreshService refreshService = Mockito.mock(RefreshService.class);
    task.setRefreshService(refreshService);
    ShapePointHelper shapePointHelper = Mockito.mock(ShapePointHelper.class);
    task.setShapePointHelper(shapePointHelper);
    TransitGraphDao transitGraphDao = Mockito.mock(TransitGraphDao.class);
    task.setTransitGraphDao(transitGraphDao);
    StopEntry stopA = stop("stopA", 47.65, -122.32);
    StopEntry stopB = stop("stopB", 47.67, -122.30);
    Mockito.when(transitGraphDao.getAllStops()).thenReturn(Arrays.asList(stopA, stopB));
    TripEntryImpl tripA = trip("tripA");
    AgencyAndId shapeIdA = aid("shapeA");
    tripA.setShapeId(shapeIdA);
    TripEntryImpl tripB = trip("tripB");
    AgencyAndId shapeIdB = aid("shapeB");
    tripB.setShapeId(shapeIdB);
    Mockito.when(transitGraphDao.getAllTrips()).thenReturn(Arrays.asList((TripEntry) tripA, tripB));
    ShapePointsFactory factory = new ShapePointsFactory();
    factory.addPoint(47.652300128129454, -122.30622018270873);
    factory.addPoint(47.653181844549394, -122.30523312979125);
    factory.addPoint(47.654265901710744, -122.30511511259459);
    ShapePoints shapeA = factory.create();
    factory = new ShapePointsFactory();
    factory.addPoint(47.661275594717026, -122.31189573698424);
    factory.addPoint(47.661347854692465, -122.3240622370758);
    factory.addPoint(47.661368177792546, -122.32508885257624);
    factory.addPoint(47.66496659665593, -122.32501375072383);
    ShapePoints shapeB = factory.create();
    Mockito.when(shapePointHelper.getShapePointsForShapeId(shapeIdA)).thenReturn(shapeA);
    Mockito.when(shapePointHelper.getShapePointsForShapeId(shapeIdB)).thenReturn(shapeB);
    task.run();
    Mockito.verify(refreshService).refresh(RefreshableResources.SHAPE_GEOSPATIAL_INDEX);
    Map<CoordinateBounds, List<AgencyAndId>> shapeIdsByBounds = ObjectSerializationLibrary.readObject(path);
    assertEquals(5, shapeIdsByBounds.size());
    CoordinateBounds b = new CoordinateBounds(47.65048049686506, -122.30767397879845, 47.654977097836735, -122.300997795721);
    assertEquals(Arrays.asList(shapeIdA), shapeIdsByBounds.get(b));
    b = new CoordinateBounds(47.65947369880841, -122.32102634495334, 47.66397029978009, -122.3143501618759);
    assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
    b = new CoordinateBounds(47.66397029978009, -122.32770252803078, 47.66846690075177, -122.32102634495334);
    assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
    b = new CoordinateBounds(47.65947369880841, -122.3143501618759, 47.66397029978009, -122.30767397879845);
    assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
    b = new CoordinateBounds(47.65947369880841, -122.32770252803078, 47.66397029978009, -122.32102634495334);
    assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
}
Also used : TransitGraphDao(org.onebusaway.transit_data_federation.services.transit_graph.TransitGraphDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) FederatedTransitDataBundle(org.onebusaway.transit_data_federation.services.FederatedTransitDataBundle) RefreshService(org.onebusaway.container.refresh.RefreshService) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) List(java.util.List) File(java.io.File) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) Test(org.junit.Test)

Example 62 with CoordinateBounds

use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.

the class GtfsStopsInRegionMain method main.

@SuppressWarnings("unchecked")
public static void main(String[] args) throws IOException {
    if (args.length != 5) {
        System.err.println("usage: gtfs_path lat1 lon1 lat2 lon2");
        System.exit(-1);
    }
    double lat1 = Double.parseDouble(args[1]);
    double lon1 = Double.parseDouble(args[2]);
    double lat2 = Double.parseDouble(args[3]);
    double lon2 = Double.parseDouble(args[4]);
    CoordinateBounds bounds = new CoordinateBounds(lat1, lon1, lat2, lon2);
    GtfsReader reader = new GtfsReader();
    reader.setDefaultAgencyId("1");
    reader.getEntityClasses().retainAll(Arrays.asList(Stop.class));
    reader.setInputLocation(new File(args[0]));
    reader.addEntityHandler(new EntityHandlerImpl(bounds));
    reader.run();
}
Also used : GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) Stop(org.onebusaway.gtfs.model.Stop) File(java.io.File) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 63 with CoordinateBounds

use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.

the class MetricResource method getScheduledTrips.

protected int getScheduledTrips(String agencyId, String routeId) {
    Set<TripDetailsBean> agencyTrips = new HashSet<TripDetailsBean>();
    TripsForBoundsQueryBean query = new TripsForBoundsQueryBean();
    List<CoordinateBounds> allBounds = getTDS().getAgencyIdsWithCoverageArea().get(agencyId);
    for (CoordinateBounds bounds : allBounds) {
        query.setBounds(bounds);
        query.setTime(SystemTime.currentTimeMillis());
        query.setMaxCount(Integer.MAX_VALUE);
        TripDetailsInclusionBean inclusion = query.getInclusion();
        inclusion.setIncludeTripBean(true);
        ListBean<TripDetailsBean> allTrips = getTDS().getTripsForBounds(query);
        if (allTrips == null) {
            continue;
        }
        _log.debug("allTrips size=" + allTrips.getList().size());
        AgencyAndId routeAndId = new AgencyAndId(agencyId, routeId);
        for (TripDetailsBean trip : allTrips.getList()) {
            if (trip.getTripId().startsWith(agencyId)) {
                if (routeId == null || routeAndId.toString().equals(trip.getTrip().getRoute().getId())) {
                    agencyTrips.add(trip);
                }
            }
        }
    }
    return agencyTrips.size();
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripDetailsInclusionBean(org.onebusaway.transit_data.model.trips.TripDetailsInclusionBean) TripsForBoundsQueryBean(org.onebusaway.transit_data.model.trips.TripsForBoundsQueryBean) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) HashSet(java.util.HashSet) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 64 with CoordinateBounds

use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.

the class MetricResource method findInvalidLatLon.

private Collection<CoordinatePoint> findInvalidLatLon(String agencyId, Set<CoordinatePoint> coordinatePoints) {
    List<CoordinatePoint> invalid = new ArrayList<CoordinatePoint>();
    List<CoordinateBounds> bounds = getTDS().getAgencyIdsWithCoverageArea().get(agencyId);
    // ensure we have a valid bounding box for requested agency
    if (bounds == null || bounds.isEmpty()) {
        _log.warn("no bounds configured for agency " + agencyId);
        for (CoordinatePoint pt : coordinatePoints) {
            invalid.add(pt);
        }
        return invalid;
    }
    for (CoordinateBounds bound : bounds) {
        boolean found = false;
        for (CoordinatePoint pt : coordinatePoints) {
            // check if point is inside bounds
            if (bound.contains(pt)) {
                found = true;
            }
            if (!found) {
                invalid.add(pt);
            }
        }
    }
    _log.debug("agency " + agencyId + " had " + invalid.size() + " invalid out of " + coordinatePoints.size());
    return invalid;
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) ArrayList(java.util.ArrayList) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 65 with CoordinateBounds

use of org.onebusaway.geospatial.model.CoordinateBounds in project onebusaway-application-modules by camsys.

the class LocationResource method findInvalidLatLon.

private Collection<CoordinatePoint> findInvalidLatLon(String agencyId, Set<CoordinatePoint> coordinatePoints) {
    List<CoordinatePoint> invalid = new ArrayList<CoordinatePoint>();
    List<CoordinateBounds> bounds = getTDS().getAgencyIdsWithCoverageArea().get(agencyId);
    // ensure we have a valid bounding box for requested agency
    if (bounds == null || bounds.isEmpty()) {
        _log.warn("no bounds configured for agency " + agencyId);
        for (CoordinatePoint pt : coordinatePoints) {
            invalid.add(pt);
        }
        return invalid;
    }
    for (CoordinateBounds bound : bounds) {
        boolean found = false;
        for (CoordinatePoint pt : coordinatePoints) {
            // check if point is inside bounds
            if (bound.contains(pt)) {
                found = true;
            }
            if (!found) {
                invalid.add(pt);
            }
        }
    }
    _log.debug("agency " + agencyId + " had " + invalid.size() + " invalid out of " + coordinatePoints.size());
    return invalid;
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) ArrayList(java.util.ArrayList) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Aggregations

CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)70 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)17 HashMap (java.util.HashMap)16 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)15 List (java.util.List)14 SearchQueryBean (org.onebusaway.transit_data.model.SearchQueryBean)12 Map (java.util.Map)9 StopBean (org.onebusaway.transit_data.model.StopBean)9 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)7 RouteBean (org.onebusaway.transit_data.model.RouteBean)7 StopsBean (org.onebusaway.transit_data.model.StopsBean)7 Envelope (com.vividsolutions.jts.geom.Envelope)5 OutOfServiceAreaServiceException (org.onebusaway.exceptions.OutOfServiceAreaServiceException)5 STRtree (com.vividsolutions.jts.index.strtree.STRtree)4 File (java.io.File)4 IOException (java.io.IOException)4 Filters (org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters)4 DetailLevel (org.onebusaway.api.actions.siri.model.DetailLevel)4 RoutesBean (org.onebusaway.transit_data.model.RoutesBean)4