org.geojson.Polygon p = new org.geojson.Polygon(); List<LngLatAlt> shell = new ArrayList<LngLatAlt>(); for (Coordinate c : polygons[i].getExteriorRing().getCoordinates()) {
int i = 0; for (List<List<LngLatAlt>> geoJsonRings : geoJsonMultiPolygon.getCoordinates()) { org.geojson.Polygon geoJsonPoly = new org.geojson.Polygon(); for (List<LngLatAlt> geoJsonRing : geoJsonRings) geoJsonPoly.add(geoJsonRing);
public static org.geojson.Polygon toGeoJson(Polygon jtsPolygon) { if (jtsPolygon == null) return null; org.geojson.Polygon geoJsonPoly = new org.geojson.Polygon(Arrays.asList(jtsPolygon.getCoordinates()).stream() .map(p -> new LngLatAlt(p.x, p.y)).collect(Collectors.toList())); geoJsonPoly.setCrs(createCrsForEpsgCode(jtsPolygon.getSRID())); return geoJsonPoly; }
/** * Build a bounding box feature. * In this case, it has a name but is empty. * * @param id the ID string * @return the Feature for the new bounds */ public static Feature createBounds(final String id) { final Feature feature = new Feature(); feature.setId(id); feature.setGeometry(new Polygon()); return feature; }
northeast.getLatitude() }; final Polygon polygon = new Polygon(); feature.setGeometry(polygon); polygon.setBbox(bbox);
@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)))); }