Search in sources :

Example 6 with CoordinateBounds

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

the class TransitDataServiceTemplateImpl method getAgenciesWithCoverage.

// @Override
public List<AgencyWithCoverageBean> getAgenciesWithCoverage() throws ServiceException {
    Map<String, CoordinateBounds> agencyIdsAndCoverageAreas = _agencyService.getAgencyIdsAndCoverageAreas();
    List<AgencyWithCoverageBean> beans = new ArrayList<AgencyWithCoverageBean>();
    for (Map.Entry<String, CoordinateBounds> entry : agencyIdsAndCoverageAreas.entrySet()) {
        String agencyId = entry.getKey();
        CoordinateBounds bounds = entry.getValue();
        AgencyBean agencyBean = _agencyBeanService.getAgencyForId(agencyId);
        if (agencyBean == null)
            throw new ServiceException("agency not found: " + agencyId);
        AgencyWithCoverageBean bean = new AgencyWithCoverageBean();
        bean.setAgency(agencyBean);
        bean.setLat((bounds.getMaxLat() + bounds.getMinLat()) / 2);
        bean.setLon((bounds.getMaxLon() + bounds.getMinLon()) / 2);
        bean.setLatSpan(bounds.getMaxLat() - bounds.getMinLat());
        bean.setLonSpan(bounds.getMaxLon() - bounds.getMinLon());
        beans.add(bean);
    }
    return beans;
}
Also used : OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException) NoSuchTripServiceException(org.onebusaway.exceptions.NoSuchTripServiceException) ServiceException(org.onebusaway.exceptions.ServiceException) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 7 with CoordinateBounds

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

the class TransitDataServiceTemplateImpl method getAllRevenueStops.

public List<StopBean> getAllRevenueStops(AgencyWithCoverageBean agency) {
    SearchQueryBean query = new SearchQueryBean();
    CoordinateBounds bounds = new CoordinateBounds();
    double lat = agency.getLat();
    double lon = agency.getLon();
    double latSpan = agency.getLatSpan() / 2;
    double lonSpan = agency.getLonSpan() / 2;
    bounds.addPoint(lat - latSpan, lon - lonSpan);
    bounds.addPoint(lat + latSpan, lon + lonSpan);
    query.setBounds(bounds);
    query.setMaxCount(Integer.MAX_VALUE);
    return _scheduleHelperService.filterRevenueService(agency.getAgency(), getStops(query));
}
Also used : CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 8 with CoordinateBounds

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

the class MonitoringActionBase method getBoxBounds.

protected CoordinateBounds getBoxBounds(String boundingCoordinates) throws NumberFormatException {
    CoordinateBounds bounds = null;
    if (boundingCoordinates != null) {
        String[] coordinates = boundingCoordinates.split(",");
        if (coordinates.length >= 4) {
            CoordinateBounds userBounds = new CoordinateBounds(Double.parseDouble(coordinates[0]), Double.parseDouble(coordinates[1]), Double.parseDouble(coordinates[2]), Double.parseDouble(coordinates[3]));
            bounds = userBounds;
        }
    }
    return bounds;
}
Also used : CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 9 with CoordinateBounds

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

the class StopPointsV2Action method index.

