JTS { public static Geometry toGeometry(final Shape shape) { return toGeometry(shape, new GeometryFactory()); } private  JTS(); static Envelope transform(final Envelope envelope, final MathTransform transform); static Envelope transform(final Envelope sourceEnvelope, Envelope targetEnvelope,
            final MathTransform transform, int npoints); static ReferencedEnvelope3D transformTo3D(final ReferencedEnvelope sourceEnvelope,
            CoordinateReferenceSystem targetCRS, boolean lenient, int npoints); static ReferencedEnvelope transformTo2D(final ReferencedEnvelope sourceEnvelope,
            CoordinateReferenceSystem targetCRS, boolean lenient, int npoints); static Geometry transform(final Geometry geom, final MathTransform transform); static Coordinate transform(final Coordinate source, Coordinate dest,
            final MathTransform transform); static Envelope toGeographic(final Envelope envelope, final CoordinateReferenceSystem crs); static ReferencedEnvelope toGeographic(final ReferencedEnvelope envelope); static void xform(final MathTransform transform, final double[] src, final double[] dest); static synchronized double orthodromicDistance(final Coordinate p1, final Coordinate p2,
            final CoordinateReferenceSystem crs); static DirectPosition toDirectPosition(final Coordinate point,
            final CoordinateReferenceSystem crs); static void copy(final Coordinate point, final double[] ordinates); static Geometry shapeToGeometry(final Shape shape, final GeometryFactory factory); static Geometry toGeometry(final Shape shape); static Geometry toGeometry(final Shape shape, final GeometryFactory factory); static Envelope2D getEnvelope2D(final Envelope envelope,
            final CoordinateReferenceSystem crs); static Point toGeometry(DirectPosition position); static Point toGeometry(DirectPosition position, GeometryFactory factory); static Polygon toGeometry(Envelope env); static Polygon toGeometry(final Envelope env, GeometryFactory factory); static ReferencedEnvelope toEnvelope(Geometry geom); static Polygon toGeometry(ReferencedEnvelope bbox); static Polygon toGeometry(BoundingBox bbox, GeometryFactory factory, int npoints); static Geometry toGeographic( Geometry geom, final CoordinateReferenceSystem crs ); static Polygon toGeometry(BoundingBox bbox); static Polygon toGeometry(BoundingBox bbox, final GeometryFactory factory); static void checkCoordinatesRange(Geometry geom, CoordinateReferenceSystem crs); static Geometry smooth(final Geometry geom, double fit); static Geometry smooth(final Geometry geom, double fit, final GeometryFactory factory); static ReferencedEnvelope bounds( Geometry geometry, CoordinateReferenceSystem crs ); static Geometry removeCollinearVertices(final Geometry g); static Geometry removeCollinearVertices(final Geometry geometry, int minPoints); static List<Polygon> makeValid(Polygon polygon, boolean removeHoles);  }
@Test public void toGeometry_Shape_Poly() { Shape shape = new Polygon(XPOINTS, YPOINTS, NPOINTS); Geometry geom = JTS.toGeometry(shape); assertTrue(geom instanceof LinearRing); Coordinate[] coords = geom.getCoordinates(); assertEquals(NPOINTS + 1, coords.length); CoordList list = new CoordList(coords); Coordinate c = new Coordinate(); for (int i = 0; i < NPOINTS; i++) { c.x = XPOINTS[i]; c.y = YPOINTS[i]; assertTrue(list.contains(c)); } }
@Test public void toGeometry_Shape_Line() { GeneralPath path = new GeneralPath(); path.moveTo(XPOINTS[0], YPOINTS[0]); for (int i = 1; i < NPOINTS; i++) { path.lineTo(XPOINTS[i], YPOINTS[i]); } Geometry geom = JTS.toGeometry(path); assertTrue(geom instanceof LineString); Coordinate[] coords = geom.getCoordinates(); assertEquals(NPOINTS, coords.length); CoordList list = new CoordList(coords); Coordinate c = new Coordinate(); for (int i = 0; i < NPOINTS; i++) { c.x = XPOINTS[i]; c.y = YPOINTS[i]; assertTrue(list.contains(c)); } }
@Test public void toGeometry_Envelope() { Envelope refEnv = new Envelope(-10, 10, -5, 5); Geometry geom = JTS.toGeometry(refEnv); assertTrue(geom instanceof com.vividsolutions.jts.geom.Polygon); Envelope geomEnv = geom.getEnvelopeInternal(); assertEquals(-10.0, geomEnv.getMinX(), TOL); assertEquals(10.0, geomEnv.getMaxX(), TOL); assertEquals(-5.0, geomEnv.getMinY(), TOL); assertEquals(5.0, geomEnv.getMaxY(), TOL); }
@Test public void toGeometry_ReferencedEnvelope() { ReferencedEnvelope refEnv = new ReferencedEnvelope(-10, 10, -5, 5, DefaultGeographicCRS.WGS84); Geometry geom = JTS.toGeometry(refEnv); assertTrue(geom instanceof com.vividsolutions.jts.geom.Polygon); Envelope geomEnv = geom.getEnvelopeInternal(); assertEquals(-10.0, geomEnv.getMinX(), TOL); assertEquals(10.0, geomEnv.getMaxX(), TOL); assertEquals(-5.0, geomEnv.getMinY(), TOL); assertEquals(5.0, geomEnv.getMaxY(), TOL); }
@Test public void toGeometry_BoundingBox() { BoundingBox bbox = new ReferencedEnvelope(-10, 10, -5, 5, null); Geometry geom = JTS.toGeometry(bbox); assertTrue(geom instanceof com.vividsolutions.jts.geom.Polygon); Envelope geomEnv = geom.getEnvelopeInternal(); assertEquals(-10.0, geomEnv.getMinX(), TOL); assertEquals(10.0, geomEnv.getMaxX(), TOL); assertEquals(-5.0, geomEnv.getMinY(), TOL); assertEquals(5.0, geomEnv.getMaxY(), TOL); }