Java Code Examples for org.locationtech.jts.geom.MultiPolygon#getNumGeometries()

The following examples show how to use org.locationtech.jts.geom.MultiPolygon#getNumGeometries() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TWKBWriter.java    From geowave with Apache License 2.0 6 votes vote down vote up
private void writeMultiPolygon(
    final MultiPolygon multiPolygon,
    final PrecisionWriter precision,
    final DataOutput output) throws IOException {
  Varint.writeUnsignedVarInt(multiPolygon.getNumGeometries(), output);
  for (int i = 0; i < multiPolygon.getNumGeometries(); i++) {
    final Polygon polygon = (Polygon) multiPolygon.getGeometryN(i);
    if (polygon.isEmpty()) {
      Varint.writeUnsignedVarInt(0, output);
      continue;
    }
    Varint.writeUnsignedVarInt(polygon.getNumInteriorRing() + 1, output);
    precision.writePointArray(polygon.getExteriorRing().getCoordinates(), output);
    for (int j = 0; j < polygon.getNumInteriorRing(); j++) {
      precision.writePointArray(polygon.getInteriorRingN(j).getCoordinates(), output);
    }
  }
}
 
Example 2
Source File: GeoJSONEncoder.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: MultiPolygonUtils.java    From geofence with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Simplifies a MultiPolygon.
 * <BR/><BR/>
 * Simplification is performed by first removing collinear points, then
 * by applying DouglasPeucker simplification.
 * <BR/>Order <B>is</B> important, since it's more likely to have collinear
 * points before applying any other simplification.
 */
public static MultiPolygon simplifyMultiPolygon(final MultiPolygon mp)
{

    final Polygon[] simpPolys = new Polygon[mp.getNumGeometries()];

    for (int i = 0; i < mp.getNumGeometries(); i++)
    {
        Polygon p = (Polygon) mp.getGeometryN(i);
        Polygon s1 = p; //Utils.removeCollinearVertices(p);
        TopologyPreservingSimplifier tps = new TopologyPreservingSimplifier(s1);
        Polygon s2 = (Polygon) tps.getResultGeometry();
        simpPolys[i] = s2;

        if (LOGGER.isInfoEnabled())
        {
            LOGGER.info("RCV: simplified poly " + getPoints(p) +
                " --> " + getPoints(s1) +
                " --> " + getPoints(s2));
        }
    }

    // reuse existing factory
    final GeometryFactory gf = mp.getFactory();

    return gf.createMultiPolygon(simpPolys);
}
 
Example 4
Source File: GeoJSONUtils.java    From crate with Apache License 2.0 5 votes vote down vote up
private double[][][][] extract(MultiPolygon multiPolygon) {
    int size = multiPolygon.getNumGeometries();
    double[][][][] polygons = new double[size][][][];
    for (int i = 0; i < size; i++) {
        polygons[i] = extract((Polygon) multiPolygon.getGeometryN(i));
    }
    return polygons;
}
 
Example 5
Source File: ShapeWriter.java    From geopaparazzi with GNU General Public License v3.0 5 votes vote down vote up
private DrawableShape toShape(MultiPolygon mp) {
    GeometryCollectionShape shapes = new GeometryCollectionShape();
    for (int i = 0; i < mp.getNumGeometries(); i++) {
        Polygon polygon = (Polygon) mp.getGeometryN(i);
        DrawableShape shape = toShape(polygon);
        shapes.add(shape);
    }
    return shapes;
}
 
Example 6
Source File: JtsPolygonIterable.java    From geogson with Apache License 2.0 5 votes vote down vote up
public static JtsPolygonIterable of(final MultiPolygon src) {
    return new JtsPolygonIterable(new PolygonProvider() {
        @Override
        public int getNumPolygons() {
            return src.getNumGeometries();
        }

        @Override
        public Polygon getPolygonN(int n) {
            return (Polygon) src.getGeometryN(n);
        }
    });
}
 
Example 7
Source File: GeoUtils.java    From elasticsearch-plugin-geoshape with MIT License 3 votes vote down vote up
public static MultiPolygon removeDuplicateCoordinates(MultiPolygon multiPolygon) {

        Polygon[] polygons = new Polygon[multiPolygon.getNumGeometries()];

        for (int i = 0; i < multiPolygon.getNumGeometries(); i++) {
            polygons[i] = (Polygon) removeDuplicateCoordinates(multiPolygon.getGeometryN(i));
        }

        return multiPolygon.getFactory().createMultiPolygon(polygons);
    }
 
Example 8
Source File: GeometryTransform.java    From sis with Apache License 2.0 3 votes vote down vote up
/**
 * Transforms the given polygons. Can be invoked directly if the type is known at compile-time,
 * or indirectly through a call to the more generic {@link #transform(Geometry)} method.
 *
 * @param  geom  the polygons to transform.
 * @return the transformed polygons.
 * @throws TransformException if an error occurred while transforming a geometry.
 */
public MultiPolygon transform(final MultiPolygon geom) throws TransformException {
    final Polygon[] subs = new Polygon[geom.getNumGeometries()];
    for (int i = 0; i < subs.length; i++) {
        subs[i] = transform((Polygon) geom.getGeometryN(i));
    }
    return geometryFactory.createMultiPolygon(subs);
}