public static Geometry getJts(final PolyLine polyLine) { if (polyLine instanceof Polygon) { return new JtsPolygonConverter().convert((Polygon) polyLine); } return new JtsPolyLineConverter().convert(polyLine); }
@Override public Polygon backwardConvert(final String wkt) { com.vividsolutions.jts.geom.Polygon geometry = null; final WKTReader myReader = new WKTReader(); try { geometry = (com.vividsolutions.jts.geom.Polygon) myReader.read(wkt); } catch (final ParseException | ClassCastException e) { throw new CoreException("Cannot parse wkt : {}", wkt); } return new JtsPolygonConverter().backwardConvert(geometry); }
/** * Tests that the {@link Polygon}'s geometry is valid * * @param polygon * the {@link Polygon} to test * @return {@code true} if the {@link Polygon} has valid geometry, otherwise {@code false} */ public static boolean isValidPolygon(final Polygon polygon) { final com.vividsolutions.jts.geom.Polygon jtsPolygon = POLYGON_CONVERTER.convert(polygon); return jtsPolygon.isSimple(); }
/** * Triangulate this {@link Polygon}, using the JTS library. * * @return All the triangles that form this {@link Polygon}. */ public List<Polygon> triangles() { final ConformingDelaunayTriangulationBuilder trianguler = new ConformingDelaunayTriangulationBuilder(); // Populate the delaunay triangulation builder trianguler.setSites(JTS_POLYGON_CONVERTER.convert(this)); final GeometryCollection triangleCollection = (GeometryCollection) trianguler .getTriangles(JtsPrecisionManager.getGeometryFactory()); // Get the output and convert back to Core Polygons, filter out the extraneous polygons from // the Delaunay triangulation. return Iterables.stream(GeometryStreamer.streamPolygons(triangleCollection)) .map(JTS_POLYGON_CONVERTER.revert()) .filter(polygon -> fullyGeometricallyEncloses(polygon.center())).collectToList(); }
@Override public MultiPolygon backwardConvert(final Set<com.vividsolutions.jts.geom.Polygon> object) { final MultiMap<Polygon, Polygon> result = new MultiMap<>(); for (final com.vividsolutions.jts.geom.Polygon polygon : object) { final Polygon outer = POLYGON_CONVERTER.backwardConvert(polygon); if (outer == null) { continue; } for (int n = 0; n < polygon.getNumInteriorRing(); n++) { final LinearRing ring = new LinearRing( polygon.getInteriorRingN(n).getCoordinateSequence(), FACTORY); final Polygon inner = LINEAR_RING_CONVERTER.backwardConvert(ring); result.add(outer, inner); } if (polygon.getNumInteriorRing() == 0) { // Make sure the outer still exists if the inners are not there. result.put(outer, new ArrayList<>()); } } return new MultiPolygon(result); }
/** * This will return the centroid of a given polygon. It can handle complex polygons including * multiple polygons. This will not necessarily return a location that is contained within the * original polygon. For example if you have two concentric circles forming a donut shape, one * smaller one contained within the bigger one. The centroid of that polygon will be at the * center technically outside of the polygon. This is a very different concept to a * representative point. * * @return a Location object that is the centroid of the polygon */ public Location center() { final Point point = JTS_POLYGON_CONVERTER.convert(this).getCentroid(); return new JtsLocationConverter().backwardConvert(point.getCoordinate()); }
@Override public byte[] convert(final Polygon polygon) { final Geometry geometry = new JtsPolygonConverter().convert(polygon); final byte[] wkb = new WKBWriter().write(geometry); return wkb; } }
/** * Returns a location that is the closest point within the polygon to the centroid. The function * delegates to the Geometry class which delegates to the InteriorPointPoint class. You can see * the javadocs in the link below. <a href= * "http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/algorithm/InteriorPointPoint"> * http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/algorithm/InteriorPointPoint * </a> .html * * @return location that is the closest point within the polygon to the centroid */ public Location interiorCenter() { final Point point = JTS_POLYGON_CONVERTER.convert(this).getInteriorPoint(); return new JtsLocationConverter().backwardConvert(point.getCoordinate()); }
@Override public Polygon backwardConvert(final byte[] wkb) { com.vividsolutions.jts.geom.Polygon geometry = null; final WKBReader myReader = new WKBReader(); try { geometry = (com.vividsolutions.jts.geom.Polygon) myReader.read(wkb); } catch (final ParseException | ClassCastException e) { throw new CoreException("Cannot parse wkb : {}", WKBWriter.toHex(wkb)); } return new JtsPolygonConverter().backwardConvert(geometry); }
@Override public String convert(final Polygon polygon) { final Geometry geometry = new JtsPolygonConverter().convert(polygon); return new WKTWriter().write(geometry); } }
private List<? extends PolyLine> processResult(final Geometry intersections) { final List<PolyLine> result = new ArrayList<>(); if (intersections instanceof GeometryCollection) { final GeometryCollection collection = (GeometryCollection) intersections; final int numGeometries = collection.getNumGeometries(); for (int n = 0; n < numGeometries; n++) { final Geometry geometry = collection.getGeometryN(n); result.addAll(processResult(geometry)); } } else if (intersections instanceof com.vividsolutions.jts.geom.Polygon) { result.add(new JtsPolygonConverter() .backwardConvert((com.vividsolutions.jts.geom.Polygon) intersections)); } else if (intersections instanceof LineString) { result.add(new JtsPolyLineConverter().backwardConvert((LineString) intersections)); } return result; } }
geometry = JTS_POLYGON_CONVERTER.convert(new Polygon(line));
final org.openstreetmap.atlas.geography.Polygon polygon = new JtsPolygonConverter() .backwardConvert((Polygon) geometry); return atlas.subAtlas(polygon, cutType);
final com.vividsolutions.jts.geom.Polygon polygon = JTS_POLYGON_CONVERTER.convert(this); final Point point = new JtsPointConverter().convert(location); return polygon.covers(point);
final org.openstreetmap.atlas.geography.Polygon polygon = new JtsPolygonConverter() .backwardConvert((Polygon) geometry); final Iterable<? extends Shard> shards = sharding.shards(polygon); for (final Shard shard : shards)