Search in sources :

Example 16 with CoordinatePoint

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());
}
Also used : ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) TargetTime(org.onebusaway.transit_data_federation.model.TargetTime) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Example 17 with CoordinatePoint

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);
}
Also used : XYPoint(org.onebusaway.geospatial.model.XYPoint) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 18 with CoordinatePoint

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;
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) ArrayList(java.util.ArrayList) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 19 with CoordinatePoint

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);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) Test(org.junit.Test)

Example 20 with CoordinatePoint

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);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) ArrayList(java.util.ArrayList) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) Test(org.junit.Test)

Aggregations

CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)57 ArrayList (java.util.ArrayList)22 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)12 Test (org.junit.Test)10 XYPoint (org.onebusaway.geospatial.model.XYPoint)10 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)9 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)7 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)7 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)7 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)6 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)6 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)5 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)4 VehicleLocationRecordBean (org.onebusaway.transit_data.model.realtime.VehicleLocationRecordBean)4 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)4 VehiclePosition (com.google.transit.realtime.GtfsRealtime.VehiclePosition)3 List (java.util.List)3 Min (org.onebusaway.collections.Min)3 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)3 Record (org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record)3