CoordinateReferenceSystem crs = CRS.decode(srs); wli.setSRS(srs); wli.setNativeCRS(crs); if (envelope != null) { ReferencedEnvelope re = new ReferencedEnvelope( envelope.getMinimum(0), envelope.getMaximum(0), envelope.getMinimum(1), envelope.getMaximum(1), wli.getNativeCRS()); if (llbbox != null) { ReferencedEnvelope re = new ReferencedEnvelope( llbbox.getMinX(), llbbox.getMaxX(), try { wli.setLatLonBoundingBox( wli.getNativeBoundingBox().transform(DefaultGeographicCRS.WGS84, true)); } catch (Exception e) { LOGGER.log(Level.INFO, "Could not transform native bbox into a lat/lon one", e);
@Test public void testLatLonBounds() throws Exception { ReferencedEnvelope nativeBounds = new ReferencedEnvelope(700000, 800000, 4000000, 4100000, null); CoordinateReferenceSystem crs = CRS.decode("EPSG:32632", true); CatalogBuilder cb = new CatalogBuilder(getCatalog()); ReferencedEnvelope re = cb.getLatLonBounds(nativeBounds, crs); assertEquals(DefaultGeographicCRS.WGS84, re.getCoordinateReferenceSystem()); assertEquals(11.22, re.getMinX(), 0.01); assertEquals(36.1, re.getMinY(), 0.01); }
@Test public void testWMSLayer130crs84() throws Exception { TestHttpClientProvider.startTest(); try { String baseURL = TestHttpClientProvider.MOCKSERVER + "/wms13"; MockHttpClient client = new MockHttpClient(); URL capsURL = new URL(baseURL + "?service=WMS&request=GetCapabilities&version=1.3.0"); client.expectGet( capsURL, new MockHttpResponse(getClass().getResource("caps130_crs84.xml"), "text/xml")); TestHttpClientProvider.bind(client, capsURL); CatalogBuilder cb = new CatalogBuilder(getCatalog()); WMSStoreInfo store = cb.buildWMSStore("test-store"); store.setCapabilitiesURL(capsURL.toExternalForm()); cb.setStore(store); WMSLayerInfo layer = cb.buildWMSLayer("world4326"); // check the bbox has the proper axis order assertEquals("EPSG:4326", layer.getSRS()); ReferencedEnvelope bbox = layer.getLatLonBoundingBox(); assertEquals(-180, bbox.getMinX(), 0d); assertEquals(-90, bbox.getMinY(), 0d); assertEquals(180, bbox.getMaxX(), 0d); assertEquals(90, bbox.getMaxY(), 0d); } finally { TestHttpClientProvider.endTest(); } }
/** 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; }
@Override public BoundingBox getBoundingBox(CoordinateReferenceSystem crs) { try { Envelope bounds = (Envelope) pedestrianIndex.getRoot().getBounds(); ReferencedEnvelope refEnv = new ReferencedEnvelope(bounds, CRS.decode("EPSG:4326", true)); return refEnv.toBounds(crs); } catch (Exception e) { LOG.error("error transforming graph bounding box to request CRS : {}", crs); return null; } }
@Test public void testNullSymbolizer() throws Exception { CoordinateReferenceSystem googleMercator = CRS.decode("EPSG:3857"); ReferencedEnvelope mapExtent = new ReferencedEnvelope( -20037508.34, 20037508.34, -20037508.34, 20037508.34, googleMercator); Rectangle screenSize = new Rectangle(200, (int) (mapExtent.getHeight() / mapExtent.getWidth() * 200)); AffineTransform w2s = RendererUtilities.worldToScreenTransform(mapExtent, screenSize); GridCoverageRenderer renderer = new GridCoverageRenderer(googleMercator, mapExtent, screenSize, w2s); GridCoverage2D coverage = worldReader.read(null); RenderedImage image = renderer.renderImage( coverage, null, Interpolation.getInstance(Interpolation.INTERP_BICUBIC), Color.RED, 256, 256); File reference = new File( "src/test/resources/org/geotools/renderer/lite/gridcoverage2d/googleMercatorBicubic.png"); ImageAssert.assertEquals(reference, image, 0); }
@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()); }
public DisplayCoverageTest() { headless = GraphicsEnvironment.isHeadless(); bounds = new Rectangle(0, 0, WIDTH, WIDTH); env = new ReferencedEnvelope(bounds, DefaultEngineeringCRS.GENERIC_2D); }
@Test public void testPaddingHeteroMosaic() throws Exception { String testLocation = "hetero_utm"; URL storeUrl = TestData.url(this.getClass(), testLocation); File testDataFolder = new File(storeUrl.toURI()); File testDirectory = crsMosaicFolder.newFolder(testLocation); FileUtils.copyDirectory(testDataFolder, testDirectory); ImageMosaicReader imReader = new ImageMosaicReader(testDirectory, null); ReferencedEnvelope mapExtent = new ReferencedEnvelope(11, 13, -1, 1, DefaultGeographicCRS.WGS84); GridCoverageReaderHelper helper = new GridCoverageReaderHelper( imReader, new Rectangle(1024, 512), mapExtent, Interpolation.getInstance(Interpolation.INTERP_NEAREST)); ReferencedEnvelope readEnvelope = helper.getReadEnvelope(); final double EPS = 1e-3; assertEquals(10.981, readEnvelope.getMinX(), EPS); assertEquals(13.021, readEnvelope.getMaxX(), EPS); assertEquals(-1.041, readEnvelope.getMinY(), EPS); assertEquals(1.037, readEnvelope.getMaxY(), EPS); }
GridCoverageUtilities.getReferencedEnvelopeFromGeographicBoundingBox( new GeographicBoundingBoxImpl(coverageEnvelope)); coverageRequestedRasterArea = new Rectangle(); coverageCRS2D = CRS.getHorizontalCRS(coverageCRS); assert coverageCRS2D.getCoordinateSystem().getDimension() == 2; if (coverageCRS.getCoordinateSystem().getDimension() != 2) { final MathTransform transform = CRS.findMathTransform(coverageCRS, (CoordinateReferenceSystem) coverageCRS2D); final GeneralEnvelope bbox = CRS.transform(transform, coverageEnvelope); bbox.setCoordinateReferenceSystem(coverageCRS2D); coverageBBox = new ReferencedEnvelope(bbox); } else { coverageBBox = new ReferencedEnvelope(coverageEnvelope);
/** * Test custom PADDING is being used when provided as Hint * * @throws Exception */ @Test public void testPadding() throws Exception { CoordinateReferenceSystem wgs84 = CRS.decode("EPSG:4326", true); final double envWidth = 30; final double envHeight = 30; ReferencedEnvelope mapExtent = new ReferencedEnvelope(0, envWidth, 0, envHeight, wgs84); Rectangle screenSize = new Rectangle((int) envWidth, (int) envHeight); checkPadding(screenSize, mapExtent, 4); checkPadding(screenSize, mapExtent, 12); }
@Test public void coordinateTransform_MatchingAspectRatioDisabled() throws Exception { MapViewport vp = new MapViewport(false); // world and screen bounds with different aspect ratios final ReferencedEnvelope world = WORLD_1_1; final Rectangle screen = SCREEN_2_1; vp.setBounds(world); vp.setScreenArea(screen); double[] screenXY = { screen.getMinX(), screen.getMinY(), screen.getMaxX(), screen.getMaxY() }; double[] worldXY = new double[screenXY.length]; vp.getScreenToWorld().transform(screenXY, 0, worldXY, 0, screenXY.length / 2); assertEquals(world.getMinX(), worldXY[0], TOL); assertEquals(world.getMaxY(), worldXY[1], TOL); assertEquals(world.getMaxX(), worldXY[2], TOL); assertEquals(world.getMinY(), worldXY[3], TOL); }
assertEquals(2, some.size()); ReferencedEnvelope e = new ReferencedEnvelope(CRS.decode("EPSG:4326", forceLongitudeFirst)); e.include(td.roadFeatures[0].getBounds()); e.include(td.roadFeatures[1].getBounds()); assertEquals(1, half.getSchema().getAttributeCount()); SimpleFeatureType actual = reader.next().getFeatureType(); assertEquals(type.getName(), actual.getName()); assertEquals(type.getAttributeCount(), actual.getAttributeCount());
@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); }
/** Calculates the world bounds of the current screen area. */ private ReferencedEnvelope calculateActualBounds() { Point2D p0 = new Point2D.Double(screenArea.getMinX(), screenArea.getMinY()); Point2D p1 = new Point2D.Double(screenArea.getMaxX(), screenArea.getMaxY()); screenToWorld.transform(p0, p0); screenToWorld.transform(p1, p1); return new ReferencedEnvelope( Math.min(p0.getX(), p1.getX()), Math.max(p0.getX(), p1.getX()), Math.min(p0.getY(), p1.getY()), Math.max(p0.getY(), p1.getY()), bounds.getCoordinateReferenceSystem()); }
public GridCoverage2D getDummyRaster() { WritableRaster raster = WritableRaster.createBandedRaster(DataBuffer.TYPE_INT, 1,1,1, new Point(0,0)); raster.setSample(0,0,0,Integer.MIN_VALUE); Envelope e = getActivityField().getBoundingBox().getEnvelopeInternal(); BoundingBox boundingBox = new ReferencedEnvelope(e.getMinX(), e.getMaxX(), e.getMinY(), e.getMaxY(), DefaultGeographicCRS.WGS84); GridCoverageFactory factory = CoverageFactoryFinder.getGridCoverageFactory(null); return factory.create("name", raster, boundingBox); }
@Test public void testWrapGeometryReprojectToLatLonED50() throws Exception { ReferencedEnvelope world = new ReferencedEnvelope(-80, 80, -180, 180, ED50_LATLON); // make sure the geometry is not wrapped, but it is preserved ProjectionHandler handler = ProjectionHandlerFinder.getHandler(world, WGS84, true); // a geometry that will cross the dateline and sitting in the same area as the // rendering envelope (with wgs84 lon/latcoordinates) String wkt = "POLYGON((178 -80, 178 80, 182 80, 182 80, 178 -80))"; Geometry g = new WKTReader().read(wkt); Geometry original = new WKTReader().read(wkt); MathTransform mt = CRS.findMathTransform(WGS84, ED50_LATLON); MathTransform prepared = handler.getRenderingTransform(CRS.findMathTransform(WGS84, ED50_LATLON)); Geometry reprojected = JTS.transform(original, prepared); assertTrue(handler.requiresProcessing(g)); Geometry preProcessed = handler.preProcess(g); // no cutting expected assertEquals(original, preProcessed); // post process, this should wrap the geometry and clone it Geometry postProcessed = handler.postProcess(prepared, reprojected); assertTrue(postProcessed instanceof MultiPolygon); }
@Test public void testUTMDatelineWrapping() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:32601", true); ReferencedEnvelope re = new ReferencedEnvelope(300000, 409800, 5890200, 6000000, crs); MathTransform mt = CRS.findMathTransform(crs, WGS84); Geometry geom = JTS.toGeometry(re); ReferencedEnvelope targetReferenceEnvelope = new ReferencedEnvelope(-180, 180, -90, 90, WGS84); ProjectionHandler ph = ProjectionHandlerFinder.getHandler(targetReferenceEnvelope, crs, true); Geometry preProcessed = ph.preProcess(geom); Geometry transformed = JTS.transform(preProcessed, mt); Geometry postProcessed = ph.postProcess(mt.inverse(), transformed); // sits across the dateline and it's "small" (used to cover the entire planet) Envelope ppEnvelope = postProcessed.getGeometryN(0).getEnvelopeInternal(); assertTrue(ppEnvelope.contains(180, 54)); // the original width is 109km, at this latitude one degree of longitude is only 65km assertEquals(1.7, ppEnvelope.getWidth(), 0.1); }
@Test public void testWrapGeometryMercator() throws Exception { ReferencedEnvelope world = new ReferencedEnvelope(160, 180, -40, 40, WGS84); ReferencedEnvelope mercatorEnvelope = world.transform(MERCATOR, true); // move it so that it crosses the dateline (measures are still accurate for something // crossing the dateline mercatorEnvelope.translate(mercatorEnvelope.getWidth() / 2, 0); // a geometry that will cross the dateline and sitting in the same area as the // rendering envelope Geometry g = new WKTReader().read("LINESTRING(170 -40, 190 40)"); // make sure the geometry is not wrapped ProjectionHandler handler = ProjectionHandlerFinder.getHandler(mercatorEnvelope, WGS84, true); assertTrue(handler.requiresProcessing(g)); Geometry preProcessed = handler.preProcess(g); // no cutting expected assertEquals(g, preProcessed); // transform and post process MathTransform mt = CRS.findMathTransform(WGS84, MERCATOR, true); Geometry transformed = JTS.transform(g, mt); Geometry postProcessed = handler.postProcess(mt.inverse(), transformed); Envelope env = postProcessed.getEnvelopeInternal(); // check the geometry is in the same area as the rendering envelope assertEquals(mercatorEnvelope.getMinX(), env.getMinX(), EPS); assertEquals(mercatorEnvelope.getMaxX(), env.getMaxX(), EPS); }