Ejemplo n.º 1
0
  /**
   * make sure outer ring is CCW and holes are CW
   *
   * @param p polygon to check
   */
  Polygon makeGoodSHAPEPolygon(Polygon p) {
    LinearRing outer;
    LinearRing[] holes = new LinearRing[p.getNumInteriorRing()];
    Coordinate[] coords;

    coords = p.getExteriorRing().getCoordinates();

    if (cga.isCCW(coords)) {
      outer = reverseRing((LinearRing) p.getExteriorRing());
    } else {
      outer = (LinearRing) p.getExteriorRing();
    }

    for (int t = 0; t < p.getNumInteriorRing(); t++) {
      coords = p.getInteriorRingN(t).getCoordinates();

      if (!(cga.isCCW(coords))) {
        holes[t] = reverseRing((LinearRing) p.getInteriorRingN(t));
      } else {
        holes[t] = (LinearRing) p.getInteriorRingN(t);
      }
    }

    return new Polygon(outer, holes, new PrecisionModel(), 0);
  }
Ejemplo n.º 2
0
  public Geobuf.Data.Geometry polyToGeobuf(Polygon poly) {
    Geobuf.Data.Geometry.Builder builder =
        Geobuf.Data.Geometry.newBuilder().setType(Geobuf.Data.Geometry.Type.POLYGON);

    Stream<LineString> interiorRings =
        IntStream.range(0, poly.getNumInteriorRing()).mapToObj(poly::getInteriorRingN);

    Stream.concat(Stream.of(poly.getExteriorRing()), interiorRings)
        .forEach(r -> addRing(r, builder));

    return builder.build();
  }
Ejemplo n.º 3
0
  public Geobuf.Data.Geometry multiPolyToGeobuf(MultiPolygon poly) {
    Geobuf.Data.Geometry.Builder builder =
        Geobuf.Data.Geometry.newBuilder().setType(Geobuf.Data.Geometry.Type.MULTIPOLYGON);

    // first we specify the number of polygons
    builder.addLengths(poly.getNumGeometries());

    for (int i = 0; i < poly.getNumGeometries(); i++) {
      Polygon p = (Polygon) poly.getGeometryN(i);
      // how many rings there are
      builder.addLengths(p.getNumInteriorRing() + 1);

      Stream<LineString> interiorRings =
          IntStream.range(0, p.getNumInteriorRing()).<LineString>mapToObj(p::getInteriorRingN);

      Stream.concat(Stream.of(p.getExteriorRing()), interiorRings)
          .forEach(r -> addRing(r, builder));
    }

    return builder.build();
  }