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));
}
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();
}
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();
}
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;
}
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;
}
Aggregations