/** * 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; }
private void checkReprojection() throws FactoryException { geometryCRS = CRS.getHorizontalCRS(sourceCRS); CoordinateReferenceSystem renderingCRS = renderingEnvelope.getCoordinateReferenceSystem(); try { noReprojection = !CRS.isTransformationRequired(geometryCRS, renderingCRS); } catch (Exception e) { LOGGER.log( Level.FINE, "Failed to determine is reprojection is required, assumming it is", e); noReprojection = false; } }
SingleCRS horizontalCRS = CRS.getHorizontalCRS(crs); Unit targetUnit; if (horizontalCRS != null) {
/** Tests {@link CRS#getHorizontalCRS} from a compound CRS. */ public void testHorizontalFromCompound() throws FactoryException { // retrives "NTF (Paris) / France II + NGF Lallemand" CoordinateReferenceSystem compound = CRS.decode("EPSG:7401"); CoordinateReferenceSystem horizontal = CRS.getHorizontalCRS(compound); // compares with "NTF (Paris) / France II" assertEquals(CRS.decode("EPSG:27582"), horizontal); }
/** * Initializes a projection handler * * @param sourceCRS The source CRS * @param validAreaBounds The valid area (used to cut geometries that go beyond it) * @param renderingEnvelope The target rendering area and target CRS * @throws FactoryException */ public ProjectionHandler( CoordinateReferenceSystem sourceCRS, Envelope validAreaBounds, ReferencedEnvelope renderingEnvelope) throws FactoryException { this.renderingEnvelope = renderingEnvelope; this.sourceCRS = CRS.getHorizontalCRS(sourceCRS); this.targetCRS = renderingEnvelope.getCoordinateReferenceSystem(); this.validAreaBounds = validAreaBounds != null ? new ReferencedEnvelope(validAreaBounds, DefaultGeographicCRS.WGS84) : null; this.validArea = null; this.validaAreaTester = null; // query across dateline only in case of reprojection, Oracle won't use the spatial index // with two or-ed bboxes and fixing the issue at the store level requires more // time/resources than we presently have this.queryAcrossDateline = !CRS.equalsIgnoreMetadata( sourceCRS, renderingEnvelope.getCoordinateReferenceSystem()); checkReprojection(); }
@Test public void testGetHorizontalCrs() { assertEquals( DefaultEngineeringCRS.GENERIC_2D, CRS.getHorizontalCRS(DefaultEngineeringCRS.GENERIC_2D)); }
CoordinateReferenceSystem crs = CRS.getHorizontalCRS(CRS.decode("EPSG:" + currentSRID)); double distanceMeters = getDistanceInMeters(operator); if (crs instanceof GeographicCRS) {
@Test public void testWrappingOn3DCRS() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:4939", true); SingleCRS hcrs = CRS.getHorizontalCRS(crs); ReferencedEnvelope wgs84Envelope = new ReferencedEnvelope(-190, 60, -90, 45, hcrs); ProjectionHandler handler = ProjectionHandlerFinder.getHandler(wgs84Envelope, crs, true); assertNull(handler.validAreaBounds); List<ReferencedEnvelope> envelopes = handler.getQueryEnvelopes(); assertEquals(2, envelopes.size()); ReferencedEnvelope expected = new ReferencedEnvelope(170, 180, -90, 45, hcrs); assertTrue(envelopes.remove(wgs84Envelope)); assertEquals(expected, envelopes.get(0)); }
transformTo2D = CRS.findMathTransform( requestedEnvelopeCRS2D, CRS.getHorizontalCRS(requestedEnvelopeCRS2D)); requestedEnvelopeCRS2D = CRS.getHorizontalCRS(requestedEnvelopeCRS2D); } else transformTo2D = IdentityTransform.create(2);
coverageCRS2D = CRS.getHorizontalCRS(coverageCRS); assert coverageCRS2D.getCoordinateSystem().getDimension() == 2; if (coverageCRS.getCoordinateSystem().getDimension() != 2) {
final Rectangle2D rect = gridCoverageReader.getOriginalEnvelope().toRectangle2D(); final CoordinateReferenceSystem sourceCrs = CRS.getHorizontalCRS(gridCoverageReader.getCoordinateReferenceSystem()); if (sourceCrs == null) throw new UnsupportedOperationException(
CRS.getHorizontalCRS(envelope.getCoordinateReferenceSystem()); if (envelopeCrs2D != null && !CRS.equalsIgnoreMetadata(crs, envelopeCrs2D)) { CoordinateOperationFactory operationFactory =
coverageCRS2D = CRS.getHorizontalCRS(coverageCRS); assert coverageCRS2D.getCoordinateSystem().getDimension() == 2; if (coverageCRS.getCoordinateSystem().getDimension() != 2) {
public Object visit(BBOX filter, Object extraData) { // if no srs is specified we can't transform anyways String srs = filter.getSRS(); if (srs != null && !"".equals(srs.trim())) return super.visit(filter, extraData); if (defaultCrs == null || filter.getBounds() == null || defaultCrs.getCoordinateSystem().getDimension() == filter.getBounds().getDimension()) { return getFactory(extraData) .bbox( filter.getExpression1(), ReferencedEnvelope.create(filter.getBounds(), defaultCrs)); } else { try { SingleCRS horizontalCRS = CRS.getHorizontalCRS(defaultCrs); ReferencedEnvelope bounds = ReferencedEnvelope.create(filter.getBounds(), horizontalCRS); return getFactory(extraData).bbox(filter.getExpression1(), bounds); } catch (Exception e) { throw new RuntimeException("Could not decode srs '" + srs + "'", e); } } }
@Test public void force3DCRS2DEnvelope() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:4939", true); CoordinateReferenceSystem hcrs = CRS.getHorizontalCRS(crs); BBOX bbox = ff.bbox("the_geom", -180, -90, 180, 90, null); DefaultCRSFilterVisitor visitor = new DefaultCRSFilterVisitor(ff, crs); BBOX filtered = (BBOX) bbox.accept(visitor, null); Literal box = (Literal) filtered.getExpression2(); Geometry g = (Geometry) box.evaluate(null); assertEquals(hcrs, g.getUserData()); }
/** Tests {@link CRS#getHorizontalCRS} from a Geographic 3D CR. */ public void testHorizontalFromGeodetic() throws FactoryException { // retrives "WGS 84 (geographic 3D)" CoordinateReferenceSystem compound = CRS.decode("EPSG:4327"); CoordinateReferenceSystem horizontal = CRS.getHorizontalCRS(compound); // the horizonal version is basically 4326, but it won't compare positively // with 4326, not even using CRS.equalsIgnoreMetadata(), so we check the axis directly CoordinateSystem cs = horizontal.getCoordinateSystem(); assertEquals(2, cs.getDimension()); assertEquals(AxisDirection.NORTH, cs.getAxis(0).getDirection()); assertEquals(AxisDirection.EAST, cs.getAxis(1).getDirection()); }
returnedCRS = CRS.getHorizontalCRS(coverage.getCoordinateReferenceSystem()); if (returnedCRS == null) throw new TransformException(
@Test public void force3DCRS3DEnvelope() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:4939", true); CoordinateReferenceSystem hcrs = CRS.getHorizontalCRS(crs); BBOX bbox = ff.bbox( ff.property("the_geom"), new ReferencedEnvelope3D(-180, 180, -90, 90, 0, 100, null)); DefaultCRSFilterVisitor visitor = new DefaultCRSFilterVisitor(ff, crs); BBOX filtered = (BBOX) bbox.accept(visitor, null); Literal box = (Literal) filtered.getExpression2(); Geometry g = (Geometry) box.evaluate(null); assertEquals(crs, g.getUserData()); } }
coverageCRS2D = CRS.getHorizontalCRS(coverageCRS); assert coverageCRS2D.getCoordinateSystem().getDimension() == 2; if (coverageCRS.getCoordinateSystem().getDimension() != 2) {
/** * Make sure we can properly retrieve the bounds of 3d layers * * @throws Exception */ public void testBounds() throws Exception { ReferencedEnvelope env = dataStore.getFeatureSource(tname(getLine3d())).getBounds(); // check we got the right 2d component Envelope expected = new Envelope(1, 5, 0, 4); assertEquals(expected, env); // check the srs the expected one assertEquals(CRS.getHorizontalCRS(crs), env.getCoordinateReferenceSystem()); }