public DefaultHttpHeaders index() throws IOException {
    long responseTimestamp = getTime();
    processGoogleAnalytics();
    _realtimeService.setTime(responseTimestamp);
    boolean useLineRefOnly = false;
    Boolean upcomingServiceAllStops = null;
    CoordinateBounds bounds = null;
    boolean validBoundDistance = true;
    // User Parameters
    String boundingBox = _request.getParameter(BOUNDING_BOX);
    String circle = _request.getParameter(CIRCLE);
    String lineRef = _request.getParameter(LINE_REF);
    String directionId = _request.getParameter(DIRECTION_REF);
    String agencyId = _request.getParameter(OPERATOR_REF);
    String hasUpcomingScheduledService = _request.getParameter(UPCOMING_SCHEDULED_SERVICE);
    String detailLevelParam = _request.getParameter(STOP_POINTS_DETAIL_LEVEL);
    // get the detail level parameter or set it to default if not specified
    DetailLevel detailLevel;
    if (DetailLevel.contains(detailLevelParam)) {
        detailLevel = DetailLevel.valueOf(detailLevelParam.toUpperCase());
    } else {
        detailLevel = DetailLevel.NORMAL;
    }
    // Error Strings
    String routeIdsErrorString = "";
    String boundsErrorString = "";
    /* 
     * We need to support the user providing no agency id which means 'all
    agencies'. So, this array will hold a single agency if the user provides it or
    all agencies if the user provides none. We'll iterate over them later while
    querying for vehicles and routes
    */
    List<String> agencyIds = processAgencyIds(agencyId);
    List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
    routeIdsErrorString = processRouteIds(lineRef, routeIds, agencyIds);
    // Calculate Bounds
    try {
        if (StringUtils.isNotBlank(circle)) {
            bounds = getCircleBounds(circle);
            if (bounds != null && !isValidBoundsDistance(bounds, MAX_BOUNDS_RADIUS)) {
                boundsErrorString += "Provided values exceed allowed search radius of " + MAX_BOUNDS_RADIUS + "m ";
                validBoundDistance = false;
            }
        } else if (StringUtils.isNotBlank(boundingBox)) {
            bounds = getBoxBounds(boundingBox);
            if (bounds != null && !isValidBoundBoxDistance(bounds, MAX_BOUNDS_DISTANCE)) {
                boundsErrorString += "Provided values exceed allowed search distance of " + MAX_BOUNDS_DISTANCE + "m ";
                validBoundDistance = false;
            }
        }
    } catch (NumberFormatException nfe) {
        boundsErrorString += ERROR_NON_NUMERIC;
    }
    // Check for case where only LineRef was provided
    if (bounds == null) {
        if (routeIds.size() > 0) {
            useLineRefOnly = true;
        } else {
            boundsErrorString += ERROR_REQUIRED_PARAMS;
        }
    }
    // Setup Filters
    Map<Filters, String> filters = new HashMap<Filters, String>();
    filters.put(Filters.DIRECTION_REF, directionId);
    filters.put(Filters.UPCOMING_SCHEDULED_SERVICE, hasUpcomingScheduledService);
    // Annotated Stop Points
    List<AnnotatedStopPointStructure> stopPoints = new ArrayList<AnnotatedStopPointStructure>();
    Map<Boolean, List<AnnotatedStopPointStructure>> stopPointsMap;
    // Error Handler
    Exception error = null;
    if ((bounds == null && !useLineRefOnly) || (_request.getParameter(LINE_REF) != null && routeIds.size() == 0) || !validBoundDistance) {
        String errorString = (boundsErrorString + " " + routeIdsErrorString).trim();
        error = new Exception(errorString);
    } else {
        if (useLineRefOnly) {
            stopPointsMap = _realtimeService.getAnnotatedStopPointStructures(agencyIds, routeIds, detailLevel, responseTimestamp, filters);
        } else {
            stopPointsMap = _realtimeService.getAnnotatedStopPointStructures(bounds, agencyIds, routeIds, detailLevel, responseTimestamp, filters);
        }
        for (Map.Entry<Boolean, List<AnnotatedStopPointStructure>> entry : stopPointsMap.entrySet()) {
            if (entry.getValue().size() > 0)
                upcomingServiceAllStops = entry.getKey();
            stopPoints.addAll(entry.getValue());
        }
    }
    _response = generateSiriResponse(stopPoints, upcomingServiceAllStops, error, responseTimestamp);
    try {
        this._servletResponse.getWriter().write(getStopPoints());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) AnnotatedStopPointStructure(uk.org.siri.siri_2.AnnotatedStopPointStructure) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) Filters(org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters) DetailLevel(org.onebusaway.api.actions.siri.model.DetailLevel) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 10 with CoordinateBounds

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

the class RealtimeServiceTest method testStopPointsByBounds.

