Search in sources :

Example 1 with Feature

use of org.geojson.Feature 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)

Example 2 with Feature

use of org.geojson.Feature 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 3 with Feature

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

the class PointFeature method fromJsonNode.

@SuppressWarnings("unchecked")
public static PointFeature fromJsonNode(JsonNode feature) throws EmptyPolygonException, UnsupportedGeometryException {
    Feature geoJsonFeature;
    try {
        geoJsonFeature = deserializer.readValue(feature.traverse(), Feature.class);
    } catch (IOException e) {
        throw new UnsupportedGeometryException(e.getMessage());
    }
    PointFeature ret = new PointFeature(geoJsonFeature.getId());
    ret.setGeom(GeometryUtils.convertGeoJsonToJtsGeometry(geoJsonFeature.getGeometry()));
    Object structured = geoJsonFeature.getProperty("structured");
    if (structured == null || !(structured instanceof Map))
        return null;
    // The code below assume the structured map to have integers only
    ret.setAttributes((Map<String, Integer>) (structured));
    return ret;
}
Also used : IOException(java.io.IOException) Feature(org.geojson.Feature) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with Feature

use of org.geojson.Feature in project onebusaway-gtfs-modules by OneBusAway.

the class LocationsGeoJSONReader method read.

public Collection<Location> read() throws IOException {
    FeatureCollection featureCollection = new ObjectMapper().readValue(reader, FeatureCollection.class);
    Collection<Location> locations = new ArrayList<>(featureCollection.getFeatures().size());
    for (Feature feature : featureCollection.getFeatures()) {
        Location location = new Location();
        location.setId(new AgencyAndId(this.defaultAgencyId, feature.getId()));
        location.setGeometry(feature.getGeometry());
        location.setName((String) feature.getProperties().get("stop_name"));
        location.setDescription((String) feature.getProperties().get("stop_description"));
        location.setUrl((String) feature.getProperties().get("stop_url"));
        location.setZoneId((String) feature.getProperties().get("zone_id"));
        locations.add(location);
    }
    return locations;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) FeatureCollection(org.geojson.FeatureCollection) ArrayList(java.util.ArrayList) Feature(org.geojson.Feature) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Location(org.onebusaway.gtfs.model.Location)

Example 5 with Feature

use of org.geojson.Feature in project dhis2-core by dhis2.

the class AttributeValueServiceTest method testGeoJSONAttributeValue.

@Test
void testGeoJSONAttributeValue() throws JsonProcessingException {
    Attribute attribute = new Attribute();
    attribute.setValueType(ValueType.GEOJSON);
    attribute.setName("attributeGeoJson");
    attributeService.addAttribute(attribute);
    String geoJson = "{\"type\": \"Feature\", \"geometry\": { \"type\": \"Point\"," + "\"coordinates\": [125.6, 10.1] }, \"properties\": { \"name\": \"Dinagat Islands\" } }";
    AttributeValue avA = new AttributeValue(geoJson, attribute);
    dataElementA.getAttributeValues().add(avA);
    dataElementStore.save(dataElementA);
    List<DataElement> dataElements = dataElementStore.getByAttribute(attribute);
    assertEquals(1, dataElements.size());
    assertEquals(dataElementA.getUid(), dataElements.get(0).getUid());
    dataElements = dataElementStore.getByAttributeAndValue(attribute, geoJson);
    assertEquals(1, dataElements.size());
    assertEquals(dataElementA.getUid(), dataElements.get(0).getUid());
    DataElement dataElement = dataElements.get(0);
    AttributeValue av = dataElement.getAttributeValues().iterator().next();
    GeoJsonObject geoJsonObject = new ObjectMapper().readValue(av.getValue(), GeoJsonObject.class);
    assertTrue(geoJsonObject instanceof Feature);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) GeoJsonObject(org.geojson.GeoJsonObject) Feature(org.geojson.Feature) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Feature (org.geojson.Feature)6 FeatureCollection (org.geojson.FeatureCollection)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ArrayList (java.util.ArrayList)3 GeoJsonObject (org.geojson.GeoJsonObject)3 IOException (java.io.IOException)2 Map (java.util.Map)2 MultiPoint (org.geojson.MultiPoint)2 Point (org.geojson.Point)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1