Search in sources :

Example 1 with EnterpriseGeocoderResult

use of org.onebusaway.geocoder.enterprise.services.EnterpriseGeocoderResult in project onebusaway-application-modules by camsys.

the class SearchServiceImpl method tryAsLatLon.

private void tryAsLatLon(SearchResultCollection results, String rawQuery, SearchResultFactory resultFactory) {
    List<SearchResult> routesNearby = null;
    Matcher m = latLonPattern.matcher(rawQuery);
    if (m.find()) {
        String latStr = m.group(1) + m.group(2);
        String lonStr = m.group(5) + m.group(6);
        _log.info("parse lat/lon = " + latStr + ", " + lonStr);
        try {
            Double lat = Double.parseDouble(latStr);
            Double lon = Double.parseDouble(lonStr);
            EnterpriseGeocoderResult egr = new SimpleEnterpriseGeocoderResult(lat, lon);
            _log.info("found lat/lon");
            results.addMatch(resultFactory.getGeocoderResult(egr, results.getRouteFilter()));
        } catch (Exception any) {
            _log.info("no results, exception=" + any);
        }
    }
}
Also used : EnterpriseGeocoderResult(org.onebusaway.geocoder.enterprise.services.EnterpriseGeocoderResult) Matcher(java.util.regex.Matcher) SearchResult(org.onebusaway.presentation.model.SearchResult) OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException) NoSuchStopServiceException(org.onebusaway.exceptions.NoSuchStopServiceException)

Example 2 with EnterpriseGeocoderResult

use of org.onebusaway.geocoder.enterprise.services.EnterpriseGeocoderResult in project onebusaway-application-modules by camsys.

the class EnterpriseFilteredGeocoderBase method filterResultsByWktPolygon.

protected List<EnterpriseGeocoderResult> filterResultsByWktPolygon(List<EnterpriseGeocoderResult> input) {
    if (_wktFilterPolygon == null) {
        return input;
    }
    List<EnterpriseGeocoderResult> output = new ArrayList<EnterpriseGeocoderResult>();
    for (EnterpriseGeocoderResult result : input) {
        Coordinate coordinate = new Coordinate(result.getLongitude(), result.getLatitude());
        Geometry point = _geometryFactory.createPoint(coordinate);
        if (_wktFilterPolygon.intersects(point)) {
            output.add(result);
        }
    }
    return output;
}
Also used : EnterpriseGeocoderResult(org.onebusaway.geocoder.enterprise.services.EnterpriseGeocoderResult) Geometry(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) ArrayList(java.util.ArrayList)

Example 3 with EnterpriseGeocoderResult

use of org.onebusaway.geocoder.enterprise.services.EnterpriseGeocoderResult in project onebusaway-application-modules by camsys.

the class EnterpriseBingGeocoderImpl method enterpriseGeocode.

public List<EnterpriseGeocoderResult> enterpriseGeocode(String location, String id, String key) {
    try {
        List<EnterpriseGeocoderResult> results = new ArrayList<EnterpriseGeocoderResult>();
        StringBuilder q = new StringBuilder();
        q.append("includeNeighborhood=true");
        q.append("&output=xml");
        if (location != null && StringUtils.isNotBlank(_regionalSuggestion) && location.indexOf(",") == -1) {
            location = location + ", " + _regionalSuggestion;
        }
        String encodedLocation = URLEncoder.encode(location, "UTF-8");
        q.append("&query=").append(encodedLocation);
        if (_resultBiasingBounds != null) {
            q.append("&userMapView=").append(_resultBiasingBounds.getMinLat() + "," + _resultBiasingBounds.getMinLon() + "," + _resultBiasingBounds.getMaxLat() + "," + _resultBiasingBounds.getMaxLon());
        }
        String secretKey = key;
        if (secretKey != null && !StringUtils.isEmpty(secretKey)) {
            q.append("&key=").append(secretKey);
        }
        URL url = new URL(GEOCODE_URL_PREFIX + "?" + q.toString());
        Digester digester = createDigester();
        digester.push(results);
        _log.debug("Requesting " + url.toString());
        InputStream inputStream = url.openStream();
        digester.parse(inputStream);
        _log.debug("Got " + results.size() + " geocoder results.");
        results = filterResultsByWktPolygon(results);
        _log.debug("Have " + results.size() + " geocoder results AFTER filtering.");
        return results;
    } catch (Exception e) {
        _log.error("Geocoding error: " + e.getMessage());
        return null;
    }
}
Also used : EnterpriseGeocoderResult(org.onebusaway.geocoder.enterprise.services.EnterpriseGeocoderResult) InputStream(java.io.InputStream) Digester(org.apache.commons.digester.Digester) ArrayList(java.util.ArrayList) URL(java.net.URL)

