/** * Transforms the envelope from its current crs to {@link DefaultGeographicCRS#WGS84}. If the * specified envelope is already in WGS84, then it is returned unchanged. * * <p>The method {@link CRS#equalsIgnoreMetadata(Object, Object)} is used to compare the numeric * values and axis order (so {@code CRS.decode("CRS.84")} or {@code CRS.decode("4326",true)} * provide an appropriate match). * * @param envelope The envelope to transform. * @param crs The CRS the envelope is currently in. * @return The envelope transformed to be in {@link DefaultGeographicCRS#WGS84}. * @throws TransformException If at least one coordinate can't be transformed. */ 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); } /**
@Test public void testToGeographicGeometry() throws Exception { // This time we are in north / east order CoordinateReferenceSystem gda94 = CRS.decode("EPSG:4939", true); GeometryFactory gf = new GeometryFactory(); Point point = gf.createPoint( new Coordinate(130.882672103999, -16.4463909341494, 97.009018073082)); Point world = (Point) JTS.toGeographic(point, gda94); assertEquals(point.getX(), world.getX(), 0.00000005); assertEquals(point.getY(), world.getY(), 0.00000005); }
gda94); ReferencedEnvelope worldBounds = JTS.toGeographic(bounds); assertEquals(DefaultGeographicCRS.WGS84, worldBounds.getCoordinateReferenceSystem()); 130.875825803896, 130.898939990319, -16.4491956225999, -16.4338185791628); Envelope worldBounds2 = JTS.toGeographic(envelope, gda94); if (worldBounds2 instanceof BoundingBox) { assertEquals(
@Test public void testBounds() throws Exception { ReferencedEnvelope bounds2d = point_test_2d.getBounds(); ReferencedEnvelope bounds3d = point_test.getBounds(); double aspect2d = bounds2d.getWidth() / bounds2d.getHeight(); double aspect3d = bounds3d.getWidth() / bounds3d.getHeight(); assertEquals(aspect2d, aspect3d, 0.0005); ReferencedEnvelope bbox2d = JTS.toGeographic(bounds2d); ReferencedEnvelope bbox3d = JTS.toGeographic(bounds3d); aspect2d = bbox2d.getWidth() / bbox2d.getHeight(); aspect3d = bbox3d.getWidth() / bbox3d.getHeight(); assertEquals(aspect2d, aspect3d, 0.000005); }
@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 { // This time we are in north / east order 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); }
assertFalse(typeName + " bounds null", dataBounds.isNull()); ReferencedEnvelope bounds = JTS.toGeographic(dataBounds); assertNotNull(typeName + " world", bounds); assertTrue( assertFalse(typeName + " world null", bounds.isNull()); ReferencedEnvelope reference = JTS.toGeographic(point_test_2d.getBounds()); assertNotNull("reference point_test_2d bounds", reference); assertTrue(
Envelope env = geom.getEnvelopeInternal(); if (crs != null) env = JTS.toGeographic(env, crs); result.expandToInclude(env);
.getCoordinateSystem(); if (crs != null) envelope = JTS.toGeographic(envelope, crs); state.expandDirtyBounds(envelope);
.getCoordinateSystem(); if (crs != null) envelope = JTS.toGeographic(envelope, crs); state.expandDirtyBounds(envelope);