Search in sources :

Example 36 with CoordinatePoint

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

the class VehiclePositionsForAgencyAction method fillFeedMessage.

@Override
protected void fillFeedMessage(FeedMessage.Builder feed, String agencyId, long timestamp) {
    ListBean<VehicleStatusBean> vehicles = _service.getAllVehiclesForAgency(agencyId, timestamp);
    for (VehicleStatusBean vehicle : vehicles.getList()) {
        FeedEntity.Builder entity = feed.addEntityBuilder();
        entity.setId(Integer.toString(feed.getEntityCount()));
        VehiclePosition.Builder vehiclePosition = entity.getVehicleBuilder();
        TripStatusBean tripStatus = vehicle.getTripStatus();
        if (tripStatus != null) {
            TripBean activeTrip = tripStatus.getActiveTrip();
            RouteBean route = activeTrip.getRoute();
            TripDescriptor.Builder tripDesc = vehiclePosition.getTripBuilder();
            tripDesc.setTripId(normalizeId(activeTrip.getId()));
            tripDesc.setRouteId(normalizeId(route.getId()));
        }
        VehicleDescriptor.Builder vehicleDesc = vehiclePosition.getVehicleBuilder();
        vehicleDesc.setId(normalizeId(vehicle.getVehicleId()));
        CoordinatePoint location = vehicle.getLocation();
        if (location != null) {
            Position.Builder position = vehiclePosition.getPositionBuilder();
            position.setLatitude((float) location.getLat());
            position.setLongitude((float) location.getLon());
        }
        vehiclePosition.setTimestamp(vehicle.getLastUpdateTime() / 1000);
    }
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) VehiclePosition(com.google.transit.realtime.GtfsRealtime.VehiclePosition) Position(com.google.transit.realtime.GtfsRealtime.Position) TripBean(org.onebusaway.transit_data.model.trips.TripBean) VehicleStatusBean(org.onebusaway.transit_data.model.VehicleStatusBean) RouteBean(org.onebusaway.transit_data.model.RouteBean) VehiclePosition(com.google.transit.realtime.GtfsRealtime.VehiclePosition) TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) VehicleDescriptor(com.google.transit.realtime.GtfsRealtime.VehicleDescriptor)

Example 37 with CoordinatePoint

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

the class FederatedByCoordinatePointsMethodInvocationHandlerImpl method invoke.

public Object invoke(FederatedServiceCollection collection, Method method, Object[] args) throws ServiceAreaServiceException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    List<CoordinatePoint> points = new ArrayList<CoordinatePoint>();
    for (int i = 0; i < _argumentIndices.length; i++) {
        Object value = args[_argumentIndices[i]];
        PropertyPathExpression expression = _expressions[i];
        if (expression != null)
            value = expression.invoke(value);
        CoordinatePoint point = (CoordinatePoint) value;
        points.add(point);
    }
    FederatedService service = collection.getServiceForLocations(points);
    return method.invoke(service, args);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) FederatedService(org.onebusaway.federations.FederatedService) ArrayList(java.util.ArrayList) PropertyPathExpression(org.onebusaway.collections.beans.PropertyPathExpression) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 38 with CoordinatePoint

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

the class GtfsController method getStops.

@RequestMapping(value = "/stops/{agencyId}/{id}")
@ResponseBody
public List<CoordinatePoint> getStops(@PathVariable String agencyId, @PathVariable String id) {
    AgencyAndId routeId = new AgencyAndId(agencyId, id);
    RouteEntry route = _transitGraphDao.getRouteForId(routeId);
    TripEntry trip = routeToTrip(route);
    List<StopTimeEntry> stopTimes = trip.getStopTimes();
    List<CoordinatePoint> points = new ArrayList<CoordinatePoint>();
    for (StopTimeEntry entry : stopTimes) {
        StopEntry stop = entry.getStop();
        points.add(stop.getStopLocation());
    }
    return points;
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) ArrayList(java.util.ArrayList) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 39 with CoordinatePoint

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

the class PolylineEncoderTest method test2.

@Test
public void test2() {
    List<CoordinatePoint> points = new ArrayList<CoordinatePoint>();
    points.add(new CoordinatePoint(47.67839087880088, -122.27878118907307));
    points.add(new CoordinatePoint(47.67845871865856, -122.27342376951559));
    points.add(new CoordinatePoint(47.682076843204875, -122.2735240417865));
    String expected = "}d_bHlqiiVKo`@sUR";
    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)

Example 40 with CoordinatePoint

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

the class SphericalGeometryLibraryTest method testProjectPointToSegmentApproximate.

@Test
public void testProjectPointToSegmentApproximate() {
    CoordinatePoint p = new CoordinatePoint(40.737284, -73.955430);
    CoordinatePoint seg1 = new CoordinatePoint(40.737997, -73.955472);
    CoordinatePoint seg2 = new CoordinatePoint(40.734575, -73.954979);
    CoordinatePoint r = SphericalGeometryLibrary.projectPointToSegmentAppropximate(p, seg1, seg2);
    assertEquals(40.73729256997116, r.getLat(), 0.0);
    assertEquals(-73.95537051431788, r.getLon(), 0.0);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) 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