/** * 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(); }
@Override public byte[] convert(final Polygon polygon) { final Geometry geometry = new JtsPolygonConverter().convert(polygon); final byte[] wkb = new WKBWriter().write(geometry); return wkb; } }
public static Geometry getJts(final PolyLine polyLine) { if (polyLine instanceof Polygon) { return new JtsPolygonConverter().convert((Polygon) polyLine); } return new JtsPolyLineConverter().convert(polyLine); }
@Override public String convert(final Polygon polygon) { final Geometry geometry = new JtsPolygonConverter().convert(polygon); return new WKTWriter().write(geometry); } }
/** * 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()); }
/** * 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()); }
geometry = JTS_POLYGON_CONVERTER.convert(new Polygon(line));
final com.vividsolutions.jts.geom.Polygon polygon = JTS_POLYGON_CONVERTER.convert(this); final Point point = new JtsPointConverter().convert(location); return polygon.covers(point);
/** * 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(); }