@Test
public void testStopPointsByBounds() throws Exception {
    // MOCKS
    // Coordinate Bounds
    CoordinateBounds bounds = new CoordinateBounds(Double.parseDouble("47.612813"), Double.parseDouble("-122.339662"), Double.parseDouble("47.608813"), Double.parseDouble("-122.337662"));
    // Stops For Bounds
    StopsBean stopsBean = new StopsBean();
    stopsBean.setStops(stops);
    when(transitDataService.getRouteForId("1_100194")).thenReturn(routeBean);
    when(transitDataService.getStops(any(SearchQueryBean.class))).thenReturn(stopsBean);
    when(transitDataService.getStopsForRoute("1_100194")).thenReturn(stopsForRouteBean);
    when(transitDataService.stopHasUpcomingScheduledService(anyString(), anyLong(), anyString(), anyString(), anyString())).thenReturn(true);
    // EXPECTED
    LineDirectionStructure lds = new LineDirectionStructure();
    DirectionRefStructure drs = new DirectionRefStructure();
    LineRefStructure lrs = new LineRefStructure();
    lds.setDirectionRef(drs);
    lds.setLineRef(lrs);
    drs.setValue("0");
    lrs.setValue("1_100194");
    LocationStructure ls = new LocationStructure();
    BigDecimal lat = new BigDecimal(47.610813);
    BigDecimal lon = new BigDecimal(-122.338662);
    ls.setLatitude(lat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
    ls.setLongitude(lon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
    NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
    stopName.setValue("3rd Ave & Pine St");
    List<NaturalLanguageStringStructure> stopNames = new ArrayList<NaturalLanguageStringStructure>();
    stopNames.add(stopName);
    StopPointRefStructure stopPointRef = new StopPointRefStructure();
    stopPointRef.setValue("1_430");
    Boolean monitored = true;
    AnnotatedStopPointStructure mockStopPoint = new AnnotatedStopPointStructure();
    mockStopPoint.setLines(new AnnotatedStopPointStructure.Lines());
    mockStopPoint.getLines().getLineRefOrLineDirection().add(lds);
    mockStopPoint.setLocation(ls);
    mockStopPoint.getStopName().add(stopName);
    mockStopPoint.setStopPointRef(stopPointRef);
    mockStopPoint.setMonitored(monitored);
    // REALTIME ARGUMENTS
    // Agency Ids
    List<String> agencyIds = new ArrayList<String>();
    String agencyId = "1";
    agencyIds.add(agencyId);
    // Route Ids
    List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
    AgencyAndId routeId = AgencyAndIdLibrary.convertFromString("1_100194");
    routeIds.add(routeId);
    // Detail Level
    DetailLevel detailLevel = DetailLevel.NORMAL;
    // Time
    long time = System.currentTimeMillis();
    // Filters
    Map<Filters, String> filters = new HashMap<Filters, String>();
    Map<Boolean, List<AnnotatedStopPointStructure>> actualResult = realtimeService.getAnnotatedStopPointStructures(bounds, agencyIds, routeIds, detailLevel, time, filters);
    AnnotatedStopPointStructure actualStopPoint = actualResult.get(true).get(0);
    assertTrue(isEqual(mockStopPoint, actualStopPoint));
}
Also used : NaturalLanguageStringStructure(uk.org.siri.siri_2.NaturalLanguageStringStructure) LineDirectionStructure(uk.org.siri.siri_2.LineDirectionStructure) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) LocationStructure(uk.org.siri.siri_2.LocationStructure) Filters(org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters) SearchQueryBean(org.onebusaway.transit_data.model.SearchQueryBean) ArrayList(java.util.ArrayList) List(java.util.List) StopPointRefStructure(uk.org.siri.siri_2.StopPointRefStructure) AnnotatedStopPointStructure(uk.org.siri.siri_2.AnnotatedStopPointStructure) LineRefStructure(uk.org.siri.siri_2.LineRefStructure) BigDecimal(java.math.BigDecimal) DetailLevel(org.onebusaway.api.actions.siri.model.DetailLevel) DirectionRefStructure(uk.org.siri.siri_2.DirectionRefStructure) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) StopsBean(org.onebusaway.transit_data.model.StopsBean) Test(org.junit.Test)

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