@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 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 testUseCRSBounds() throws NoSuchAuthorityCodeException, FactoryException { // this test is almost trivial since the code itself is trivial CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326"); LayerGroupHelper helper = new LayerGroupHelper(nested); helper.calculateBoundsFromCRS(targetCRS); // layer group bounds should now match target CRS bounds assertEquals(nested.getBounds(), new ReferencedEnvelope(CRS.getEnvelope(targetCRS))); // null CRS should get null bounds helper.calculateBoundsFromCRS(null); assertEquals(nested.getBounds(), null); }
@Test public void testHeterogeneousViewOutsideBounds() throws Exception { CoverageInfo info = new GridGeometry2D( new GridEnvelope2D(0, 0, 10, 10), new ReferencedEnvelope(0, 1000, 0, 1000, UTM32N))); GridCoverage2DReader reader = (GridCoverage2DReader) info.getGridCoverageReader(null, null);
@Test public void empty() { // ensure empty can grab a default CRS when starting from nothing ReferencedEnvelope bbox = new ReferencedEnvelope(); // this is empty assertNull(bbox.getCoordinateReferenceSystem()); ReferencedEnvelope australia = new ReferencedEnvelope(DefaultGeographicCRS.WGS84); australia.include(40, 110); australia.include(10, 150); bbox.include(australia); assertEquals(australia.getCoordinateReferenceSystem(), bbox.getCoordinateReferenceSystem()); }
if (bounds != null && bounds.getCoordinateReferenceSystem() == null && crs != null) { bounds = new ReferencedEnvelope(bounds, crs); if (bounds.getCoordinateReferenceSystem() instanceof GeographicCRS) { expandBy = 0.0001; bounds = new ReferencedEnvelope(reader.getOriginalEnvelope());
public void testReprojectEnvelopeCrsFromQuery() throws Exception { Query query = new Query(Query.ALL); CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326"); CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:3005"); query.setCoordinateSystemReproject(targetCRS); ReferencedEnvelope envelope = data.getFeatureSource("river").getBounds(query); assertEquals(targetCRS, envelope.getCoordinateReferenceSystem()); assertEquals( new ReferencedEnvelope(riverBounds, sourceCRS).transform(targetCRS, true), envelope); }
@Test public void testMultiStyleGroup() throws Exception { Catalog catalog = getCatalog(); new ReferencedEnvelope(-180, 180, -90, 90, DefaultGeographicCRS.WGS84), lg.getBounds());
@Test public void testGetBoundsFromCRS() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.LINES.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.LINES)); CoordinateReferenceSystem resourceCRS = fti.getCRS(); assertNotNull(resourceCRS); // make sure the srs is as expected, otherwise the rest of the tests don't make sense assertEquals("EPSG:32615", fti.getSRS()); ReferencedEnvelope crsBounds = cb.getBoundsFromCRS(fti); assertNotNull(crsBounds); CoordinateReferenceSystem exptectedCRS = CRS.decode("EPSG:32615"); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds); // if we change the srs when there's no reproject policy, should still be the same bounding // box fti.setSRS("EPSG:4326"); fti.setProjectionPolicy(ProjectionPolicy.NONE); crsBounds = cb.getBoundsFromCRS(fti); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds); // if we use reproject policy, bounds should now be different fti.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED); crsBounds = cb.getBoundsFromCRS(fti); assertNotEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds); // should now be 4326 bounds CoordinateReferenceSystem crs4326 = CRS.decode("EPSG:4326"); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(crs4326)), crsBounds); fti.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(crs4326)), crsBounds); }
@Test public void getEnvelope2D() { ReferencedEnvelope refEnv = new ReferencedEnvelope(-10, 10, -5, 5, DefaultGeographicCRS.WGS84); Envelope2D env2D = JTS.getEnvelope2D(refEnv, refEnv.getCoordinateReferenceSystem()); CRS.equalsIgnoreMetadata( refEnv.getCoordinateReferenceSystem(), env2D.getCoordinateReferenceSystem()); assertTrue(env2D.boundsEquals(refEnv, 0, 1, TOL)); }
@Test public void testPolarStereographic() throws Exception { ReferencedEnvelope envelope = new ReferencedEnvelope( -10700000, 14700000, -10700000, 14700000, CRS.decode("EPSG:5041", true)); ProjectionHandler handler = ProjectionHandlerFinder.getHandler(envelope, WGS84, true); assertNotNull(handler); assertEquals(envelope, handler.getRenderingEnvelope()); assertTrue( CRS.getMapProjection(envelope.getCoordinateReferenceSystem()) instanceof PolarStereographic); }
@Override public void createIndividuals() { try { coverageCRS = CRS.decode(crsCode, true); } catch (Exception e) { LOG.error("error decoding coordinate reference system code.", e); return; } if (boundsFromGraph) { // autowire graph service or pass in } gridEnvelope = new GridEnvelope2D(0, 0, cols, rows); refEnvelope = new ReferencedEnvelope(left, right, bottom, top, coverageCRS); gridGeometry = new GridGeometry2D(gridEnvelope, refEnvelope); super.createIndividuals0(); }
/** 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()); }
@Test public void testBoundsEquals2D() { Rectangle2D bounds = new Rectangle2D.Double(-20.0, -20.0, 40.0, 40.0); ReferencedEnvelope env1 = new ReferencedEnvelope(bounds, null); ReferencedEnvelope env2 = new ReferencedEnvelope(bounds, null); double eps = 1.0e-4d; assertTrue(env1.boundsEquals2D(env2, eps)); bounds = new Rectangle2D.Double(-20.01, -20.01, 40.0, 40.0); env2 = new ReferencedEnvelope(bounds, null); assertFalse(env1.boundsEquals2D(env2, eps)); }
/** * 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 setBoundsWithAspectCorrection_1_2() { double h = WORLD_1_1.getHeight(); ReferencedEnvelope expected = new ReferencedEnvelope( WORLD_1_1.getMinX(), WORLD_1_1.getMaxX(), WORLD_1_1.getMinY() - h / 2, WORLD_1_1.getMaxY() + h / 2, WORLD_1_1.getCoordinateReferenceSystem()); assertAspectCorrection(SCREEN_1_2, expected); }
@Test public void testPolarTouchDateline() throws Exception { // we request a small area, oversampling, and the output has some white pixels in a corner CoordinateReferenceSystem crs = CRS.decode("EPSG:3031", true); // across the dateline, not including the pole ReferencedEnvelope mapExtent = new ReferencedEnvelope(-1250000, 0, -10000000, -8750000, crs); Rectangle screenSize = new Rectangle(256, 256); AffineTransform w2s = RendererUtilities.worldToScreenTransform(mapExtent, screenSize); GridCoverageRenderer renderer = new GridCoverageRenderer( mapExtent.getCoordinateReferenceSystem(), mapExtent, screenSize, w2s); RasterSymbolizer rasterSymbolizer = buildRainColorMap(); RenderedImage image = renderer.renderImage( rainReader, null, rasterSymbolizer, Interpolation.getInstance(Interpolation.INTERP_NEAREST), Color.RED, 256, 256); assertNotNull(image); File reference = new File( "src/test/resources/org/geotools/renderer/lite/gridcoverage2d/polar_touchdateline.png"); ImageAssert.assertEquals(reference, image, 0); }
CoordinateReferenceSystem crs = srs != null ? CRS.decode(srs) : null; baseMap.put("baseMapEnvelope", new ReferencedEnvelope(x1, x2, y1, y2, crs));
/** Check if this bounding box intersects the provided bounds. */ @Override public ReferencedEnvelope intersection(Envelope env) { if (env instanceof BoundingBox) { BoundingBox bbox = (BoundingBox) env; ensureCompatibleReferenceSystem(bbox); } return new ReferencedEnvelope(super.intersection(env), this.getCoordinateReferenceSystem()); }
@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))); }