geomSerializer.writeValue(jgen, p); } else { org.geojson.Point p = new org.geojson.Point(lons[i], lats[i]); geomSerializer.writeValue(jgen, p);
/** * Create a GeoJSON Point from a LatLng. * * @param latLng the LatLng * @return the GeoServiceLatLng */ default Point toPoint(final LatLng latLng) { if (latLng == null) { return null; } return new Point(latLng.lng, latLng.lat); } }
private Feature buildFeature() { Feature feature = new Feature(); feature.setGeometry(new Point(Math.random() * 360 - 180, Math.random() * 180 - 90)); feature.setProperty("key", instanceIdSeq.getAndIncrement()); feature.setProperty("field", "some-field"); feature.setProperty("empty", "no"); feature.setProperty("valid", "yes"); return feature; } }
public static org.geojson.Point toGeoJson(Point jtsPoint) { if (jtsPoint == null) return null; org.geojson.Point geoJsonPoint = new org.geojson.Point(new LngLatAlt(jtsPoint.getX(), jtsPoint.getY())); geoJsonPoint.setCrs(createCrsForEpsgCode(jtsPoint.getSRID())); return geoJsonPoint; }
/** * Create a GeoJSON Point from a LatLng. * * @param latLng the LatLng * @param locationType the location type * @return the GeoServiceLatLng */ default Feature toLocationFeature(final LatLng latLng, final LocationType locationType) { if (latLng == null) { final Feature feature = new Feature(); feature.setProperty("locationType", locationType); feature.setId("location"); return feature; } final Point point = new Point(latLng.lng, latLng.lat); final Feature feature = new Feature(); feature.setGeometry(point); feature.setProperty("locationType", locationType); feature.setId("location"); return feature; } }
@Test public void transforms_a_submission_to_a_feature_list() throws IOException, XmlPullParserException { Map<String, Feature> features = getFeatures( Pair.of(GEOPOINT, "1 2 3"), Pair.of(GEOTRACE, "1 2;3 4"), Pair.of(GEOSHAPE, "1 2;3 4;5 6;1 2") ).stream().collect(toMap( f -> f.getProperty("field"), f -> f )); assertThat(features.values(), hasSize(3)); assertThat(features.values(), allMatch(feature -> feature.getProperty("key").equals("uuid:39f3dd36-161e-45cb-a1a4-395831d253a7"))); assertThat(features.values(), allMatch(feature -> feature.getProperty("empty").equals("no"))); assertThat(features.get("some-field-1").getGeometry(), is(new Point(2, 1, 3))); assertThat(features.get("some-field-2").getGeometry(), is(new LineString(new LngLatAlt(2, 1), new LngLatAlt(4, 3)))); assertThat(features.get("some-field-3").getGeometry(), is(new Polygon(new LngLatAlt(2, 1), new LngLatAlt(4, 3), new LngLatAlt(6, 5), new LngLatAlt(2, 1)))); }