use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.
the class BlockLocationServiceImplTest method testWithShapeInfo.
@Test
public void testWithShapeInfo() {
StopEntryImpl stopA = stop("a", 47.5, -122.5);
StopEntryImpl stopB = stop("b", 47.6, -122.4);
StopEntryImpl stopC = stop("c", 47.5, -122.3);
BlockEntryImpl block = block("block");
TripEntryImpl tripA = trip("tripA", "serviceId");
TripEntryImpl tripB = trip("tripB", "serviceId");
stopTime(0, stopA, tripA, 30, 90, 0);
stopTime(1, stopB, tripA, 120, 120, 100);
stopTime(2, stopC, tripA, 180, 210, 200);
stopTime(3, stopC, tripB, 240, 240, 300);
stopTime(4, stopB, tripB, 270, 270, 400);
stopTime(5, stopA, tripB, 300, 300, 500);
BlockConfigurationEntry blockConfig = linkBlockTrips(block, tripA, tripB);
long serviceDate = 1000 * 1000;
double epsilon = 0.001;
TargetTime target = new TargetTime(t(serviceDate, 0, 0), System.currentTimeMillis());
BlockInstance blockInstance = new BlockInstance(blockConfig, serviceDate);
BlockLocation location = _service.getLocationForBlockInstance(blockInstance, target);
assertNull(location);
ScheduledBlockLocation p = new ScheduledBlockLocation();
p.setActiveTrip(blockConfig.getTrips().get(0));
p.setClosestStop(blockConfig.getStopTimes().get(0));
p.setClosestStopTimeOffset(0);
p.setDistanceAlongBlock(0);
p.setLocation(new CoordinatePoint(stopA.getStopLat(), stopA.getStopLon()));
p.setInService(true);
Mockito.when(_blockLocationService.getScheduledBlockLocationFromScheduledTime(blockConfig, 1800)).thenReturn(p);
target = new TargetTime(t(serviceDate, 0, 30), System.currentTimeMillis());
location = _service.getLocationForBlockInstance(blockInstance, target);
assertTrue(location.isInService());
assertEquals(blockConfig.getStopTimes().get(0), location.getClosestStop());
assertEquals(0, location.getClosestStopTimeOffset());
assertEquals(stopA.getStopLocation(), location.getLocation());
assertFalse(location.isScheduleDeviationSet());
assertTrue(Double.isNaN(location.getScheduleDeviation()));
assertFalse(location.isDistanceAlongBlockSet());
assertTrue(Double.isNaN(location.getDistanceAlongBlock()));
assertEquals(blockInstance, location.getBlockInstance());
assertEquals(0, location.getLastUpdateTime());
assertEquals(blockConfig.getTrips().get(0), location.getActiveTrip());
assertNull(location.getVehicleId());
assertEquals(47.5, location.getLocation().getLat(), epsilon);
assertEquals(-122.5, location.getLocation().getLon(), epsilon);
assertEquals(blockConfig.getStopTimes().get(0), location.getClosestStop());
assertEquals(0, location.getClosestStopTimeOffset());
}
use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.
the class DefaultProjectionTest method assertPoint.
private void assertPoint(double lat, double lon, double x, double y) {
CoordinatePoint point = new CoordinatePoint(lat, lon);
XYPoint p = _projection.forward(point);
assertEquals(x, p.getX(), 0.01);
assertEquals(y, p.getY(), 0.01);
}
use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.
the class GeospatialTestSupport method shiftPoints.
public static List<CoordinatePoint> shiftPoints(List<CoordinatePoint> points) {
if (points.size() < 2)
return points;
int minIndex = 0;
CoordinatePoint minPoint = null;
for (int index = 0; index < points.size(); index++) {
CoordinatePoint p = points.get(index);
if (minPoint == null || POINTS_COMPARATOR.compare(p, minPoint) < 0) {
minIndex = index;
minPoint = p;
}
}
List<CoordinatePoint> shifted = new ArrayList<CoordinatePoint>();
for (int i = minIndex; i < points.size(); i++) shifted.add(points.get(i));
for (int i = 0; i < minIndex; i++) shifted.add(points.get(i));
return shifted;
}
use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.
the class PolylineEncoderTest method testDecode.
@Test
public void testDecode() {
String polyline = "mz{aHryriV???tE???jE??AlC???lF??AlF??AnF???fF???|F???P?N???lE???T?\\???xD???|@???nD???xB???L?zG???nG?V???jD??qAxC??i@vAKXGTABAJ?B?B??AfF?D@`A??BPBZBr@???d@@`B?V?d@???zBAf@Cb@E^AX??Ad@??AfB?|A??@~G???vF???zF??A`H??WzAUx@??]v@??GL??yAzCg@x@??GH_@b@??c@f@??mC~C??gBtBi@f@??ABMF??cAn@kAl@wE`C??_Aj@C@eAx@a@Z[T??YT]Vg@`@??OVKVGRI`@CVG~@??@fA???pC??@tE??@lB?zA?P??AbN???lL??@hK?vC???N???T??AzN???LAhF?T?fG???dH";
List<CoordinatePoint> decode = PolylineEncoder.decode(polyline);
assertEquals(157, decode.size());
CoordinatePoint p = decode.get(0);
assertEquals(47.661350000000006, p.getLat(), 1e-5);
assertEquals(-122.32618000000001, p.getLon(), 1e-5);
}
use of org.onebusaway.geospatial.model.CoordinatePoint in project onebusaway-application-modules by camsys.
the class PolylineEncoderTest method testEncoder.
@Test
public void testEncoder() {
List<CoordinatePoint> points = new ArrayList<CoordinatePoint>();
points.add(new CoordinatePoint(38.5, -120.2));
points.add(new CoordinatePoint(40.7, -120.95));
points.add(new CoordinatePoint(43.252, -126.453));
String expected = "_p~iF~ps|U_ulLnnqC_mqNvxq`@";
EncodedPolylineBean actual = PolylineEncoder.createEncodings(points, 0);
Assert.assertEquals(expected, actual.getPoints());
List<CoordinatePoint> decodedPoints = PolylineEncoder.decode(actual);
GeospatialTestSupport.assertEqualsPointLists(points, decodedPoints, 1e-5);
}
Aggregations