Example 4 with EnterpriseGeocoderResult

use of org.onebusaway.geocoder.enterprise.services.EnterpriseGeocoderResult in project onebusaway-application-modules by camsys.

the class EnterpriseGoogleGeocoderImpl method enterpriseGeocode.

public List<EnterpriseGeocoderResult> enterpriseGeocode(String location) {
    try {
        List<EnterpriseGeocoderResult> results = new ArrayList<EnterpriseGeocoderResult>();
        StringBuilder q = new StringBuilder();
        q.append("sensor=").append(_sensor);
        String encodedLocation = URLEncoder.encode(location, "UTF-8");
        q.append("&address=").append(encodedLocation);
        if (_resultBiasingBounds != null) {
            q.append("&bounds=").append(_resultBiasingBounds.getMinLat() + "," + _resultBiasingBounds.getMinLon() + "|" + _resultBiasingBounds.getMaxLat() + "," + _resultBiasingBounds.getMaxLon());
        }
        String clientId = _configurationService.getConfigurationValueAsString("display.googleMapsClientId", null);
        String authKey = _configurationService.getConfigurationValueAsString("display.googleMapsSecretKey", null);
        String channelId = _configurationService.getConfigurationValueAsString("display.googleMapsChannelId", null);
        // Fail if we don't have client key, auth key, channel id
        if (StringUtils.isEmpty(clientId) || StringUtils.isEmpty(authKey) || StringUtils.isEmpty(channelId)) {
            _log.warn("No clientId, authKey, or channelId. Not accessing Google.");
            return Collections.emptyList();
        }
        q.append("&client=").append(clientId);
        q.append("&channel=").append(channelId);
        URL url = new URL(GEOCODE_URL_PREFIX + signRequest(authKey, GEOCODE_PATH + "?" + q.toString()));
        Digester digester = createDigester();
        digester.push(results);
        _log.debug("Requesting " + url.toString());
        InputStream inputStream = url.openStream();
        digester.parse(inputStream);
        _log.debug("Got " + results.size() + " geocoder results.");
        results = filterResultsByWktPolygon(results);
        _log.debug("Have " + results.size() + " geocoder results AFTER filtering.");
        return results;
    } catch (Exception e) {
        _log.error("Geocoding error: " + e.getMessage());
        return null;
    }
}
Also used : EnterpriseGeocoderResult(org.onebusaway.geocoder.enterprise.services.EnterpriseGeocoderResult) InputStream(java.io.InputStream) Digester(org.apache.commons.digester.Digester) ArrayList(java.util.ArrayList) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

EnterpriseGeocoderResult (org.onebusaway.geocoder.enterprise.services.EnterpriseGeocoderResult)4 ArrayList (java.util.ArrayList)3 InputStream (java.io.InputStream)2 URL (java.net.URL)2 Digester (org.apache.commons.digester.Digester)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URISyntaxException (java.net.URISyntaxException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Matcher (java.util.regex.Matcher)1 NoSuchStopServiceException (org.onebusaway.exceptions.NoSuchStopServiceException)1 OutOfServiceAreaServiceException (org.onebusaway.exceptions.OutOfServiceAreaServiceException)1 SearchResult (org.onebusaway.presentation.model.SearchResult)1