/** Returns the coordinate system in use with the envelope. */ private CoordinateSystem getCoordinateSystem() { if (envelope != null) { final CoordinateReferenceSystem crs; crs = envelope.getCoordinateReferenceSystem(); if (crs != null) { return crs.getCoordinateSystem(); } } return null; }
public Primitive createPrimitive(Envelope envelope) throws MismatchedReferenceSystemException, MismatchedDimensionException { LineSegment segment = processBoundsToSegment(envelope); setCoordinateReferenceSystem(envelope.getCoordinateReferenceSystem()); return processSegmentToPrimitive(envelope, segment, 1); }
/** Sets BBOX and SRS using the provided Envelope. */ public void setBBox(Envelope envelope) { String version = properties.getProperty(VERSION); boolean forceXY = version == null || !version.startsWith("1.3"); String srsName = CRS.toSRS(envelope.getCoordinateReferenceSystem()); CoordinateReferenceSystem crs = toServerCRS(srsName, forceXY); Envelope bbox; try { bbox = CRS.transform(envelope, crs); } catch (TransformException e) { bbox = envelope; } StringBuffer sb = new StringBuffer(); sb.append(bbox.getMinimum(0)); sb.append(","); sb.append(bbox.getMinimum(1) + ","); sb.append(bbox.getMaximum(0) + ","); sb.append(bbox.getMaximum(1)); setBBox(sb.toString()); } /**
return new ReferencedEnvelope3D(env.getCoordinateReferenceSystem()); } else { return new ReferencedEnvelope3D(env); return new ReferencedEnvelope(env.getCoordinateReferenceSystem());
/** * Converts a {@link Envelope} into a {@link ReferencedEnvelope} * * @param envelope * @return */ ReferencedEnvelope reference(Envelope envelope) { ReferencedEnvelope env = new ReferencedEnvelope(envelope.getCoordinateReferenceSystem()); env.expandToInclude(envelope.getMinimum(0), envelope.getMinimum(1)); env.expandToInclude(envelope.getMaximum(0), envelope.getMaximum(1)); return env; }
/** * Converts a {@link Envelope} into a {@link ReferencedEnvelope} * * @param envelope * @return */ ReferencedEnvelope reference(Envelope envelope) { ReferencedEnvelope env = new ReferencedEnvelope(envelope.getCoordinateReferenceSystem()); env.expandToInclude(envelope.getMinimum(0), envelope.getMinimum(1)); env.expandToInclude(envelope.getMaximum(0), envelope.getMaximum(1)); return env; }
/** * Examines the map extent and tries to determine the number of digits that will be needed in * the display. If a coordinate reference system with valid extent defined, it is used to * determine coordinate limits; otherwise the extent of the envelope is used directly. If all * else fails, a default number of digits is set. * * @param env the map extent (may be {@code null}) */ private void setIntegerLen(Envelope env) { int len = -1; if (env != null) { // Try to get a valid extent for the CRS and use this to // determine num coordinate digits CoordinateReferenceSystem crs = env.getCoordinateReferenceSystem(); if (crs != null) { Envelope validExtent = CRS.getEnvelope(crs); if (validExtent != null) { len = getMaxIntegerLen(validExtent); } } if (len < 0) { // Use map extent directly len = getMaxIntegerLen(env); } } else { // Nothing to go on: use an arbitrary length len = DEFAULT_NUM_INTEGER_DIGITS; } intLen = len; }
/** * Resamples a grid coverage to the specified envelope. * * @param source The source coverage. * @param envelope The target envelope, including a possibly different coordinate reference * system. * @param interpolationType The interpolation type, or {@code null} for the default one. * @throws CoverageProcessingException if the operation can't be applied. * @see org.geotools.coverage.processing.operation.Resample * @see org.geotools.coverage.processing.operation.Resample#computeGridGeometry * @since 2.5 */ public Coverage resample( final GridCoverage source, final Envelope envelope, final Interpolation interpolationType) throws CoverageProcessingException { final GridGeometry gridGeometry; try { gridGeometry = Resample.computeGridGeometry(source, envelope); } catch (TransformException exception) { throw new CoverageProcessingException(exception); } return doOperation( "Resample", source, "CoordinateReferenceSystem", envelope.getCoordinateReferenceSystem(), "GridGeometry", gridGeometry, "InterpolationType", interpolationType); }
public CRSEnvelope(Envelope envelope) { this.srsName = CRS.toSRS(envelope.getCoordinateReferenceSystem()); // this.srsName = epsgCode; this.minX = envelope.getMinimum(0); this.maxX = envelope.getMaximum(0); this.minY = envelope.getMinimum(1); this.maxY = envelope.getMaximum(1); }
/** * Sets this envelope to the intersection if this envelope with the specified one. * * <p>This method assumes that the specified envelope uses the same CRS than this envelope. For * performance reason, it will no be verified unless J2SE assertions are enabled. * * @param envelope the {@code Envelope} to intersect to this envelope. * @throws MismatchedDimensionException if the specified envelope doesn't have the expected * dimension. */ public void intersect(final Envelope envelope) throws MismatchedDimensionException { ensureNonNull("envelope", envelope); final int dim = ordinates.length / 2; AbstractDirectPosition.ensureDimensionMatch("envelope", envelope.getDimension(), dim); assert equalsIgnoreMetadata(crs, envelope.getCoordinateReferenceSystem()) : envelope; for (int i = 0; i < dim; i++) { double min = Math.max(ordinates[i], envelope.getMinimum(i)); double max = Math.min(ordinates[i + dim], envelope.getMaximum(i)); if (min > max) { // Make an empty envelope (min==max) // while keeping it legal (min<=max). min = max = 0.5 * (min + max); } ordinates[i] = min; ordinates[i + dim] = max; } }
/** * Creates a new envelope from an existing OGC envelope. * * <p>NOTE: if the envelope is empty, the resulting ReferencedEnvelope will not be. In case this * is needed use {@link #create(org.opengis.geometry.Envelope, CoordinateReferenceSystem) * ReferencedEnvelope.create(envelope, envelope.getCoordinateReferenceSystem())} * * @param envelope The envelope to initialize from. * @throws MismatchedDimensionException if the CRS dimension is not valid. * @since 2.4 */ public ReferencedEnvelope(final org.opengis.geometry.Envelope envelope) throws MismatchedDimensionException { super( envelope.getMinimum(0), envelope.getMaximum(0), envelope.getMinimum(1), envelope.getMaximum(1)); this.crs = envelope.getCoordinateReferenceSystem(); checkCoordinateReferenceSystemDimension(); }
this.getCoordinateReferenceSystem(), that.getCoordinateReferenceSystem())) { assert hashCode() == that.hashCode() : this; return true;
/** * Constructs a new envelope with the same data than the specified envelope. * * @param envelope The envelope to copy. */ public GeneralEnvelope(final Envelope envelope) { ensureNonNull("envelope", envelope); if (envelope instanceof GeneralEnvelope) { final GeneralEnvelope e = (GeneralEnvelope) envelope; ordinates = e.ordinates.clone(); crs = e.crs; } else { crs = envelope.getCoordinateReferenceSystem(); final int dimension = envelope.getDimension(); ordinates = new double[2 * dimension]; for (int i = 0; i < dimension; i++) { ordinates[i] = envelope.getMinimum(i); ordinates[i + dimension] = envelope.getMaximum(i); } checkCoordinates(ordinates); } }
/** * Helper method for {@linkplain #setDisplayArea} which is also called by other methods that * want to set the display area without provoking repainting of the display * * @param envelope requested display area */ protected void doSetDisplayArea(Envelope envelope) { if (mapContent != null) { CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem(); if (crs == null) { // assume that it is the current CRS crs = mapContent.getCoordinateReferenceSystem(); } ReferencedEnvelope refEnv = new ReferencedEnvelope( envelope.getMinimum(0), envelope.getMaximum(0), envelope.getMinimum(1), envelope.getMaximum(1), crs); mapContent.getViewport().setBounds(refEnv); } else { pendingDisplayArea = new ReferencedEnvelope(envelope); } // Publish the resulting display area with the event publishEvent( new MapPaneEvent(this, MapPaneEvent.Type.DISPLAY_AREA_CHANGED, getDisplayArea())); }
/** * Constructs two-dimensional envelope defined by an other {@link Envelope}. * * @param envelope The envelope to copy. */ public Envelope2D(final Envelope envelope) { super( envelope.getMinimum(0), envelope.getMinimum(1), envelope.getSpan(0), envelope.getSpan(1)); // TODO: check below should be first, if only Sun could fix RFE #4093999. final int dimension = envelope.getDimension(); if (dimension != 2) { throw new MismatchedDimensionException( Errors.format(ErrorKeys.NOT_TWO_DIMENSIONAL_$1, dimension)); } setCoordinateReferenceSystem(envelope.getCoordinateReferenceSystem()); }
/** * Creates a new envelope from an existing OGC envelope. * * <p>NOTE: if the envelope is empty, the resulting ReferencedEnvelope will not be. In case this * is needed use {@link #create(org.opengis.geometry.Envelope, CoordinateReferenceSystem) * ReferencedEnvelope.create(envelope, envelope.getCoordinateReferenceSystem())} * * @param envelope The envelope to initialize from. * @throws MismatchedDimensionException if the CRS dimension is not valid. */ public ReferencedEnvelope3D(final org.opengis.geometry.Envelope envelope) throws MismatchedDimensionException { init( envelope.getMinimum(0), envelope.getMaximum(0), envelope.getMinimum(1), envelope.getMaximum(1), envelope.getMinimum(2), envelope.getMaximum(2)); this.crs = envelope.getCoordinateReferenceSystem(); checkCoordinateReferenceSystemDimension(); }
/** * Adds an envelope object to this envelope. The resulting envelope is the union of the two * {@code Envelope} objects. * * <p>This method assumes that the specified envelope uses the same CRS than this envelope. For * performance reason, it will no be verified unless J2SE assertions are enabled. * * @param envelope the {@code Envelope} to add to this envelope. * @throws MismatchedDimensionException if the specified envelope doesn't have the expected * dimension. */ public void add(final Envelope envelope) throws MismatchedDimensionException { ensureNonNull("envelope", envelope); final int dim = ordinates.length / 2; AbstractDirectPosition.ensureDimensionMatch("envelope", envelope.getDimension(), dim); assert equalsIgnoreMetadata(crs, envelope.getCoordinateReferenceSystem()) : envelope; for (int i = 0; i < dim; i++) { final double min = envelope.getMinimum(i); final double max = envelope.getMaximum(i); if (min < ordinates[i]) ordinates[i] = min; if (max > ordinates[i + dim]) ordinates[i + dim] = max; } assert isEmpty() || contains(envelope, true); }
private LineSegment processBoundsToSegment(Envelope bounds) { final int D = 0; CoordinateReferenceSystem crs = bounds.getCoordinateReferenceSystem(); CoordinateSystemAxis axis = crs.getCoordinateSystem().getAxis(D); DirectPosition positionA = getPositionFactory().createDirectPosition(null); DirectPosition positionB = getPositionFactory().createDirectPosition(null); if (axis.getDirection() != AxisDirection.OTHER) { positionA.setOrdinate(D, bounds.getMinimum(D)); positionB.setOrdinate(D, bounds.getMaximum(D)); } return getGeometryFactory().createLineSegment(positionA, positionB); }
/** * Tests the transformations of an envelope when the two CRS have identify transforms but * different datum names */ @Test public void testEnvelopeTransformation2() throws FactoryException, TransformException { final CoordinateReferenceSystem WGS84Altered = CRS.parseWKT(WKT.WGS84_ALTERED); final CoordinateReferenceSystem WGS84 = DefaultGeographicCRS.WGS84; final MathTransform crsTransform = CRS.findMathTransform(WGS84, WGS84Altered, true); assertTrue(crsTransform.isIdentity()); final GeneralEnvelope firstEnvelope; firstEnvelope = new GeneralEnvelope(new double[] {-124, 42}, new double[] {-122, 43}); firstEnvelope.setCoordinateReferenceSystem(WGS84); // this triggered a assertion error in GEOT-2934 Envelope transformed = CRS.transform(firstEnvelope, WGS84Altered); // check the envelope is what we expect assertEquals(transformed.getCoordinateReferenceSystem(), WGS84Altered); double EPS = 1e-9; assertEquals(transformed.getMinimum(0), firstEnvelope.getMinimum(0), EPS); assertEquals(transformed.getMinimum(1), firstEnvelope.getMinimum(1), EPS); assertEquals(transformed.getMaximum(0), firstEnvelope.getMaximum(0), EPS); assertEquals(transformed.getMaximum(1), firstEnvelope.getMaximum(1), EPS); }
@Test public void testMBTilesMetaData() throws Exception { try (MBTilesFile file = new MBTilesFile(dbfile); ) { MBTilesMetadata metadata2 = file.loadMetaData(); assertEquals("osm2vectortiles", metadata2.getName()); assertEquals("Extract from http://osm2vectortiles.org", metadata2.getDescription()); assertEquals("2.0", metadata2.getVersion()); metadata2.getBounds().getLowerCorner().getCoordinate(); double delta = 0.0001; assertEquals(-180.0, metadata2.getBounds().getLowerCorner().getOrdinate(0), delta); assertEquals(180.0, metadata2.getBounds().getUpperCorner().getOrdinate(0), delta); assertEquals(-85.0511, metadata2.getBounds().getLowerCorner().getOrdinate(1), delta); assertEquals(85.0511, metadata2.getBounds().getUpperCorner().getOrdinate(1), delta); assertEquals( CRS.decode("EPSG:4326", true), metadata2.getBounds().getCoordinateReferenceSystem()); assertEquals(t_format.PBF, metadata2.getFormat()); assertEquals(t_type.BASE_LAYER, metadata2.getType()); assertEquals(0, metadata2.getMinZoom()); assertEquals(5, metadata2.getMaxZoom()); } }