Пример #1
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();
  }
Пример #2
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();
  }