@Test public void testQueryEnvelopeOnInvalidArea() throws Exception { // and Envelope that does not make sense for EPSG:3003, too far away from central meridian ReferencedEnvelope re = new ReferencedEnvelope(-130, -120, -40, 30, DefaultGeographicCRS.WGS84); ProjectionHandler ph = ProjectionHandlerFinder.getHandler(re, CRS.decode("EPSG:3003", true), true); List<ReferencedEnvelope> queryEnvelopes = ph.getQueryEnvelopes(); assertEquals(0, queryEnvelopes.size()); }
/** * Returns a projection handler for the specified rendering area, or null if not found * * @param renderingArea The area to be painted (mind, the CRS must be property set for * projection handling to work) * @param wrap Enable continuous map wrapping if it's possible for the current projection * @throws FactoryException */ public static ProjectionHandler getHandler( ReferencedEnvelope renderingArea, CoordinateReferenceSystem sourceCrs, boolean wrap) throws FactoryException { if (renderingArea.getCoordinateReferenceSystem() == null) return null; for (ProjectionHandlerFactory factory : getProjectionHandlerFactories()) { ProjectionHandler handler = factory.getHandler(renderingArea, sourceCrs, wrap, WRAP_LIMIT); if (handler != null) return handler; } return null; } }
@Test public void testQueryEnvelopesWrappingWGS84() throws Exception { // dateline crossing request ReferencedEnvelope request = new ReferencedEnvelope(170, 190, -40, 40, WGS84); // grab a non wrapping handler ProjectionHandler handler = ProjectionHandlerFinder.getHandler(request, WGS84, true); List<ReferencedEnvelope> envelopes = handler.getQueryEnvelopes(); assertEquals(2, envelopes.size()); assertTrue(envelopes.contains(new ReferencedEnvelope(170, 180, -40, 40, WGS84))); assertTrue(envelopes.contains(new ReferencedEnvelope(-180, -170, -40, 40, WGS84))); }
@Test public void testQueryEnvelopeOnInvalidArea2() throws Exception { // and Envelope that does not make sense for EPSG:3003, too far away from central meridian ReferencedEnvelope re = new ReferencedEnvelope(-130, -120, -40, 30, DefaultGeographicCRS.WGS84); ReferencedEnvelope re3857 = re.transform(CRS.decode("EPSG:3857", true), true); ProjectionHandler ph = ProjectionHandlerFinder.getHandler(re3857, CRS.decode("EPSG:3003", true), true); List<ReferencedEnvelope> queryEnvelopes = ph.getQueryEnvelopes(); assertEquals(0, queryEnvelopes.size()); }
@Test public void testQueryEnvelopesNonWrappingWGS84() throws Exception { // dateline crossing request ReferencedEnvelope request = new ReferencedEnvelope(170, 190, -40, 40, WGS84); // grab a non wrapping handler ProjectionHandler handler = ProjectionHandlerFinder.getHandler(request, WGS84, false); List<ReferencedEnvelope> envelopes = handler.getQueryEnvelopes(); assertEquals(1, envelopes.size()); assertEquals(request, envelopes.get(0)); }
private ReferencedEnvelope reprojectBounds( ReferencedEnvelope referenceBounds, CoordinateReferenceSystem targetCRS, ReferencedEnvelope bounds) throws FactoryException, TransformException { ProjectionHandler ph = ProjectionHandlerFinder.getHandler(referenceBounds, targetCRS, true); ReferencedEnvelope targetBounds = null; if (ph != null) { List<ReferencedEnvelope> queryEnvelopes = ph.getQueryEnvelopes(); for (ReferencedEnvelope envelope : queryEnvelopes) { ReferencedEnvelope transformed = envelope.transform(targetCRS, true); if (targetBounds == null) { targetBounds = transformed; } else { targetBounds.expandToInclude(transformed); } } } else { targetBounds = bounds.transform(targetCRS, true); } return targetBounds; }
@Test public void testQueryWrappingWGS84() throws Exception { ReferencedEnvelope wgs84Envelope = new ReferencedEnvelope(-190, 60, -90, 45, WGS84); ProjectionHandler handler = ProjectionHandlerFinder.getHandler(wgs84Envelope, WGS84, true); assertNull(handler.validAreaBounds); List<ReferencedEnvelope> envelopes = handler.getQueryEnvelopes(); assertEquals(2, envelopes.size()); ReferencedEnvelope expected = new ReferencedEnvelope(170, 180, -90, 45, WGS84); assertTrue(envelopes.remove(wgs84Envelope)); assertEquals(expected, envelopes.get(0)); }
boolean isAccurateResolutionComputationSafe(ReferencedEnvelope readEnvelope) throws MismatchedDimensionException, FactoryException, TransformException { // accurate resolution computation depends on reprojection working, we need // to make sure the read envelope is sane for the source data at hand CoordinateReferenceSystem readCRS = readEnvelope.getCoordinateReferenceSystem(); ProjectionHandler handler = ProjectionHandlerFinder.getHandler( new ReferencedEnvelope(readCRS), DefaultGeographicCRS.WGS84, true); if (handler != null) { // if there are no limits or the projection is periodic, assume it's fine to read // whatever if (handler.getValidAreaBounds() == null || handler instanceof WrappingProjectionHandler) { return true; } // in this case we need to make sure the area is actually safe to perform reprojections // on try { // when assertions are enabled accuracy tests might fail this path ReferencedEnvelope validBounds = handler.getValidAreaBounds().transform(readCRS, true); return validBounds.contains((Envelope) readEnvelope); } catch (Exception e) { return false; } } else { return false; } }
@Test public void testQueryWrappingED50LatLon() throws Exception { ReferencedEnvelope envelope = new ReferencedEnvelope(-90, 45, -190, 60, ED50_LATLON); ProjectionHandler handler = ProjectionHandlerFinder.getHandler(envelope, ED50_LATLON, true); assertNull(handler.validAreaBounds); List<ReferencedEnvelope> envelopes = handler.getQueryEnvelopes(); assertEquals(2, envelopes.size()); ReferencedEnvelope expected = new ReferencedEnvelope(-90, 45, 170, 180, ED50_LATLON); assertTrue(envelopes.remove(envelope)); assertEquals(expected, envelopes.get(0)); }
@Test public void testQueryOutsideValidArea() throws Exception { ReferencedEnvelope world = new ReferencedEnvelope(-200, 200, -89, -86, WGS84); ReferencedEnvelope mercatorEnvelope = world.transform(MERCATOR_SHIFTED, true); ProjectionHandler handler = ProjectionHandlerFinder.getHandler(mercatorEnvelope, WGS84, true); List<ReferencedEnvelope> envelopes = handler.getQueryEnvelopes(); assertEquals(0, envelopes.size()); }
@Test public void testQueryEnvelopesWrapping3857() throws Exception { // dateline crossing request ReferencedEnvelope requestWgs84 = new ReferencedEnvelope(170, 190, -40, 40, WGS84); ReferencedEnvelope request = requestWgs84.transform(OSM, true); // grab a non wrapping handler ProjectionHandler handler = ProjectionHandlerFinder.getHandler(request, WGS84, true); List<ReferencedEnvelope> envelopes = handler.getQueryEnvelopes(); assertEquals(2, envelopes.size()); assertEnvelopesEqual( new ReferencedEnvelope(170, 180, -40, 40, WGS84), envelopes.get(0), EPS); assertEnvelopesEqual( new ReferencedEnvelope(-180, -170, -40, 40, WGS84), envelopes.get(1), EPS); }
@Test public void testQueryEnvelopesNonWrapping3857() throws Exception { // dateline crossing request ReferencedEnvelope requestWgs84 = new ReferencedEnvelope(170, 190, -40, 40, WGS84); ReferencedEnvelope request = requestWgs84.transform(OSM, true); // grab a non wrapping handler ProjectionHandler handler = ProjectionHandlerFinder.getHandler(request, WGS84, false); List<ReferencedEnvelope> envelopes = handler.getQueryEnvelopes(); assertEquals(1, envelopes.size()); assertEnvelopesEqual(requestWgs84, envelopes.get(0), EPS); }
@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)); }
@Test public void testWGS84BackToWebMercator() throws Exception { ReferencedEnvelope renderingEnvelope = new ReferencedEnvelope(135, 180, -90, -45, WGS84); ProjectionHandler handler = ProjectionHandlerFinder.getHandler(renderingEnvelope, OSM, true); assertNotNull(handler); List<ReferencedEnvelope> queryEnvelopes = handler.getQueryEnvelopes(); assertEquals(1, queryEnvelopes.size()); ReferencedEnvelope expected = new ReferencedEnvelope( 1.5028131257091932E7, 2.0037508342789244E7, -1.9971868880408555E7, -5621521.486192067, OSM); assertEnvelopesEqual(expected, queryEnvelopes.get(0), EPS); }
@Test public void testQueryUTM() throws Exception { ReferencedEnvelope wgs84Envelope = new ReferencedEnvelope(8, 10, 40, 45, WGS84); ReferencedEnvelope utmEnvelope = wgs84Envelope.transform(UTM32N, true); // get query area, we expect just one envelope, the original one ProjectionHandler handler = ProjectionHandlerFinder.getHandler(utmEnvelope, WGS84, true); ReferencedEnvelope expected = utmEnvelope.transform(WGS84, true); List<ReferencedEnvelope> envelopes = handler.getQueryEnvelopes(); assertEquals(1, envelopes.size()); assertEquals(expected, envelopes.get(0)); }
@Test public void testE50LatLonBackToWebMercator() throws Exception { ReferencedEnvelope renderingEnvelope = new ReferencedEnvelope(-80, -45, 135, 180, ED50_LATLON); ProjectionHandler handler = ProjectionHandlerFinder.getHandler(renderingEnvelope, OSM, true); assertNotNull(handler); List<ReferencedEnvelope> queryEnvelopes = handler.getQueryEnvelopes(); assertEquals(1, queryEnvelopes.size()); // the ED50 to WGS84 switch causes dateline switch, making it read a larger area... // to be fixed in another commit (a different Jira) ReferencedEnvelope expected = new ReferencedEnvelope( -2.003748375258002E7, 1.9582312033733368E7, -1.5538175797794182E7, -5621345.809658899, OSM); assertEnvelopesEqual(expected, queryEnvelopes.get(0), EPS); }
handler = ProjectionHandlerFinder.getHandler(targetReferenceEnvelope, sourceCRS, true); } else { handler = ProjectionHandlerFinder.getHandler(reference, sourceCRS, false);
@Test public void testE50BackToWebMercator() throws Exception { ReferencedEnvelope renderingEnvelope = new ReferencedEnvelope(135, 180, -80, -45, ED50); ProjectionHandler handler = ProjectionHandlerFinder.getHandler(renderingEnvelope, OSM, true); assertNotNull(handler); List<ReferencedEnvelope> queryEnvelopes = handler.getQueryEnvelopes(); assertEquals(1, queryEnvelopes.size()); // the ED50 to WGS84 switch causes dateline switch, making it read a larger area... // to be fixed in another commit (a different Jira) ReferencedEnvelope expected = new ReferencedEnvelope( -2.003748375258002E7, 1.9582312033733368E7, -1.5538175797794182E7, -5621345.809658899, OSM); assertEnvelopesEqual(expected, queryEnvelopes.get(0), EPS); } }
@Test public void testOutsideDefinitionArea() throws Exception { // setup a request that is outside of the coverage CoordinateReferenceSystem crs = CRS.decode("EPSG:3031", true); ReferencedEnvelope mapExtent = new ReferencedEnvelope(-1250000, 0, -13750000, -12500000, crs); // System.out.println(mapExtent.transform(DefaultGeographicCRS.WGS84, true)); GridCoverageReaderHelper helper = new GridCoverageReaderHelper( reader, new Rectangle(400, 200), mapExtent, Interpolation.getInstance(Interpolation.INTERP_NEAREST)); // read, nothing should come out ProjectionHandler handler = ProjectionHandlerFinder.getHandler( mapExtent, reader.getCoordinateReferenceSystem(), true); List<GridCoverage2D> coverages = helper.readCoverages(null, handler); assertTrue(coverages.isEmpty()); }
@Test public void testCutGeometryLambertConformal() throws Exception { // get a lambert conformal conic with ReferencedEnvelope wgs84South = new ReferencedEnvelope(-180, -90, -40, 0, WGS84); ReferencedEnvelope laeSouth = wgs84South.transform(CRS.decode("EPSG:2194"), true); ProjectionHandler handler = ProjectionHandlerFinder.getHandler(laeSouth, WGS84, true); // a Geometry that crosses the opposite of the central meridian Polygon geometry = JTS.toGeometry(new Envelope(5, 15, 0, 10)); Geometry preProcessed = handler.preProcess(geometry); assertTrue( "Should have sliced the geometry in two parts", preProcessed instanceof MultiPolygon); }