Refine search
@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); }
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());
/** 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()); }
/** 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()); }
/** * 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(); }
public ProjectionHandler getHandler( ReferencedEnvelope renderingEnvelope, CoordinateReferenceSystem sourceCrs, boolean wrap, int maxWraps) throws FactoryException { if (renderingEnvelope == null) { return null; } MapProjection mapProjection = CRS.getMapProjection(renderingEnvelope.getCoordinateReferenceSystem()); if (mapProjection instanceof WorldVanDerGrintenI) { ReferencedEnvelope validArea = new ReferencedEnvelope( -Integer.MAX_VALUE, Integer.MAX_VALUE, -90, 90, DefaultGeographicCRS.WGS84); return new ProjectionHandler(sourceCrs, validArea, renderingEnvelope); } return null; } }
/** * Re-Projects the given envelope to destinationCRS using transformation. * * @param envelope * @param destinationCRS * @param transformation * @return * @throws Exception */ public static ReferencedEnvelope getProjectedEnvelope( ReferencedEnvelope envelope, CoordinateReferenceSystem destinationCRS, MathTransform transformation) throws TransformException, FactoryException { CoordinateReferenceSystem sourceCRS = envelope.getCoordinateReferenceSystem(); if (sourceCRS.equals(destinationCRS)) { // no need to reproject return envelope; } else { // Reproject envelope: first try JTS.transform, if that fails use // ReferencedEnvelope.transform try { return new ReferencedEnvelope( JTS.transform(envelope, transformation), destinationCRS); } catch (Exception exc) { return envelope.transform(destinationCRS, false); } } }
if (checkEditable("setCoordinateReferenceSystem")) { if (crs == null) { bounds = new ReferencedEnvelope(bounds, null); } else if (!CRS.equalsIgnoreMetadata(crs, bounds.getCoordinateReferenceSystem())) { if (bounds.isEmpty()) { bounds = new ReferencedEnvelope(crs);
/** * Returns an expanded rendering envelope if the buffering size is not using feature attributes. * If the buffering size is feature dependent the user will have to expand the rendering area * via the renderer buffer parameter */ public ReferencedEnvelope invert(ReferencedEnvelope renderingEnvelope) { Double buffer = getExpression(1).evaluate(null, Double.class); if (buffer == null || buffer <= 0.0) { return null; } Envelope bufferedEnvelope = JTS.toGeometry((Envelope) renderingEnvelope).buffer(buffer).getEnvelopeInternal(); return new ReferencedEnvelope( bufferedEnvelope, renderingEnvelope.getCoordinateReferenceSystem()); } }
extent = new ReferencedEnvelope(bounds); CoordinateReferenceSystem featuresCRS = featureBounds.getCoordinateReferenceSystem(); CoordinateReferenceSystem boundsCRS = extent.getCoordinateReferenceSystem();
@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()); }
/** * Transform the current area of interest for this context using the provided transform. This * may be useful for zooming and panning processes. Does nothing if no area of interest is set. * * @param transform The transform to change map viewport */ public void transform(AffineTransform transform) { ReferencedEnvelope oldBounds = getAreaOfInterest(); if (!(oldBounds == null || oldBounds.isEmpty())) { double[] coords = new double[4]; coords[0] = oldBounds.getMinX(); coords[1] = oldBounds.getMinY(); coords[2] = oldBounds.getMaxX(); coords[3] = oldBounds.getMaxY(); transform.transform(coords, 0, coords, 0, 2); ReferencedEnvelope newBounds = new ReferencedEnvelope( coords[0], coords[2], coords[1], coords[3], oldBounds.getCoordinateReferenceSystem()); setAreaOfInterest(newBounds); } }
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 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)); }
private ReferencedEnvelope reduceEnvelope( ReferencedEnvelope envelope, ProjectionHandler handler) throws TransformException, FactoryException { Polygon polygon = JTS.toGeometry(envelope); Geometry geom = handler.preProcess(polygon); if (geom == null) { return null; } PolygonExtractor pe = new PolygonExtractor(); Polygon largest = null; for (Polygon p : pe.getPolygons(geom)) { if (largest == null || largest.getArea() > p.getArea()) { largest = p; } } ReferencedEnvelope reduced = new ReferencedEnvelope( largest.getEnvelopeInternal(), envelope.getCoordinateReferenceSystem()); return reduced; }
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); }
@Before public void setUp() throws Exception { File property = new File(TestData.getResource(this, "tilerect.properties").toURI()); PropertyDataStore ds = new PropertyDataStore(property.getParentFile()); polyfs = ds.getFeatureSource("tilerect"); property = new File(TestData.getResource(this, "tilelines.properties").toURI()); ds = new PropertyDataStore(property.getParentFile()); linefs = ds.getFeatureSource("tilelines"); leftTileBounds = new ReferencedEnvelope( 0, 10, 0, 10, polyfs.getBounds().getCoordinateReferenceSystem()); rightTileBounds = new ReferencedEnvelope( 10, 20, 0, 10, polyfs.getBounds().getCoordinateReferenceSystem()); // load font Font f = Font.createFont( Font.TRUETYPE_FONT, TestData.getResource(this, "recreate.ttf").openStream()); FontCache.getDefaultInstance().registerFont(f); // System.setProperty("org.geotools.test.interactive", "true"); }
@Test public void testTransformToWGS84() throws Exception { String wkt = "GEOGCS[\"GDA94\"," + " DATUM[\"Geocentric Datum of Australia 1994\"," + " SPHEROID[\"GRS 1980\", 6378137.0, 298.257222101, AUTHORITY[\"EPSG\",\"7019\"]]," + " TOWGS84[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], " + " AUTHORITY[\"EPSG\",\"6283\"]], " + " PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]]," + " UNIT[\"degree\", 0.017453292519943295], " + " AXIS[\"Geodetic longitude\", EAST], " + " AXIS[\"Geodetic latitude\", NORTH], " + " AXIS[\"Ellipsoidal height\", UP], " + " AUTHORITY[\"EPSG\",\"4939\"]]"; CoordinateReferenceSystem gda94 = CRS.parseWKT(wkt); ReferencedEnvelope bounds = new ReferencedEnvelope( 130.875825803896, 130.898939990319, -16.4491956225999, -16.4338185791628, DefaultGeographicCRS.WGS84); ReferencedEnvelope worldBounds2D = bounds.transform(DefaultGeographicCRS.WGS84, true); assertEquals(DefaultGeographicCRS.WGS84, worldBounds2D.getCoordinateReferenceSystem()); ReferencedEnvelope worldBounds3D = bounds.transform(DefaultGeographicCRS.WGS84_3D, true); assertEquals(DefaultGeographicCRS.WGS84_3D, worldBounds3D.getCoordinateReferenceSystem()); ReferencedEnvelope gda94Bounds3D = bounds.transform(gda94, true); assertEquals(gda94, gda94Bounds3D.getCoordinateReferenceSystem()); }
@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); }
public void testSetsEnvelopeCrsFromQuery() throws Exception { Query query = new Query(Query.ALL); query.setCoordinateSystem(DefaultEngineeringCRS.CARTESIAN_2D); ReferencedEnvelope envelope = data.getFeatureSource("river").getBounds(query); assertEquals(DefaultEngineeringCRS.CARTESIAN_2D, envelope.getCoordinateReferenceSystem()); assertEquals( new ReferencedEnvelope(riverBounds, DefaultEngineeringCRS.CARTESIAN_2D), envelope); }