/** * Create a LinearRing from the given points. * * @param points Point Iterable composed at least by 4 points, with the first and the last that are the same. * @return a LinearRing */ public static LinearRing of(Stream<Point> points) { return of(points::iterator); }
/** * Convert to a LinearRing. * * @return LinearRing */ public LinearRing toLinearRing() { return new LinearRing(positions()); }
protected com.vividsolutions.jts.geom.LinearRing toJtsLinearRing(LinearRing src) { return this.geometryFactory.createLinearRing( StreamSupport.stream(src.positions().children().spliterator(), false) .map(sp -> new Coordinate(sp.lon(), sp.lat(), sp.alt())) .toArray(Coordinate[]::new) ); }
protected com.vividsolutions.jts.geom.LinearRing toJtsLinearRing(LinearRing src) { return this.geometryFactory.createLinearRing( StreamSupport.stream(src.positions().children().spliterator(), false) .map(sp -> new Coordinate(sp.lon(), sp.lat(), sp.alt())) .toArray(Coordinate[]::new) ); }
/** * Create a LinearRing from the given points. * * @param points Point Iterable composed at least by 4 points, with the first and the last that are the same. * @return a LinearRing */ public static LinearRing of(Stream<Point> points) { return of(points::iterator); }
/** * 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()); }
/** * Convert to a LinearRing. * * @return LinearRing */ public LinearRing toLinearRing() { return new LinearRing(positions()); }
/** * Create a LinearRing from the given points. * * @param points Point sequence composed at least by 4 points, with the first and the last that are the same. * @return a LinearRing */ public static LinearRing of(Point... points) { return of(Arrays.asList(points)); }
/** * 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()); }
/** * Create a LinearRing from the given points. * * @param points Point Iterable composed at least by 4 points, with the first and the last that are the same. * @return a LinearRing */ public static LinearRing of(Iterable<Point> points) { LinearPositions.Builder builder = LinearPositions.builder(); for(Point point : points) { builder.addSinglePosition(point.positions()); } return new LinearRing(builder.build()); }
/** * Create a LinearRing from the given points. * * @param points Point sequence composed at least by 4 points, with the first and the last that are the same. * @return a LinearRing */ public static LinearRing of(Point... points) { return of(Arrays.asList(points)); }
private static Boolean isPointInside(Feature feature, Coordinates location) { Polygon polygon = (Polygon) feature.geometry(); List<SinglePosition> positions = Lists.newArrayList(polygon.perimeter().positions().children()); if ((positions == null) || (location == null)) { return false; } int wn = 0; for (int i = 0; i < positions.size() - 1; i++) { if (positions.get(i).coordinates().getLat() <= location.getLat()) { if (positions.get(i + 1).coordinates().getLat() > location.getLat()) { if (isLeft(positions.get(i).coordinates(), positions.get(i + 1).coordinates(), location) > 0.0) { ++wn; } } } else { if (positions.get(i + 1).coordinates().getLat() <= location.getLat()) { if (isLeft(positions.get(i).coordinates(), positions.get(i + 1).coordinates(), location) < 0.0) { --wn; } } } } return (wn != 0); }
/** * Create a LinearRing from the given points. * * @param points Point Iterable composed at least by 4 points, with the first and the last that are the same. * @return a LinearRing */ public static LinearRing of(Iterable<Point> points) { LinearPositions.Builder builder = LinearPositions.builder(); for(Point point : points) { builder.addSinglePosition(point.positions()); } return new LinearRing(builder.build()); }
protected static LinearRing fromJtsLinearRing(com.vividsolutions.jts.geom.LinearRing src) { return LinearRing.of(StreamSupport .stream(JtsPointIterable.of(src).spliterator(), false) .map(AbstractJtsCodec::fromJtsPoint)::iterator ); }
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); } }
protected static LinearRing fromJtsLinearRing(com.vividsolutions.jts.geom.LinearRing src) { return LinearRing.of(StreamSupport .stream(JtsPointIterable.of(src).spliterator(), false) .map(AbstractJtsCodec::fromJtsPoint)::iterator ); }
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 shouldHandleLinearRing() { LinearRing source = LinearRing.of(Point.from(12.3, 45.3), Point.from(43.9, 5.8), Point.from(43.9, 5.8), Point.from(12.3, 45.3)); LinearRing parsed = toTest.fromJson(toTest.toJson(source), LinearRing.class); assertThat(parsed, equalTo(source)); }
@Test public void shouldHandlePolygonWithoutHoles() { Polygon source = Polygon.of( LinearRing.of(Point.from(120.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(120.3, 45.3)) ); Polygon parsed = this.toTest.fromJson(this.toTest.toJson(source), Polygon.class); assertThat(parsed, equalTo(source)); }
@Test public void shouldHandleMultiPolygonWithSinglePolygonWithoutHoles() { MultiPolygon source = MultiPolygon.of( Polygon.of(LinearRing.of(Point.from(120.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(120.3, 45.3))) ); MultiPolygon parsed = this.toTest.fromJson(this.toTest.toJson(source), MultiPolygon.class); assertThat(parsed, equalTo(source)); }