/** Helper method for transforming an envelope. */ private static ReferencedEnvelope transform(ReferencedEnvelope e, CoordinateReferenceSystem crs) throws TransformException, FactoryException { if (!CRS.equalsIgnoreMetadata(crs, e.getCoordinateReferenceSystem())) { return e.transform(crs, true); } return e; }
/** * Computes the geographic bounds of a {@link ResourceInfo} by reprojecting the available native * bounds * * @param rinfo * @return the geographic bounds, or null if the native bounds are not available * @throws IOException */ public ReferencedEnvelope getLatLonBounds( ReferencedEnvelope nativeBounds, CoordinateReferenceSystem declaredCRS) throws IOException { if (nativeBounds != null && declaredCRS != null) { // make sure we use the declared CRS, not the native one, the may differ if (!CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, declaredCRS)) { // transform try { ReferencedEnvelope bounds = new ReferencedEnvelope(nativeBounds, CRS.getHorizontalCRS(declaredCRS)); return bounds.transform(DefaultGeographicCRS.WGS84, true); } catch (Exception e) { throw (IOException) new IOException("transform error").initCause(e); } } else { return new ReferencedEnvelope(nativeBounds, DefaultGeographicCRS.WGS84); } } return null; }
CoordinateReferenceSystem crs1 = e1.getCoordinateReferenceSystem(); CoordinateReferenceSystem crs2 = e2.getCoordinateReferenceSystem(); if (crs1 != crs2 && !CRS.equalsIgnoreMetadata(crs1, crs2)) { throw new RuntimeException( "Two collections are returning different CRSs, cannot perform this "
if (CRS.equalsIgnoreMetadata(sourceCRS, DefaultGeographicCRS.WGS84)) { return new GeneralEnvelope(envelope); if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { targetEnvelope = CRS.transform(envelope, targetCRS); } else {
if (!CRS.equalsIgnoreMetadata(sourceCRS, destCRS)) { try { envelope = CRS.transform(envelope, destCRS);
if (!CRS.equalsIgnoreMetadata(crs, this.crs)) { try { destinationToSourceTransform = CRS.findMathTransform(crs, this.crs, true);
public ReferencedEnvelope boundingBox() throws Exception { CoordinateReferenceSystem declaredCRS = getCRS(); CoordinateReferenceSystem nativeCRS = getNativeCRS(); ProjectionPolicy php = getProjectionPolicy(); ReferencedEnvelope nativeBox = this.nativeBoundingBox; if (nativeBox == null) { // back project from lat lon try { nativeBox = getLatLonBoundingBox().transform(declaredCRS, true); } catch (Exception e) { LOGGER.log(Level.WARNING, "Failed to derive native bbox from declared one", e); return null; } } ReferencedEnvelope result; if (!CRS.equalsIgnoreMetadata(declaredCRS, nativeCRS) && php == ProjectionPolicy.REPROJECT_TO_DECLARED) { result = nativeBox.transform(declaredCRS, true); } else if (php == ProjectionPolicy.FORCE_DECLARED) { result = ReferencedEnvelope.create((Envelope) nativeBox, declaredCRS); } else { result = nativeBox; } // make sure that in no case the actual field value is returned to the client, this // is not a getter, it's a derivative, thus ModificationProxy won't do a copy on its own return ReferencedEnvelope.create(result); }
} else { if (!CRS.equalsIgnoreMetadata(nativeCRS, targetCRS)) { fc = new ReprojectFeatureResults(fc, targetCRS);
@Test public void testCRSConverter() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); CRSConverter c = new CRSConverter(); assertEquals(crs.toWKT(), c.toString(crs)); assertEquals(DefaultGeographicCRS.WGS84.toWKT(), c.toString(DefaultGeographicCRS.WGS84)); CoordinateReferenceSystem crs2 = (CoordinateReferenceSystem) c.fromString(crs.toWKT()); assertTrue(CRS.equalsIgnoreMetadata(crs, crs2)); crs2 = (CoordinateReferenceSystem) c.fromString("EPSG:4326"); assertTrue(CRS.equalsIgnoreMetadata(crs, crs2)); }
public SimpleFeatureCollection subCollection(Filter filter) { // reproject the filter to the delegate native crs CoordinateReferenceSystem crs = getSchema().getCoordinateReferenceSystem(); CoordinateReferenceSystem crsDelegate = delegate.getSchema().getCoordinateReferenceSystem(); if (crs != null) { DefaultCRSFilterVisitor defaulter = new DefaultCRSFilterVisitor(FF, crs); filter = (Filter) filter.accept(defaulter, null); if (crsDelegate != null && !CRS.equalsIgnoreMetadata(crs, crsDelegate)) { ReprojectingFilterVisitor reprojector = new ReprojectingFilterVisitor(FF, delegate.getSchema()); filter = (Filter) filter.accept(reprojector, null); } } SimpleFeatureCollection sub = delegate.subCollection(filter); if (sub != null) { try { ReprojectingFeatureCollection wrapper = new ReprojectingFeatureCollection(sub, target); wrapper.setDefaultSource(defaultSource); return wrapper; } catch (Exception e) { throw new RuntimeException(e); } } return null; }
if (nativeCRS == null) { if (other.getNativeCRS() != null) return false; } else if (!CRS.equalsIgnoreMetadata(nativeCRS, other.getNativeCRS())) return false; if (nativeName == null) { if (other.getNativeName() != null) return false;
@Test public void testWgs84BoundsFromCompoundCRS() throws Exception { try { MapProjection.SKIP_SANITY_CHECKS = true; CatalogBuilder cb = new CatalogBuilder(getCatalog()); ReferencedEnvelope3D bounds = new ReferencedEnvelope3D( 142892, 470783, 16, 142900, 470790, 20, CRS.decode("EPSG:7415")); // used to throw an exception here ReferencedEnvelope latLonBounds = cb.getLatLonBounds(bounds, bounds.getCoordinateReferenceSystem()); assertTrue( CRS.equalsIgnoreMetadata( CRS.decode("EPSG:4326"), latLonBounds.getCoordinateReferenceSystem())); // System.out.println(latLonBounds); } finally { MapProjection.SKIP_SANITY_CHECKS = false; } }
@Test public void testCRSConverterInvalidWKT() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:3575"); try { ((Formattable) crs).toWKT(2, true); fail("expected exception"); } catch (UnformattableObjectException e) { } String wkt = null; try { wkt = new CRSConverter().toString(crs); } catch (UnformattableObjectException e) { fail("Should have thrown exception"); } CoordinateReferenceSystem crs2 = (CoordinateReferenceSystem) new CRSConverter().fromString(wkt); assertTrue(CRS.equalsIgnoreMetadata(crs, crs2)); }
r = (GridCoverage2DReader) ci.getGridCoverageReader(null, GeoTools.getDefaultHints()); assertTrue( CRS.equalsIgnoreMetadata( CRS.decode("EPSG:3857"), r.getCoordinateReferenceSystem())); CRS.equalsIgnoreMetadata( CRS.decode("EPSG:3857"), r.getCoordinateReferenceSystem())); r = (GridCoverage2DReader) rpool.getGridCoverageReader(store, GeoTools.getDefaultHints()); assertTrue( CRS.equalsIgnoreMetadata( CRS.decode("EPSG:4326"), r.getCoordinateReferenceSystem()));
requestedEnvelope.getCoordinateReferenceSystem(); final CoordinateReferenceSystem nativeCRS = reader.getCoordinateReferenceSystem(); if (!CRS.equalsIgnoreMetadata(requestCRS, nativeCRS)) { requestedEnvelope = CRS.transform(requestedEnvelope, nativeCRS);
if (!CRS.equalsIgnoreMetadata(resultCRS, schema.getCoordinateReferenceSystem())) schema = FeatureTypes.transform(schema, resultCRS); } catch (Exception e) {
assertTrue(cv.getParameters().containsKey("foo")); assertNull(cv.getParameters().get("foo")); assertTrue(CRS.equalsIgnoreMetadata(CRS.decode("EPSG:4326"), cv.getNativeCRS()));
assertEquals(ns, wl.getNamespace()); assertEquals("EPSG:4326", wl.getSRS()); assertTrue(CRS.equalsIgnoreMetadata(CRS.decode("EPSG:4326"), wl.getNativeCRS()));
assertEquals(ns, wl.getNamespace()); assertEquals("EPSG:4326", wl.getSRS()); assertTrue(CRS.equalsIgnoreMetadata(CRS.decode("EPSG:4326"), wl.getNativeCRS()));
assertEquals("EPSG:4326", ft.getSRS()); assertEquals(new Measure(10, SI.METRE), ft.getLinearizationTolerance()); assertTrue(CRS.equalsIgnoreMetadata(CRS.decode("EPSG:4326"), ft.getNativeCRS()));