LinearRing shell = gf.createLinearRing(convertPath(geoJsonPolygon.getExteriorRing())); LinearRing[] holes = new LinearRing[geoJsonPolygon.getInteriorRings().size()]; int i = 0; for (List<LngLatAlt> hole : geoJsonPolygon.getInteriorRings()) { holes[i++] = gf.createLinearRing(convertPath(hole)); 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); jtsPolygons[i++] = (Polygon) convertGeoJsonToJtsGeometry(geoJsonPoly);
org.geojson.Polygon p = new org.geojson.Polygon(); List<LngLatAlt> shell = new ArrayList<LngLatAlt>(); for (Coordinate c : polygons[i].getExteriorRing().getCoordinates()) { shell.add(new LngLatAlt(c.x, c.y)); p.add(shell); geomSerializer.writeValue(jgen, p); } else {
public MultiPolygon add(Polygon polygon) { coordinates.add(polygon.getCoordinates()); return this; }
northeast.getLatitude() }; final Polygon polygon = new Polygon(); feature.setGeometry(polygon); polygon.setBbox(bbox); final List<LngLatAlt> elements = new ArrayList<>(5); elements.add(new LngLatAlt(bbox[SW_LNG], bbox[SW_LAT])); elements.add(new LngLatAlt(bbox[SW_LNG], bbox[NE_LAT])); elements.add(new LngLatAlt(bbox[SW_LNG], bbox[SW_LAT])); polygon.add(elements); feature.setBbox(bbox); return feature;
public static Polygon toJts(org.geojson.Polygon polygon) { if (polygon.getInteriorRings().size() > 0) { throw new UnsupportedOperationException("Only polygons without holes are supported!"); } String geoJsonCrs = polygon.getCrs().getProperties().get(org.geojson.jackson.CrsType.name.name()).toString(); GeometryFactory gf = new GeometryFactory(new PrecisionModel(), Integer.parseInt(geoJsonCrs.substring(CRS_URN_BASE_EPSG.length()))); return toJts(polygon.getExteriorRing(), gf); }
public Polygon(List<LngLatAlt> polygon) { add(polygon); }
/** * 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; }
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; }
public List<LngLatAlt> getInteriorRing(int index) { assertExteriorRing(); return coordinates.get(1 + index); }
private Optional<? extends LatLon> createPoiFromGeoJson(final GeoJsonObject object) { if (object instanceof Point) { final Point p = (Point) object; return toGeoLocation(p.getCoordinates()); } else if (object instanceof Polygon) { final Polygon p = (Polygon) object; return toGeoLocation(p.getExteriorRing(), true); } else if (object instanceof LineString) { return toGeoLocation(((LineString) object).getCoordinates(), false); } else if (object instanceof MultiPolygon) { return toGeoLocation((MultiPolygon) object); } else if (object instanceof MultiPoint) { return ((MultiPoint) object) .getCoordinates() .stream() .map(this::toGeoLocation) .filter(Optional::isPresent) .map(Optional::get) .findFirst(); } else { // TODO: Could implement others here but Baleen currently only outputs the above .. } return Optional.empty(); }
public MultiPolygon add(Polygon polygon) { coordinates.add(polygon.getCoordinates()); return this; }
public Polygon(List<LngLatAlt> polygon) { add(polygon); }
@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)))); }
public List<LngLatAlt> getInteriorRing(int index) { assertExteriorRing(); return coordinates.get(1 + index); }
/** * Create a Bounds from a GeoServiceBounds. * * @param feature the bounding box feature * @return the Bounds */ default Bounds toBounds(final Feature feature) { if (feature == null) { return null; } final Polygon polygon = (Polygon) feature.getGeometry(); final List<List<LngLatAlt>> coordinates = polygon.getCoordinates(); if (coordinates == null || coordinates.isEmpty()) { return new Bounds(); } final List<LngLatAlt> list = coordinates.get(0); final Bounds bounds = toBounds(list.get(2), list.get(0)); return bounds; }
public Polygon(LngLatAlt... polygon) { add(Arrays.asList(polygon)); }
public void addInteriorRing(List<LngLatAlt> points) { assertExteriorRing(); coordinates.add(points); }
.getGeometry(); final List<List<LngLatAlt>> viewportRings = viewportPolygon .getCoordinates(); final List<LngLatAlt> viewportOutline = viewportRings.get(0); final LngLatAlt southwest = viewportOutline.get(0);
public Polygon(LngLatAlt... polygon) { add(Arrays.asList(polygon)); }
public void addInteriorRing(List<LngLatAlt> points) { assertExteriorRing(); coordinates.add(points); }