/** * Creates an envelope for the given CRS and coordinate values. */ @Override GeneralEnvelope createFromExtremums(CoordinateReferenceSystem crs, double xmin, double ymin, double xmax, double ymax) { final GeneralEnvelope env = new GeneralEnvelope(crs); env.setRange(0, xmin, xmax); env.setRange(1, ymin, ymax); return env; }
switch (type) { case GENERAL: { final GeneralEnvelope ge = new GeneralEnvelope(2); ge.setCoordinateReferenceSystem(WGS84); ge.setRange(0, xmin, xmax); ge.setRange(1, ymin, ymax); envelope = ge; break; GeneralEnvelope ge = new GeneralEnvelope(5); ge.setRange(1, xmin, xmax); ge.setRange(2, ymin, ymax); ge.setRange(0, 2, 3); // Following values will be verified in verifyInvariants(…) ge.setRange(3, 4, 6); ge.setRange(4, 8, 9); ge = ge.subEnvelope(1, 3); ge.setCoordinateReferenceSystem(WGS84); envelope = ge; break;
for (final GeographicExtent ge : extent.getGeographicElements()) { if (ge instanceof GeographicBoundingBox) { final GeneralEnvelope env = new GeneralEnvelope((GeographicBoundingBox) ge); if (bounds == null) { bounds = env; } else { bounds.add(env);
/** * Computes the envelope with the given coordinate reference system. This method is invoked from constructors. * The {@link #extent}, {@link #gridToCRS} and {@link #cornerToCRS} fields must be set before this method is invoked. * * @param specified the transform specified by the user. This is not necessarily {@link #gridToCRS}. * @param crs the coordinate reference system to declare in the envelope. * @param limits if non-null, intersect with that envelope. The CRS must be the same than {@code crs}. */ private ImmutableEnvelope computeEnvelope(final MathTransform specified, final CoordinateReferenceSystem crs, final Envelope limits) throws TransformException { final GeneralEnvelope env; if (extent != null && cornerToCRS != null) { env = extent.toCRS(cornerToCRS, specified); env.setCoordinateReferenceSystem(crs); if (limits != null) { env.intersect(limits); } } else if (crs != null) { env = new GeneralEnvelope(crs); env.setToNaN(); } else { return null; } return new ImmutableEnvelope(env); }
final Envelope penv1 = Envelopes.transform(env1, crs); final Envelope penv2 = Envelopes.transform(env2, crs); return GeneralEnvelope.castOrCopy(penv1).intersects(penv2); } catch(Exception ex) {/*do nothing*/} try { final Envelope penv2 = Envelopes.transform(env2, crs1); if (GeneralEnvelope.castOrCopy(penv2).isEmpty()) break cas1; return GeneralEnvelope.castOrCopy(env1).intersects(penv2); } catch(Exception ex) {/*do nothing*/} try { final Envelope penv1 = Envelopes.transform(env1, crs2); if (GeneralEnvelope.castOrCopy(penv1).isEmpty()) break cas2; return GeneralEnvelope.castOrCopy(penv1).intersects(env2); } catch(Exception ex) {/*do nothing*/}
final GeneralEnvelope transformed = new GeneralEnvelope(envelope); transformed.setCoordinateReferenceSystem(null); if (targetPt != null) { for (int i=envelope.getDimension(); --i>=0;) { targetPt[i] = transformed.getMedian(i); transformed = new GeneralEnvelope(targetDim); for (int i=0; i<targetDim; i++) { final double value = ordinates[offset + i]; transformed.setRange(i, value, value); transformed.add(ordinatesView); if (x > xmin && x < xmax) { final double y = isP2 ? extremum.ey2 : extremum.ey1; if (y < transformed.getMinimum(j) || y > transformed.getMaximum(j)) transformed.add(temporary);
final GeneralEnvelope e1 = new GeneralEnvelope(4); assertTrue (e1.isEmpty()); assertFalse (e1.isAllNaN()); assertEquals(e1.getLowerCorner(), e1.getUpperCorner()); for (int i=e1.getDimension(); --i>=0;) { e1.setRange(i, i*5 + 2, i*6 + 5); assertFalse(e1.isAllNaN ()); assertFalse(e1.isEmpty()); assertFalse(e1.getLowerCorner().equals(e1.getUpperCorner())); final GeneralEnvelope e2 = new GeneralEnvelope(e1); assertPositionEquals(e1.getLowerCorner(), e2.getLowerCorner()); assertPositionEquals(e1.getUpperCorner(), e2.getUpperCorner()); assertTrue (e1.contains(e2, true )); assertFalse (e1.contains(e2, false)); assertNotSame(e1, e2); assertEquals (e1, e2); assertTrue (e1.equals(e2, EPS, true )); assertTrue (e1.equals(e2, EPS, false)); assertEquals (e1.hashCode(), e2.hashCode()); e2.setRange(2, e2.getLower(2) + 3E-5, e2.getUpper(2) - 3E-5); assertTrue (e1.contains(e2, true )); assertFalse(e1.contains(e2, false)); assertFalse(e1.equals (e2)); assertTrue (e1.equals (e2, EPS, true )); assertTrue (e1.equals (e2, EPS, false));
/** * Implementation of {@link #testAxisRangeChange3D()} and {@link #testAxisRangeChangeWithDatumShift()}. */ private void testAxisRangeChange3D(final GeographicCRS targetCRS) throws FactoryException, TransformException { final GeneralEnvelope envelope = new GeneralEnvelope(new double[] { -0.5, -90, 1000}, new double[] {354.5, +90, 1002}); envelope.setCoordinateReferenceSystem(CRS.compound( HardCodedCRS.WGS84.forConvention(AxesConvention.POSITIVE_RANGE), HardCodedCRS.TIME)); final GeneralEnvelope expected = createFromExtremums(targetCRS, -0.5, -90, -5.5, 90); assertEnvelopeEquals(expected, Envelopes.transform(envelope, targetCRS), STRICT, STRICT); /* * When the envelope to transform span the full longitude range, * target envelope should unconditionally be [-180 … +180]°. */ envelope.setRange(0, -0.5, 359.5); expected.setRange(0, -180, 180); assertEnvelopeEquals(expected, Envelopes.transform(envelope, targetCRS), STRICT, STRICT); }
final GeneralEnvelope expanded = new GeneralEnvelope(3); expanded.subEnvelope(0, 2).setEnvelope(srcEnvelope); expanded.setRange(2, 1000, 2000); matrix = Matrices.createTransform(expanded, dstEnvelope); assertEquals("numRow", 3, matrix.getNumRow()); expanded.subEnvelope(0, 2).setEnvelope(dstEnvelope); matrix = Matrices.createTransform(srcEnvelope, expanded); assertEquals("numRow", 4, matrix.getNumRow());
GeneralEnvelope envelope = new GeneralEnvelope(dimension); for (int i=0; i<dimension; i++) { envelope.setRange(i, coordinates[i], coordinates[i + dimension] + 1.0); if (envelope.isEmpty()) try { for (int j=0; j<targets.length; j++) { final int tgtDim = targets[j]; double lower = envelope.getLower(tgtDim); double upper = envelope.getUpper(tgtDim); final double value = component.getElement(j, component.getNumCol() - 1); lower = value; envelope.setRange(tgtDim, lower, upper);
/** * Creates a new sub-envelope envelope for the given ordinate values. */ @Override GeneralEnvelope create(final double xmin, final double ymin, final double xmax, final double ymax) { final GeneralEnvelope envelope = new GeneralEnvelope(5); envelope.setEnvelope(1, 4, xmin, ymin, 5, 2, 7, xmax, ymax, 9); if (!skipValidation) { validate(envelope); } final GeneralEnvelope sub = envelope.subEnvelope(2, 4); sub.setCoordinateReferenceSystem(WGS84); if (!skipValidation) { validate(sub); } return sub; }
ArgumentChecks.ensureNonNull("destination envelope", destination); final CoordinateReferenceSystem sourceCRS = source.getCoordinateReferenceSystem(); final CoordinateReferenceSystem destCRS = destination.getCoordinateReferenceSystem(); destination = new GeneralEnvelope(source); final GeneralEnvelope srcSubEnvelope = source.subEnvelope(srcLowerAxis, srcLowerAxis + srcAxisCount); destination.subEnvelope(destLowerAxis, destLowerAxis+ srcSubEnvelope.getDimension()).setEnvelope(srcSubEnvelope); usedCRS.add(destCurrent); continue browseSource; final GeneralEnvelope srcSubEnvelope = source.subEnvelope(srcLowerAxis, srcLowerAxis + srcAxisCount); srcSubEnvelope.setCoordinateReferenceSystem(srcCurrent); try { final Envelope tmp = Envelopes.transform(srcSubEnvelope, destCurrent); destination.subEnvelope(destLowerAxis, destLowerAxis + tmp.getDimension()).setEnvelope(tmp); } catch (TransformException e) {
if (sourceCRS == null) { envelope = new GeneralEnvelope(envelope); ((GeneralEnvelope) envelope).setCoordinateReferenceSystem(targetCRS); } else { final CoordinateOperation operation;
/** * If the given object is a JTS geometry and its envelope is non-empty, returns * that envelope as an Apache SIS implementation. Otherwise returns {@code null}. * * @param geometry the geometry from which to get the envelope, or {@code null}. * @return the envelope of the given object, or {@code null} if the object is not * a recognized geometry or its envelope is empty. */ @Override final GeneralEnvelope tryGetEnvelope(final Object geometry) { if (geometry instanceof Geometry) { final Envelope bounds = ((Geometry) geometry).getEnvelopeInternal(); final GeneralEnvelope env = new GeneralEnvelope(2); env.setRange(0, bounds.getMinX(), bounds.getMaxX()); env.setRange(1, bounds.getMinY(), bounds.getMaxY()); if (!env.isEmpty()) { return env; } } return null; }
final GeographicCRS sourceCRS = ReferencingUtilities.toNormalizedGeographicCRS(targetCRS); if (sourceCRS != null) { envelope = merged = new GeneralEnvelope(bounds); merged.translate(-getGreenwichLongitude(sourceCRS), 0); merged.setCoordinateReferenceSystem(sourceCRS); try { envelope = Envelopes.transform(envelope, targetCRS);
HardCodedCRS.TIME); final GeneralEnvelope env = new GeneralEnvelope(sourceCRS); env.setRange(0, -170, 170); env.setRange(1, -80, 80); env.setRange(2, -50, -50); env.setRange(3, Double.NaN, Double.NaN); assertFalse("isAllNaN", env.isAllNaN()); // Opportunist test (not really the topic of this method). assertTrue ("isEmpty", env.isEmpty()); // Opportunist test (not really the topic of this method).
/** * Returns the given envelope as an {@code AbstractEnvelope} instance. * If the given envelope is already an instance of {@code AbstractEnvelope}, * then it is returned unchanged. Otherwise the coordinate values and the CRS * of the given envelope are copied in a new envelope. * * @param envelope the envelope to cast, or {@code null}. * @return the values of the given envelope as an {@code AbstractEnvelope} instance. * * @see GeneralEnvelope#castOrCopy(Envelope) * @see ImmutableEnvelope#castOrCopy(Envelope) */ public static AbstractEnvelope castOrCopy(final Envelope envelope) { if (envelope == null || envelope instanceof AbstractEnvelope) { return (AbstractEnvelope) envelope; } return new GeneralEnvelope(envelope); }
public void testSetCoordinateReferenceSystem() { final GeneralEnvelope e = create(2, -4, 3, -3); e.setCoordinateReferenceSystem(null); e.setRange(1, -10, -20); try { e.setCoordinateReferenceSystem(WGS84); fail("Invalid range shall not be allowed."); } catch (IllegalStateException ex) { assertEquals( 2, e.getLower(0), STRICT); assertEquals(-10, e.getLower(1), STRICT); assertEquals( 3, e.getUpper(0), STRICT); assertEquals(-20, e.getUpper(1), STRICT); e.setRange(1, -20, -10); e.setCoordinateReferenceSystem(WGS84); assertEnvelopeEquals(e, 2, -20, 3, -10); verifyInvariants(e);
@SuppressWarnings("ResultOfObjectAllocationIgnored") public void testWktParsing() { GeneralEnvelope envelope = new GeneralEnvelope("BOX(-180 -90,180 90)"); assertEquals(2, envelope.getDimension()); assertEquals(-180, envelope.getLower(0), STRICT); assertEquals( 180, envelope.getUpper(0), STRICT); assertEquals( -90, envelope.getLower(1), STRICT); assertEquals( 90, envelope.getUpper(1), STRICT); validate(envelope); envelope = new GeneralEnvelope("BOX3D(-180 -90 10, 180 90 30)"); assertEquals(3, envelope.getDimension()); assertEquals(-180, envelope.getLower(0), STRICT); assertEquals( 180, envelope.getUpper(0), STRICT); assertEquals( -90, envelope.getLower(1), STRICT); assertEquals( 90, envelope.getUpper(1), STRICT); assertEquals( 10, envelope.getLower(2), STRICT); assertEquals( 30, envelope.getUpper(2), STRICT); validate(envelope); envelope = new GeneralEnvelope("POLYGON((-80 -30,-100 40,80 40,100 -40,-80 -30))"); assertEquals(-100, envelope.getLower(0), STRICT); assertEquals( 100, envelope.getUpper(0), STRICT); assertEquals( -40, envelope.getLower(1), STRICT); assertEquals( 40, envelope.getUpper(1), STRICT); validate(envelope); assertEquals("BOX(6 10, 6 10)", new GeneralEnvelope("POINT(6 10)").toString()); assertEquals("BOX3D(6 10 3, 6 10 3)", new GeneralEnvelope("POINT M [ 6 10 3 ] ").toString());
/** * Tests the {@link GeneralEnvelope#toString()} method. */ @Test public void testToString() { GeneralEnvelope envelope = new GeneralEnvelope(new double[] {-180, -90}, new double[] {180, 90}); assertEquals("BOX(-180 -90, 180 90)", envelope.toString()); envelope = new GeneralEnvelope(3); envelope.setRange(0, -180, +180); envelope.setRange(1, -90, +90); envelope.setRange(2, 10, 30); assertEquals("BOX3D(-180 -90 10, 180 90 30)", envelope.toString()); }