@Test public void testWgs84BoundsFromCompoundCRS() throws Exception { try { MapProjection.SKIP_SANITY_CHECKS = true; CatalogBuilder cb = new CatalogBuilder(getCatalog()); ReferencedEnvelope3D bounds = new ReferencedEnvelope3D( 142892, 470783, 16, 142900, 470790, 20, CRS.decode("EPSG:7415")); // used to throw an exception here ReferencedEnvelope latLonBounds = cb.getLatLonBounds(bounds, bounds.getCoordinateReferenceSystem()); assertTrue( CRS.equalsIgnoreMetadata( CRS.decode("EPSG:4326"), latLonBounds.getCoordinateReferenceSystem())); // System.out.println(latLonBounds); } finally { MapProjection.SKIP_SANITY_CHECKS = false; } }
/** Returns the specified bounding box as a JTS envelope. */ private static ReferencedEnvelope3D getJTSEnvelope(final BoundingBox3D bbox) { if (bbox == null) { throw new NullPointerException("Provided bbox envelope was null"); } if (bbox instanceof ReferencedEnvelope3D) { return (ReferencedEnvelope3D) bbox; } return new ReferencedEnvelope3D(bbox); }
/** * Factory method to create the correct ReferencedEnvelope. * * @param original ReferencedEnvelope being duplicated * @return ReferencedEnvelope, ReferencedEnvelope3D if it is 3d */ public static ReferencedEnvelope create(ReferencedEnvelope original) { if (original instanceof ReferencedEnvelope3D) { return new ReferencedEnvelope3D((ReferencedEnvelope3D) original); } return new ReferencedEnvelope(original); } /**
public BBOX3D bbox(Expression e, BoundingBox3D env, MatchAction matchAction) { PropertyName name = null; if (e instanceof PropertyName) { name = (PropertyName) e; } else { throw new IllegalArgumentException(); } return new BBOX3DImpl(name, new ReferencedEnvelope3D(env), this); }
/** * Factory method to create the correct ReferencedEnvelope implementation for the provided * CoordinateReferenceSystem. * * @param crs CoordinateReferenceSystem used to select ReferencedEnvelope implementation * @return ReferencedEnvelope, ReferencedEnvelope3D if it is 3d */ public static ReferencedEnvelope create(CoordinateReferenceSystem crs) { if (crs != null && crs.getCoordinateSystem().getDimension() > 2) { return new ReferencedEnvelope3D(crs); } return new ReferencedEnvelope(crs); }
public ReferencedEnvelope3D get3DEnvelope(Geometry geom) { Coordinate[] coordinates = geom.getCoordinates(); ReferencedEnvelope3D env = new ReferencedEnvelope3D(); for (Coordinate coordinate : coordinates) { env.expandToInclude(coordinate); } return env; }
/** * Utility method to create a ReferencedEnvelope from an opengis Envelope class, supporting 2d * as well as 3d envelopes (returning the right class). * * @param env The opgenis Envelope object * @return ReferencedEnvelope, ReferencedEnvelope3D if it is 3d,<br> * results in a null/an empty envelope, if input envelope was a null/an empty envelope * @see {@link #reference(org.opengis.geometry.Envelope)} */ public static ReferencedEnvelope create( org.opengis.geometry.Envelope env, CoordinateReferenceSystem crs) { if (env == null) { return null; } if (env.getDimension() >= 3) { // emptiness test is inside reference-method return new ReferencedEnvelope3D((ReferencedEnvelope3D) reference(env), crs); } return new ReferencedEnvelope(reference(env), crs); } /**
@Test public void testDistanceWhenMinZOfThisIsGreaterThanMaxZOfOther() { CoordinateReferenceSystem crs = DefaultEngineeringCRS.CARTESIAN_3D; ReferencedEnvelope3D a = new ReferencedEnvelope3D(2.0, 3.0, 2.0, 3.0, 2.0, 3.0, crs); ReferencedEnvelope3D b = new ReferencedEnvelope3D(0.0, 1.0, 0.0, 1.0, 0.0, 0.5, crs); assertEquals(Math.sqrt(1 * 1 + 1 * 1 + 1.5 * 1.5), a.distance(b), 0.00001); }
/** * Replacement for geometry.getEnvelopeInternal() that returns ReferencedEnvelope or * ReferencedEnvelope3D as appropriate for the provided CRS. * * @param geometry * @param crs * @return ReferencedEnvelope (or ReferencedEnvelope3D) as appropriate */ public static ReferencedEnvelope bounds(Geometry geometry, CoordinateReferenceSystem crs) { if (geometry == null) { return null; } if (crs == null) { return new ReferencedEnvelope(geometry.getEnvelopeInternal(), null); // CRS is not known } else if (crs.getCoordinateSystem().getDimension() >= 3) { ReferencedEnvelope bounds = new ReferencedEnvelope3D(crs); // Note we are visiting all coordinates (rather than just the outer rings // polygons) as holes may contribute to the min / max bounds. for (Coordinate coordinate : geometry.getCoordinates()) { bounds.expandToInclude(coordinate); } return bounds; } else { return new ReferencedEnvelope(geometry.getEnvelopeInternal(), crs); } }
@Test public void intersection() throws Exception { ReferencedEnvelope3D australia = new ReferencedEnvelope3D(DefaultGeographicCRS.WGS84_3D); australia.include(40, 110, 0); australia.include(10, 150, 10); ReferencedEnvelope3D newZealand = new ReferencedEnvelope3D(DefaultEngineeringCRS.CARTESIAN_3D); newZealand.include(50, 165, 0); newZealand.include(33, 180, 5); try { australia.intersection(newZealand); fail("Expected a mismatch of CoordinateReferenceSystem"); } catch (MismatchedReferenceSystemException t) { // expected } }
@Test public void include() throws Exception { ReferencedEnvelope3D australia = new ReferencedEnvelope3D(DefaultGeographicCRS.WGS84_3D); australia.include(40, 110, 0); australia.include(10, 150, 10); ReferencedEnvelope3D newZealand = new ReferencedEnvelope3D(DefaultEngineeringCRS.CARTESIAN_3D); newZealand.include(50, 165, 0); newZealand.include(33, 180, 5); try { australia.expandToInclude(newZealand); fail("Expected a mismatch of CoordinateReferenceSystem"); } catch (MismatchedReferenceSystemException t) { // expected } try { australia.include(newZealand); fail("Expected a mismatch of CoordinateReferenceSystem"); } catch (MismatchedReferenceSystemException t) { // expected } }
@Test public void empty() { // ensure empty can grab a default CRS when starting from nothing ReferencedEnvelope3D bbox = new ReferencedEnvelope3D(); // this is empty assertNull(bbox.getCoordinateReferenceSystem()); ReferencedEnvelope3D australia = new ReferencedEnvelope3D(DefaultGeographicCRS.WGS84_3D); australia.include(40, 110, 0); australia.include(10, 150, 10); bbox.include(australia); assertEquals(australia.getCoordinateReferenceSystem(), bbox.getCoordinateReferenceSystem()); assertEquals(0, bbox.getMinZ(), 0d); assertEquals(10, bbox.getMaxZ(), 0d); }
public void testBBOX3DOutsideLine() throws Exception { // a bbox 3d well outside the line footprint BBOX3D bbox3d = FF.bbox("", new ReferencedEnvelope3D(2, 3, 1, 2, 100, 101, crs)); SimpleFeatureCollection fc = dataStore.getFeatureSource(tname(getLine3d())).getFeatures(bbox3d); assertEquals(0, fc.size()); }
/** * Computes the intersection of two {@link Envelope}s. * * @param env the envelope to intersect with * @return a new Envelope representing the intersection of the envelopes (this will be the null * envelope if either argument is null, or they do not intersect */ public ReferencedEnvelope3D intersection(ReferencedEnvelope3D env) { ensureCompatibleReferenceSystem(env); if (isNull() || env.isNull() || !intersects(env)) return new ReferencedEnvelope3D(); double intMinX = getMinX() > env.getMinX() ? getMinX() : env.getMinX(); double intMinY = getMinY() > env.getMinY() ? getMinY() : env.getMinY(); double intMinZ = minz > env.minz ? minz : env.minz; double intMaxX = getMaxX() < env.getMaxX() ? getMaxX() : env.getMaxX(); double intMaxY = getMaxY() < env.getMaxY() ? getMaxY() : env.getMaxY(); double intMaxZ = maxz < env.maxz ? maxz : env.maxz; return new ReferencedEnvelope3D( intMinX, intMaxX, intMinY, intMaxY, intMinZ, intMaxZ, env.getCoordinateReferenceSystem()); }
@Test public void force3DCRS3DEnvelope() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:4939", true); CoordinateReferenceSystem hcrs = CRS.getHorizontalCRS(crs); BBOX bbox = ff.bbox( ff.property("the_geom"), new ReferencedEnvelope3D(-180, 180, -90, 90, 0, 100, null)); DefaultCRSFilterVisitor visitor = new DefaultCRSFilterVisitor(ff, crs); BBOX filtered = (BBOX) bbox.accept(visitor, null); Literal box = (Literal) filtered.getExpression2(); Geometry g = (Geometry) box.evaluate(null); assertEquals(crs, g.getUserData()); } }
@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 ReferencedEnvelope3D( 130.875825803896, 130.898939990319, -16.4491956225999, -16.4338185791628, 0.0, 0.0, gda94); ReferencedEnvelope worldBounds3D = bounds.transform(DefaultGeographicCRS.WGS84_3D, true); assertEquals(DefaultGeographicCRS.WGS84_3D, worldBounds3D.getCoordinateReferenceSystem()); ReferencedEnvelope worldBounds2D = bounds.transform(DefaultGeographicCRS.WGS84, true); assertEquals(DefaultGeographicCRS.WGS84, worldBounds2D.getCoordinateReferenceSystem()); }
null); BoundingBox3D envelope1 = new ReferencedEnvelope3D(0, 50, 0, 50, 0, 50, null); Filter bbox1 = ff.bbox(ff.property("geom"), envelope1); BoundingBox3D envelope2 = new ReferencedEnvelope3D(0, 50, 0, 50, 50, 100, null); Filter bbox2 = ff.bbox(ff.property("geom"), envelope2);
@Test public void testBBox3D() throws Exception { BBOX bbox = ff.bbox("location", new ReferencedEnvelope3D(0, 10, 20, 50, 60, 70, null)); assertTrue(bbox instanceof BBOX3DImpl); BBOX3DImpl bbox3d = (BBOX3DImpl) bbox; Filter unrolled = (Filter) bbox.accept(visitor, null); assertTrue(unrolled instanceof BBOX3DImpl); BBOX3DImpl unrolled3d = (BBOX3DImpl) unrolled; assertEquals(bbox3d.getMinX(), unrolled3d.getMinX(), 0.0); assertEquals(bbox3d.getMaxX(), unrolled3d.getMaxX(), 0.0); assertEquals(bbox3d.getMinY(), unrolled3d.getMinY(), 0.0); assertEquals(bbox3d.getMaxY(), unrolled3d.getMaxY(), 0.0); assertEquals(bbox3d.getMinZ(), unrolled3d.getMinZ(), 0.0); assertEquals(bbox3d.getMaxZ(), unrolled3d.getMaxZ(), 0.0); } }
public void testBBOX3DReadLine() throws Exception { BBOX3D bbox3d = FF.bbox("", new ReferencedEnvelope3D(2, 3, 1, 2, 0, 1, crs)); SimpleFeatureCollection fc = dataStore.getFeatureSource(tname(getLine3d())).getFeatures(bbox3d); try (SimpleFeatureIterator fr = fc.features()) { assertTrue(fr.hasNext()); LineString ls = (LineString) fr.next().getDefaultGeometry(); // 1 1 0, 2 2 0, 4 2 1, 5 1 1 assertEquals(4, ls.getCoordinates().length); assertTrue(new Coordinate(1, 1, 0).equals3D(ls.getCoordinateN(0))); assertTrue(new Coordinate(2, 2, 0).equals3D(ls.getCoordinateN(1))); assertTrue(new Coordinate(4, 2, 1).equals3D(ls.getCoordinateN(2))); assertTrue(new Coordinate(5, 1, 1).equals3D(ls.getCoordinateN(3))); } }
@Test public void testIntersectXYZ() { ReferencedEnvelope3D envelope = new ReferencedEnvelope3D();