/** * Creates a MultiPoint from the given points. * * @param points The {@link Point} sequence. * @return MultiPoint */ public static MultiPoint of(Point... points) { return of(Arrays.asList(points)); }
/** * Converts to a MultiPoint. * * @return MultiPoint */ public MultiPoint toMultiPoint() { return new MultiPoint(positions()); }
@Override public com.vividsolutions.jts.geom.MultiPoint fromGeometry(MultiPoint src) { return this.geometryFactory.createMultiPoint( src.points().stream() .map(p -> new Coordinate(p.lon(), p.lat(), p.alt())) .toArray(Coordinate[]::new) ); } }
@Override public com.vividsolutions.jts.geom.MultiPoint fromGeometry(MultiPoint src) { return this.geometryFactory.createMultiPoint( src.points().stream() .map(p -> new Coordinate(p.lon(), p.lat(), p.alt())) .toArray(Coordinate[]::new) ); } }
/** * Creates a MultiPoint from the given points. * * @param points The {@link Point} sequence. * @return MultiPoint */ public static MultiPoint of(Point... points) { return of(Arrays.asList(points)); }
/** * Converts to a MultiPoint. * * @return MultiPoint */ public MultiPoint toMultiPoint() { return new MultiPoint(positions()); }
/** * Creates a MultiPoint from the given points. * * @param points The {@link Point} Iterable. * @return MultiPoint */ public static MultiPoint of(Stream<Point> points) { return of(points.collect(Collectors.toList())); }
/** * Creates a MultiPoint from the given points. * * @param points The {@link Point} Iterable. * @return MultiPoint */ public static MultiPoint of(Iterable<Point> points) { LinearPositions.Builder positionsBuilder = LinearPositions.builder(); for(Point point : points) { positionsBuilder.addSinglePosition(point.positions()); } return new MultiPoint(positionsBuilder.build()); }
/** * Creates a MultiPoint from the given points. * * @param points The {@link Point} Iterable. * @return MultiPoint */ public static MultiPoint of(Stream<Point> points) { return of(points.collect(Collectors.toList())); }
/** * Creates a MultiPoint from the given points. * * @param points The {@link Point} Iterable. * @return MultiPoint */ public static MultiPoint of(Iterable<Point> points) { LinearPositions.Builder positionsBuilder = LinearPositions.builder(); for(Point point : points) { positionsBuilder.addSinglePosition(point.positions()); } return new MultiPoint(positionsBuilder.build()); }
@Override public MultiPoint toGeometry(com.vividsolutions.jts.geom.MultiPoint src) { return MultiPoint.of(StreamSupport.stream(JtsPointIterable.of(src).spliterator(), false) .map(AbstractJtsCodec::fromJtsPoint)); }
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); } }
@Override public MultiPoint toGeometry(com.vividsolutions.jts.geom.MultiPoint src) { return MultiPoint.of(StreamSupport.stream(JtsPointIterable.of(src).spliterator(), false) .map(AbstractJtsCodec::fromJtsPoint)); }
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); } }
@Test public void shouldHandleMultiPoint() { MultiPoint source = MultiPoint.of(Point.from(12.3, 45.3), Point.from(43.9, 5.8)); MultiPoint parsed = toTest.fromJson(toTest.toJson(source), MultiPoint.class); assertThat(parsed, equalTo(source)); }
geometries.add(MultiPoint.of(Point.from(12.3, 45.3), Point.from(43.9, 5.8))); geometries.add(LineString.of(Point.from(12.3, 45.3), Point.from(43.9, 5.8))); geometries.add(MultiLineString.of(