/** * Reproject the specified bbox string From the sourceCRS to the targetCRS. * * @param targetCRSName The coordinate reference system in which we have to reproject the geometry. * @param sourceCRSName The current coordinate reference system of the geometry. * @param boundingBox the bbox object to reproject as a string. * * @return The geometric object reprojected in the target coordinate reference system. * * @throws org.opengis.referencing.NoSuchAuthorityCodeException * @throws org.opengis.util.FactoryException * @throws org.opengis.referencing.operation.TransformException */ public static Object reprojectBbox2DString(final String sourceCRSName, final String targetCRSName, final String boundingBox) throws NoSuchAuthorityCodeException, FactoryException, TransformException { final String[] bbox = boundingBox.split(","); double[] lowerCorner ={Double.parseDouble(bbox[1]),Double.parseDouble(bbox[0])}; double[] upperCorner ={Double.parseDouble(bbox[3]),Double.parseDouble(bbox[2])}; GeneralEnvelope env = new GeneralEnvelope(lowerCorner,upperCorner); env.setCoordinateReferenceSystem(AbstractCRS.castOrCopy(CRS.forCode(sourceCRSName)).forConvention(AxesConvention.RIGHT_HANDED)); env = (GeneralEnvelope) reprojectGeometry(targetCRSName, sourceCRSName, env); lowerCorner = env.getLowerCorner().getCoordinate(); upperCorner = env.getUpperCorner().getCoordinate(); return lowerCorner[0]+","+lowerCorner[1]+","+upperCorner[0]+","+upperCorner[1]; }
/** * Transforms an envelope using the given math transform. * This transformation can not handle poles. * * <p>This method wraps the math transform into an opaque object for hiding the fact that the given * transform implement the {@link MathTransform2D} interface. The intent is to disable optimization * paths (if any), in order to test the generic path.</p> */ @Override GeneralEnvelope transform(CoordinateReferenceSystem targetCRS, MathTransform2D transform, GeneralEnvelope envelope) throws TransformException { final GeneralEnvelope env = Envelopes.transform(new MathTransformWrapper(transform), envelope); env.setCoordinateReferenceSystem(targetCRS); return env; }
/** * Computes the envelope with the given coordinate reference system. This method is invoked from constructors. * The {@link #extent}, {@link #gridToCRS} and {@link #cornerToCRS} fields must be set before this method is invoked. * * @param specified the transform specified by the user. This is not necessarily {@link #gridToCRS}. * @param crs the coordinate reference system to declare in the envelope. * @param limits if non-null, intersect with that envelope. The CRS must be the same than {@code crs}. */ private ImmutableEnvelope computeEnvelope(final MathTransform specified, final CoordinateReferenceSystem crs, final Envelope limits) throws TransformException { final GeneralEnvelope env; if (extent != null && cornerToCRS != null) { env = extent.toCRS(cornerToCRS, specified); env.setCoordinateReferenceSystem(crs); if (limits != null) { env.intersect(limits); } } else if (crs != null) { env = new GeneralEnvelope(crs); env.setToNaN(); } else { return null; } return new ImmutableEnvelope(env); }
/** * Creates a new geographic envelope for the given ordinate values. * This method is overridden by {@link SubEnvelopeTest}. */ GeneralEnvelope create(final double xmin, final double ymin, final double xmax, final double ymax) { final GeneralEnvelope envelope = new GeneralEnvelope(2); envelope.setCoordinateReferenceSystem(WGS84); envelope.setEnvelope(xmin, ymin, xmax, ymax); if (!skipValidation) { validate(envelope); } return envelope; }
/** * Parses a geometry together with its coordinate reference system, all in Well Known Text (WKT). * * @param geometry the geometry to parse, or {@code null} if none. * @param crs the horizontal part of the WKT (2D or 3D), or {@code null} if none. * @param additionalCRS the vertical or temporal part of the WKT, or {@code null} if none. * @return the geometry, or {@code null} if none or unparseable. */ public Geometry parseGeometry(final String geometry, final String crs, final String additionalCRS) { if (geometry != null) try { final Object obj = Geometries.implementation(library).parseWKT(geometry); final GeneralEnvelope envelope = Geometries.getEnvelope(geometry); if (envelope != null) { envelope.setCoordinateReferenceSystem(parseCRS(crs, additionalCRS)); return new GeometryWrapper(obj, envelope); } } catch (IllegalArgumentException | UnsupportedOperationException e) { log(e); } return null; }
/** * Parses a geometry together with its coordinate reference system, all in Well Known Text (WKT). * * @param geometry the geometry to parse, or {@code null} if none. * @param crs the horizontal part of the WKT (2D or 3D), or {@code null} if none. * @param additionalCRS the vertical or temporal part of the WKT, or {@code null} if none. * @return the geometry, or {@code null} if none or unparseable. */ public Geometry parseGeometry(final String geometry, final String crs, final String additionalCRS) { if (geometry != null) try { final Object obj = Geometries.implementation(library).parseWKT(geometry); final GeneralEnvelope envelope = Geometries.getEnvelope(geometry); if (envelope != null) { envelope.setCoordinateReferenceSystem(parseCRS(crs, additionalCRS)); return new GeometryWrapper(obj, envelope); } } catch (Exception e) { // Implementation-specific exception (e.g. JTS has its own exception class). log(e); } return null; }
transformed.setCoordinateReferenceSystem(targetCRS);
envelope = merged = new GeneralEnvelope(bounds); merged.translate(-getGreenwichLongitude(sourceCRS), 0); merged.setCoordinateReferenceSystem(sourceCRS); try { envelope = Envelopes.transform(envelope, targetCRS);
envelope = merged = new GeneralEnvelope(bounds); merged.translate(-getGreenwichLongitude(sourceCRS), 0); merged.setCoordinateReferenceSystem(sourceCRS); try { envelope = Envelopes.transform(envelope, targetCRS);
throw new IllegalStateException(Errors.format(Errors.Keys.UnspecifiedCRS)); ((GeneralEnvelope) genv).setCoordinateReferenceSystem((CoordinateReferenceSystem) geomCRS); genv = Envelopes.transform(genv, crs);
compound.setCoordinateReferenceSystem(CRS.compound(crsComponents));
/** * Creates a new sub-envelope envelope for the given ordinate values. */ @Override GeneralEnvelope create(final double xmin, final double ymin, final double xmax, final double ymax) { final GeneralEnvelope envelope = new GeneralEnvelope(5); envelope.setEnvelope(1, 4, xmin, ymin, 5, 2, 7, xmax, ymax, 9); if (!skipValidation) { validate(envelope); } final GeneralEnvelope sub = envelope.subEnvelope(2, 4); sub.setCoordinateReferenceSystem(WGS84); if (!skipValidation) { validate(sub); } return sub; }
((GeneralEnvelope) envelope).setCoordinateReferenceSystem(targetCRS); } else { final CoordinateOperation operation;
((GeneralEnvelope) envelope).setCoordinateReferenceSystem(targetCRS); } else {
public void testSetCoordinateReferenceSystem() { final GeneralEnvelope e = create(2, -4, 3, -3); e.setCoordinateReferenceSystem(null); e.setCoordinateReferenceSystem(WGS84); fail("Invalid range shall not be allowed."); } catch (IllegalStateException ex) { assertEquals(-20, e.getUpper(1), STRICT); e.setRange(1, -20, -10); e.setCoordinateReferenceSystem(WGS84); assertEnvelopeEquals(e, 2, -20, 3, -10); verifyInvariants(e);
case GENERAL: { final GeneralEnvelope ge = new GeneralEnvelope(2); ge.setCoordinateReferenceSystem(WGS84); ge.setRange(0, xmin, xmax); ge.setRange(1, ymin, ymax); ge.setRange(4, 8, 9); ge = ge.subEnvelope(1, 3); ge.setCoordinateReferenceSystem(WGS84); envelope = ge; break;
/** * Implementation of {@link #testAxisRangeChange3D()} and {@link #testAxisRangeChangeWithDatumShift()}. */ private void testAxisRangeChange3D(final GeographicCRS targetCRS) throws FactoryException, TransformException { final GeneralEnvelope envelope = new GeneralEnvelope(new double[] { -0.5, -90, 1000}, new double[] {354.5, +90, 1002}); envelope.setCoordinateReferenceSystem(CRS.compound( HardCodedCRS.WGS84.forConvention(AxesConvention.POSITIVE_RANGE), HardCodedCRS.TIME)); final GeneralEnvelope expected = createFromExtremums(targetCRS, -0.5, -90, -5.5, 90); assertEnvelopeEquals(expected, Envelopes.transform(envelope, targetCRS), STRICT, STRICT); /* * When the envelope to transform span the full longitude range, * target envelope should unconditionally be [-180 … +180]°. */ envelope.setRange(0, -0.5, 359.5); expected.setRange(0, -180, 180); assertEnvelopeEquals(expected, Envelopes.transform(envelope, targetCRS), STRICT, STRICT); }
final GeneralEnvelope env = (GeneralEnvelope) geometry; if (env.getCoordinateReferenceSystem() == null) { env.setCoordinateReferenceSystem(sourceCRS);
element1.setCoordinateReferenceSystem(null); env = Envelopes.compound(element0, element1); assertEnvelopeEquals(expected, env);
/** * Tests a transform from "<cite>Réseau Géodésique Français 1993</cite>" to * "<cite>Nouvelle Triangulation Française (Paris)</cite>". This transform uses * the inverse of a datum shift grid. * * @throws Exception Should not happen. * * @since 3.20 */ @Test @Ignore public void testNTF() throws Exception { assumeTrue(false /*Files.isDirectory(Installation.NADCON.directory(true))*/); assumeTrue(false /*isEpsgFactoryAvailable()*/); final CoordinateReferenceSystem sourceCRS = CRS.forCode("EPSG:2154"); // Réseau Géodésique Français 1993 final CoordinateReferenceSystem targetCRS = CRS.forCode("EPSG:27582"); // Nouvelle Triangulation Française (Paris) final GeneralEnvelope source = new GeneralEnvelope("BOX(-2000000 4000000, 2000000 4000000)"); source.setCoordinateReferenceSystem(sourceCRS); final Envelope target = Envelopes.transform(source, targetCRS); assertEquals(-2033792.23, target.getMinimum(0), 1E-2); assertEquals( 1976167.67, target.getMaximum(0), 1E-2); assertEquals( -458155.31, target.getMinimum(1), 1E-2); assertEquals( -426020.22, target.getMaximum(1), 1E-2); } }