Search in sources :

Example 1 with MultiPolygon

use of org.locationtech.jts.geom.MultiPolygon in project arctic-sea by 52North.

the class GeoJSONEncoder method encode.

protected ObjectNode encode(MultiPolygon geometry, int parentSrid) {
    Preconditions.checkNotNull(geometry);
    ObjectNode json = jsonFactory.objectNode();
    ArrayNode list = json.put(JSONConstants.TYPE, JSONConstants.MULTI_POLYGON).putArray(JSONConstants.COORDINATES);
    for (int i = 0; i < geometry.getNumGeometries(); ++i) {
        list.add(encodeCoordinates((Polygon) geometry.getGeometryN(i)));
    }
    encodeCRS(json, geometry, parentSrid);
    return json;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 2 with MultiPolygon

use of org.locationtech.jts.geom.MultiPolygon in project arctic-sea by 52North.

the class GeoJSONDecoder method decodeMultiPolygon.

protected MultiPolygon decodeMultiPolygon(JsonNode node, GeometryFactory fac) throws GeoJSONDecodingException {
    JsonNode coordinates = requireCoordinates(node);
    Polygon[] polygons = new Polygon[coordinates.size()];
    for (int i = 0; i < coordinates.size(); ++i) {
        polygons[i] = decodePolygonCoordinates(coordinates.get(i), fac);
    }
    return fac.createMultiPolygon(polygons);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 3 with MultiPolygon

use of org.locationtech.jts.geom.MultiPolygon in project arctic-sea by 52North.

the class GeoJSONTest method testMultiPolygonWithZCoordinate.

@Test
public void testMultiPolygonWithZCoordinate() throws GeoJSONDecodingException, IOException {
    MultiPolygon geometry = randomMultiPolygon(EPSG_4326);
    geometry.apply(new RandomZCoordinateFilter());
    geometry.geometryChanged();
    readWriteTest(geometry);
}
Also used : MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Test(org.junit.Test)

Example 4 with MultiPolygon

use of org.locationtech.jts.geom.MultiPolygon in project arctic-sea by 52North.

the class GeoJSONTest method randomMultiPolygon.

private MultiPolygon randomMultiPolygon(int srid) {
    MultiPolygon geometry = geometryFactory.createMultiPolygon(new Polygon[] { randomPolygon(srid), randomPolygon(srid), randomPolygon(srid) });
    geometry.setSRID(srid);
    return geometry;
}
Also used : MultiPolygon(org.locationtech.jts.geom.MultiPolygon)

Aggregations

MultiPolygon (org.locationtech.jts.geom.MultiPolygon)4 MultiPoint (org.locationtech.jts.geom.MultiPoint)2 Point (org.locationtech.jts.geom.Point)2 Polygon (org.locationtech.jts.geom.Polygon)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Test (org.junit.Test)1