/** * Converts to a {@link Polygon}. * * @return Polygon * @throws IllegalArgumentException if this MultiLineString contains an open {@link LineString} or it is empty. */ public Polygon toPolygon() { return new Polygon(positions()); }
/** * Converts to a {@link Polygon}. * * @return Polygon * @throws IllegalArgumentException if this MultiLineString contains an open {@link LineString} or it is empty. */ public Polygon toPolygon() { return new Polygon(positions()); }
/** * Creates a Polygon from the given perimeter and holes. * * @param perimeter The perimeter {@link LinearRing}. * @param holes The holes {@link LinearRing} Stream. * * @return Polygon */ public static Polygon of(LinearRing perimeter, Stream<LinearRing> holes) { return new Polygon(AreaPositions.builder() .addLinearPosition(perimeter.positions()) .addLinearPositions(holes .map(LinearRing::positions)::iterator) .build()); }
/** * Creates a Polygon from the given perimeter and holes. * * @param perimeter The perimeter {@link LinearRing}. * @param holes The holes {@link LinearRing} Stream. * * @return Polygon */ public static Polygon of(LinearRing perimeter, Stream<LinearRing> holes) { return new Polygon(AreaPositions.builder() .addLinearPosition(perimeter.positions()) .addLinearPositions(holes .map(LinearRing::positions)::iterator) .build()); }
private Geometry<?> buildGeometry(final Geometry.Type type, final Positions positions, final Geometry<?> geometries) { switch (type) { case GEOMETRY_COLLECTION: return geometries; case MULTI_POLYGON: return new MultiPolygon((MultiDimensionalPositions) positions); case POLYGON: return new Polygon((AreaPositions) positions); case MULTI_LINE_STRING: return new MultiLineString((AreaPositions) positions); case LINEAR_RING: case LINE_STRING: return ((LinearPositions) positions).isClosed() ? new LinearRing((LinearPositions) positions) : new LineString((LinearPositions) positions); case MULTI_POINT: if (positions instanceof SinglePosition) { return new MultiPoint(LinearPositions.builder().addSinglePosition((SinglePosition) positions).build()); } else { return new MultiPoint((LinearPositions) positions); } case POINT: return new Point(((SinglePosition) positions)); default: throw new IllegalArgumentException("Cannot build a geometry for type: " + type); } }
private Geometry<?> buildGeometry(final Geometry.Type type, final Positions positions, final Geometry<?> geometries) { switch (type) { case GEOMETRY_COLLECTION: return geometries; case MULTI_POLYGON: return new MultiPolygon((MultiDimensionalPositions) positions); case POLYGON: return new Polygon((AreaPositions) positions); case MULTI_LINE_STRING: return new MultiLineString((AreaPositions) positions); case LINEAR_RING: case LINE_STRING: return ((LinearPositions) positions).isClosed() ? new LinearRing((LinearPositions) positions) : new LineString((LinearPositions) positions); case MULTI_POINT: if (positions instanceof SinglePosition) { return new MultiPoint(LinearPositions.builder().addSinglePosition((SinglePosition) positions).build()); } else { return new MultiPoint((LinearPositions) positions); } case POINT: return new Point(((SinglePosition) positions)); default: throw new IllegalArgumentException("Cannot build a geometry for type: " + type); } }