/** * Creates a Polygon from the given perimeter and holes. * * @param perimeter The perimeter {@link LinearRing}. * @param holes The holes {@link LinearRing} sequence. * * @return Polygon */ public static Polygon of(LinearRing perimeter, LinearRing... holes) { return Polygon.of(perimeter, Arrays.asList(holes)); }
/** * add the lines strings for the given polygon * * @param polygon */ public void addLineString(Polygon polygon) { for (LinearRing ring : polygon.linearRings()) { addLineString(ring); } for (LineString string : polygon.lineStrings()) { addLineString(string); } }
/** * Returns the perimeter {@link LinearRing}. * * @return LinearRing */ public LinearRing perimeter() { return linearRings().iterator().next(); }
/** * Returns the {@link LinearRing}s composing this Polygon. * * @return a Guava lazy Iterable of {@link LinearRing}. */ public List<LinearRing> linearRings() { return lineStrings().stream() .map(LineString::toLinearRing).collect(Collectors.toList()); }
/** * 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()); }
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); }
/** * Creates a MultiPolygon from the given {@link Polygon} sequence. * * @param polygons The {@link Polygon} Iterable. * @return MultiPolygon */ public static MultiPolygon of(Iterable<Polygon> polygons) { MultiDimensionalPositions.Builder positionsBuilder = MultiDimensionalPositions.builder(); for(Polygon polygon : polygons) { positionsBuilder.addAreaPosition(polygon.positions()); } return new MultiPolygon(positionsBuilder.build()); }
/** * Returns the perimeter {@link LinearRing}. * * @return LinearRing */ public LinearRing perimeter() { return linearRings().iterator().next(); }
/** * Returns the {@link LinearRing}s composing this Polygon. * * @return a Guava lazy Iterable of {@link LinearRing}. */ public List<LinearRing> linearRings() { return lineStrings().stream() .map(LineString::toLinearRing).collect(Collectors.toList()); }
/** * 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 MultiPolygon from the given {@link Polygon} sequence. * * @param polygons The {@link Polygon} Iterable. * @return MultiPolygon */ public static MultiPolygon of(Iterable<Polygon> polygons) { MultiDimensionalPositions.Builder positionsBuilder = MultiDimensionalPositions.builder(); for(Polygon polygon : polygons) { positionsBuilder.addAreaPosition(polygon.positions()); } return new MultiPolygon(positionsBuilder.build()); }
/** * Creates a Polygon from the given perimeter and holes. * * @param perimeter The perimeter {@link LinearRing}. * @param holes The holes {@link LinearRing} sequence. * * @return Polygon */ public static Polygon of(LinearRing perimeter, LinearRing... holes) { return Polygon.of(perimeter, Arrays.asList(holes)); }
/** * Returns the holes {@link LinearRing}s. * * @return a Guava lazy Iterable of {@link LinearRing}. */ public List<LinearRing> holes() { return linearRings().stream().skip(1).collect(Collectors.toList()); } }
/** * 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} Iterable. * * @return Polygon */ public static Polygon of(LinearRing perimeter, Iterable<LinearRing> holes) { return of(perimeter, StreamSupport.stream(holes.spliterator(), false)); }
/** * Returns the holes {@link LinearRing}s. * * @return a Guava lazy Iterable of {@link LinearRing}. */ public List<LinearRing> holes() { return linearRings().stream().skip(1).collect(Collectors.toList()); } }
/** * 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} Iterable. * * @return Polygon */ public static Polygon of(LinearRing perimeter, Iterable<LinearRing> holes) { return of(perimeter, StreamSupport.stream(holes.spliterator(), false)); }