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;
}
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());
}
}
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;
}
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;
}
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);
}
Aggregations