JTS { public static Envelope toGeographic(final Envelope envelope, final CoordinateReferenceSystem crs) throws TransformException { if (CRS.equalsIgnoreMetadata(crs, DefaultGeographicCRS.WGS84)) { if( envelope instanceof ReferencedEnvelope){ return envelope; } return ReferencedEnvelope.create( envelope, DefaultGeographicCRS.WGS84 ); } ReferencedEnvelope initial = ReferencedEnvelope.create( envelope, crs ); return toGeographic( initial ); } 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 testTransformToWGS84() throws Exception { String wkt = "GEOGCS[\"GDA94\"," + " DATUM[\"Geocentric Datum of Australia 1994\"," + " SPHEROID[\"GRS 1980\", 6378137.0, 298.257222101, AUTHORITY[\"EPSG\",\"7019\"]]," + " TOWGS84[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], " + " AUTHORITY[\"EPSG\",\"6283\"]], " + " PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]]," + " UNIT[\"degree\", 0.017453292519943295], " + " AXIS[\"Geodetic longitude\", EAST], " + " AXIS[\"Geodetic latitude\", NORTH], " + " AXIS[\"Ellipsoidal height\", UP], " + " AUTHORITY[\"EPSG\",\"4939\"]]"; CoordinateReferenceSystem gda94 = CRS.parseWKT(wkt); ReferencedEnvelope bounds = new ReferencedEnvelope3D(130.875825803896, 130.898939990319, -16.4491956225999, -16.4338185791628, 0.0, 0.0, gda94 ); ReferencedEnvelope worldBounds = JTS.toGeographic( bounds ); assertEquals( DefaultGeographicCRS.WGS84, worldBounds.getCoordinateReferenceSystem() ); Envelope envelope = new Envelope(130.875825803896, 130.898939990319, -16.4491956225999, -16.4338185791628); Envelope worldBounds2 = JTS.toGeographic( envelope, gda94 ); if( worldBounds2 instanceof BoundingBox){ assertEquals( DefaultGeographicCRS.WGS84, ((BoundingBox)worldBounds2).getCoordinateReferenceSystem() ); } }
@Test public void testToGeographic() throws Exception { String wkt = "GEOGCS[\"GDA94\"," + " DATUM[\"Geocentric Datum of Australia 1994\"," + " SPHEROID[\"GRS 1980\", 6378137.0, 298.257222101, AUTHORITY[\"EPSG\",\"7019\"]]," + " TOWGS84[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], " + " AUTHORITY[\"EPSG\",\"6283\"]], " + " PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]]," + " UNIT[\"degree\", 0.017453292519943295], " + " AXIS[\"Geodetic longitude\", EAST], " + " AXIS[\"Geodetic latitude\", NORTH], " + " AXIS[\"Ellipsoidal height\", UP], " + " AUTHORITY[\"EPSG\",\"4939\"]]"; CoordinateReferenceSystem gda94 = CRS.parseWKT(wkt); GeometryFactory gf = new GeometryFactory(); Point point = gf.createPoint( new Coordinate( 130.875825803896, -16.4491956225999, 0.0 ) ); Geometry worldPoint = JTS.toGeographic( point, gda94 ); assertTrue( worldPoint instanceof Point ); assertEquals( point.getX(), worldPoint.getCoordinate().x,0.00000001); }
@Test public void testToGeographicGeometry() throws Exception { String wkt = "GEOGCS[\"GDA94\"," + " DATUM[\"Geocentric Datum of Australia 1994\"," + " SPHEROID[\"GRS 1980\", 6378137.0, 298.257222101, AUTHORITY[\"EPSG\",\"7019\"]]," + " TOWGS84[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], " + " AUTHORITY[\"EPSG\",\"6283\"]], " + " PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]]," + " UNIT[\"degree\", 0.017453292519943295], " + " AXIS[\"Geodetic latitude\", NORTH], " + " AXIS[\"Geodetic longitude\", EAST], " + " AXIS[\"Ellipsoidal height\", UP], " + " AUTHORITY[\"EPSG\",\"4939\"]]"; CoordinateReferenceSystem gda94 = CRS.parseWKT(wkt); GeometryFactory gf = new GeometryFactory(); Point point = gf.createPoint( new Coordinate( -16.4463909341494,130.882672103999, 97.009018073082)); Point world = (Point) JTS.toGeographic( point, gda94 ); assertEquals( point.getX(), world.getY(), 0.00000005 ); assertEquals( point.getY(), world.getX(), 0.00000005 ); }