Search in sources :

Example 1 with FeatureCollection

use of org.geojson.FeatureCollection in project OpenTripPlanner by opentripplanner.

the class BanoGeocoder method geocode.

/**
 */
@Override
public GeocoderResults geocode(String address, Envelope bbox) {
    try {
        URL banoUrl = getBanoGeocoderUrl(address, bbox);
        URLConnection conn = banoUrl.openConnection();
        InputStream in = conn.getInputStream();
        FeatureCollection featureCollection = mapper.readValue(in, FeatureCollection.class);
        in.close();
        List<GeocoderResult> geocoderResults = new ArrayList<GeocoderResult>();
        for (Feature feature : featureCollection.getFeatures()) {
            GeoJsonObject geom = feature.getGeometry();
            if (geom instanceof Point) {
                Point p = (Point) geom;
                GeocoderResult res = new GeocoderResult();
                res.setLat(p.getCoordinates().getLatitude());
                res.setLng(p.getCoordinates().getLongitude());
                res.setDescription(feature.getProperties().get("label").toString());
                /*
                     * Note: We also have here as properties a break-down of other details, such as
                     * the house number, street, city, postcode... Can be useful if needed.
                     */
                geocoderResults.add(res);
            } else {
            // Should not happen according to the API
            }
        }
        return new GeocoderResults(geocoderResults);
    } catch (IOException e) {
        LOG.error("Error processing BANO geocoder results", e);
        return new GeocoderResults(e.getLocalizedMessage());
    }
}
Also used : GeocoderResults(org.opentripplanner.geocoder.GeocoderResults) FeatureCollection(org.geojson.FeatureCollection) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Point(org.geojson.Point) IOException(java.io.IOException) GeoJsonObject(org.geojson.GeoJsonObject) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) Feature(org.geojson.Feature) URL(java.net.URL) URLConnection(java.net.URLConnection) GeocoderResult(org.opentripplanner.geocoder.GeocoderResult)

Example 2 with FeatureCollection

use of org.geojson.FeatureCollection in project collect by openforis.

the class SamplingPointsController method loadSamplingPointDataFeatures.

private FeatureCollection loadSamplingPointDataFeatures(CollectSurvey survey) {
    FeatureCollection featureCollection = new FeatureCollection();
    Feature feature = new Feature();
    feature.setProperty("letter", "o");
    feature.setProperty("color", "blue");
    feature.setProperty("rank", "15");
    MultiPoint multiPoint = new MultiPoint();
    CoordinateOperations coordinateOperations = getCoordinateOperations(survey);
    List<SamplingDesignItem> samplingDesignItems = loadSamplingDesignItems(survey);
    for (SamplingDesignItem item : samplingDesignItems) {
        Coordinate coordinate = new Coordinate(item.getX(), item.getY(), item.getSrsId());
        multiPoint.add(createLngLatAlt(coordinateOperations, coordinate));
    }
    feature.setGeometry(multiPoint);
    featureCollection.add(feature);
    return featureCollection;
}
Also used : MultiPoint(org.geojson.MultiPoint) CoordinateOperations(org.openforis.idm.geospatial.CoordinateOperations) FeatureCollection(org.geojson.FeatureCollection) Coordinate(org.openforis.idm.model.Coordinate) Feature(org.geojson.Feature) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Aggregations

Feature (org.geojson.Feature)2 FeatureCollection (org.geojson.FeatureCollection)2 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 ArrayList (java.util.ArrayList)1 GeoJsonObject (org.geojson.GeoJsonObject)1 MultiPoint (org.geojson.MultiPoint)1 Point (org.geojson.Point)1 SamplingDesignItem (org.openforis.collect.model.SamplingDesignItem)1 CoordinateOperations (org.openforis.idm.geospatial.CoordinateOperations)1 Coordinate (org.openforis.idm.model.Coordinate)1 GeocoderResult (org.opentripplanner.geocoder.GeocoderResult)1 GeocoderResults (org.opentripplanner.geocoder.GeocoderResults)1