ProjectionHandler { public List<ReferencedEnvelope> getQueryEnvelopes() throws TransformException, FactoryException { CoordinateReferenceSystem renderingCRS = renderingEnvelope.getCoordinateReferenceSystem(); if(renderingCRS instanceof GeographicCRS && !CRS.equalsIgnoreMetadata(renderingCRS, WGS84)) { ReferencedEnvelope re = renderingEnvelope; List<ReferencedEnvelope> envelopes = new ArrayList<ReferencedEnvelope>(); envelopes.add(re); if(CRS.getAxisOrder(renderingCRS) == CRS.AxisOrder.NORTH_EAST) { if (re.getMinY() >= -180.0 && re.getMaxY() <= 180) { return Collections .singletonList(transformEnvelope(renderingEnvelope, sourceCRS)); } if (re.getMinY() < -180) { envelopes.add(new ReferencedEnvelope(re.getMinY() + 360, 180, re.getMinX(), re .getMaxX(), re.getCoordinateReferenceSystem())); } if (re.getMaxY() > 180) { envelopes.add(new ReferencedEnvelope(-180, re.getMaxY() - 360, re.getMinX(), re .getMaxX(), re.getCoordinateReferenceSystem())); } } else { if (re.getMinX() >= -180.0 && re.getMaxX() <= 180) { return Collections .singletonList(transformEnvelope(renderingEnvelope, sourceCRS)); } if (re.getMinX() < -180) { envelopes.add(new ReferencedEnvelope(re.getMinX() + 360, 180, re.getMinY(), re .getMaxY(), re.getCoordinateReferenceSystem())); } if (re.getMaxX() > 180) { envelopes.add(new ReferencedEnvelope(-180, re.getMaxX() - 360, re.getMinY(), re .getMaxY(), re.getCoordinateReferenceSystem())); } } mergeEnvelopes(envelopes); reprojectEnvelopes(sourceCRS, envelopes); return envelopes; } else { if (!Double.isNaN(datelineX) && renderingEnvelope.getMinX() < datelineX && renderingEnvelope.getMaxX() > datelineX && renderingEnvelope.getWidth() < radius) { double minX = renderingEnvelope.getMinX(); double minY = renderingEnvelope.getMinY(); double maxX = renderingEnvelope.getMaxX(); double maxY = renderingEnvelope.getMaxY(); ReferencedEnvelope re1 = new ReferencedEnvelope(minX, datelineX - EPS, minY, maxY, renderingCRS); ReferencedEnvelope tx1 = transformEnvelope(re1, WGS84); tx1.expandToInclude(180, tx1.getMinY()); ReferencedEnvelope re2 = new ReferencedEnvelope(datelineX + EPS, maxX, minY, maxY, renderingCRS); ReferencedEnvelope tx2 = transformEnvelope(re2, WGS84); if (tx2.getMinX() > 180) { tx2.translate(-360, 0); } tx2.expandToInclude(-180, tx1.getMinY()); List<ReferencedEnvelope> result = new ArrayList<ReferencedEnvelope>(); result.add(tx1); result.add(tx2); mergeEnvelopes(result); return result; } else { return getSourceEnvelopes(renderingEnvelope); } } } ProjectionHandler(CoordinateReferenceSystem sourceCRS, Envelope validAreaBounds, ReferencedEnvelope renderingEnvelope);  ProjectionHandler(CoordinateReferenceSystem sourceCRS, Geometry validArea, ReferencedEnvelope renderingEnvelope); ReferencedEnvelope getRenderingEnvelope(); CoordinateReferenceSystem getSourceCRS(); List<ReferencedEnvelope> getQueryEnvelopes(); boolean requiresProcessing(Geometry geometry); Geometry preProcess(Geometry geometry); MathTransform getRenderingTransform(MathTransform mt); Geometry postProcess(MathTransform mt, Geometry geometry); ReferencedEnvelope getValidAreaBounds();  }
@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 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)); }
@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(170, 180, -90, 45, ED50_LATLON); assertTrue(envelopes.remove(envelope)); assertEquals(expected, envelopes.get(0)); }
@Test public void testQueryWrappingMercatorWorld() throws Exception { ReferencedEnvelope world = new ReferencedEnvelope(-200, 200, -89, 89, WGS84); ReferencedEnvelope mercatorEnvelope = world.transform(MERCATOR_SHIFTED, true); ProjectionHandler handler = ProjectionHandlerFinder.getHandler(mercatorEnvelope, WGS84, true); List<ReferencedEnvelope> envelopes = handler.getQueryEnvelopes(); assertEquals(1, envelopes.size()); ReferencedEnvelope env = envelopes.get(0); assertEquals(-180.0, env.getMinX(), EPS); assertEquals(180.0, env.getMaxX(), EPS); assertEquals(-89, env.getMinY(), 0.1); assertEquals(89.0, env.getMaxY(), 0.1); }
@Test public void testQueryWrappingMercatorSeparate() throws Exception { ReferencedEnvelope world = new ReferencedEnvelope(160, 180, -40, 40, WGS84); ReferencedEnvelope mercatorEnvelope = world.transform(MERCATOR, true); mercatorEnvelope.translate(mercatorEnvelope.getWidth() / 2, 0); ProjectionHandler handler = ProjectionHandlerFinder.getHandler(mercatorEnvelope, WGS84, true); List<ReferencedEnvelope> envelopes = handler.getQueryEnvelopes(); assertEquals(2, envelopes.size()); ReferencedEnvelope reOrig = envelopes.get(0); assertEquals(170.0, reOrig.getMinX(), EPS); assertEquals(180.0, reOrig.getMaxX(), EPS); ReferencedEnvelope reAdded = envelopes.get(1); assertEquals(-180.0, reAdded.getMinX(), EPS); assertEquals(-170.0, reAdded.getMaxX(), EPS); }
@Test public void testQueryWrappingPacificMercator() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:3832"); ReferencedEnvelope mercatorEnvelope = new ReferencedEnvelope(1113195, 5565975, 0, 4838471, crs); ProjectionHandler handler = ProjectionHandlerFinder.getHandler(mercatorEnvelope, WGS84, true); List<ReferencedEnvelope> envelopes = handler.getQueryEnvelopes(); assertEquals(2, envelopes.size()); ReferencedEnvelope reOrig = envelopes.get(0); assertEquals(160.0, reOrig.getMinX(), EPS); assertEquals(180.0, reOrig.getMaxX(), EPS); ReferencedEnvelope reAdded = envelopes.get(1); assertEquals(-180.0, reAdded.getMinX(), EPS); assertEquals(-160.0, reAdded.getMaxX(), EPS); }
@Test public void testQueryUTM() throws Exception { ReferencedEnvelope wgs84Envelope = new ReferencedEnvelope(8, 10, 40, 45, WGS84); ReferencedEnvelope utmEnvelope = wgs84Envelope.transform(UTM32N, true); 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)); }