/** * A coordinate position consisting of all the minimal ordinates for each dimension for all * points within the {@code Envelope}. * * @return The lower corner. * @todo Change the return type to {@link DirectPosition2D} when we will be allowed to compile * for J2SE 1.5. */ public DirectPosition getLowerCorner() { return new DirectPosition2D(crs, getMinX(), getMinY()); }
/** * Returns the minimal ordinate along the specified dimension. * * @param dimension The dimension to query. * @return The minimal ordinate value along the given dimension. * @throws IndexOutOfBoundsException If the given index is out of bounds. */ public final double getMinimum(final int dimension) throws IndexOutOfBoundsException { switch (dimension) { case 0: return getMinX(); case 1: return getMinY(); default: throw indexOutOfBounds(dimension); } }
/** * Used as a separate test from {@link #isEmpty()} so that we can detect when an envelope has * never been used. * * @return true if envelope has just been constructed */ private boolean isNull() { return (getMinX() == 0 && getMinY() == 0 && getWidth() < 0 && getHeight() < 0); } }
public void include(double x, double y) { if (isNull()) { this.x = x; this.y = y; this.width = 0; this.height = 0; } else { if (x < getMinX()) { this.width = width + (getMinX() - x); this.x = x; } if (x > getMaxX()) { this.width = width + (x - getMaxX()); } if (y < getMinY()) { this.height = height + (getMinY() - y); this.y = y; } if (y > getMaxY()) { this.height = height + (y - getMaxY()); } } }
public void test() throws Exception { p.setLocation(circumscribed.getMaxX(), circumscribed.getMinY()); sphericalGeosToGeog.transform(p, p); } });
public void test() throws Exception { p.setLocation(circumscribed.getCenterX(), circumscribed.getMinY() - tickle); ellipsoidalGeosToGeog.transform(p, p); } });
public void test() throws Exception { p.setLocation(circumscribed.getMinX(), circumscribed.getMinY()); ellipsoidalGeosToGeog.transform(p, p); } });
public void test() throws Exception { p.setLocation(circumscribed.getCenterX(), circumscribed.getMinY() - tickle); sphericalGeosToGeog.transform(p, p); } });
public void test() throws Exception { p.setLocation(circumscribed.getMinX(), circumscribed.getMinY()); sphericalGeosToGeog.transform(p, p); } });
public void test() throws Exception { p.setLocation(circumscribed.getMaxX(), circumscribed.getMinY()); ellipsoidalGeosToGeog.transform(p, p); } });
/** * Creates a new instance of {@link JGrassRegion} from an {@link Envelope2D} . * * @param envelope2D the envelope2D from which to take the setting from. */ public JGrassRegion(Envelope2D envelope2D) { west = envelope2D.getMinX(); east = envelope2D.getMaxX(); south = envelope2D.getMinY(); north = envelope2D.getMaxY(); we_res = envelope2D.getHeight(); ns_res = envelope2D.getWidth(); fixRowsAndCols(); fixResolution(); }
public boolean contains(DirectPosition location) { ensureCompatibleReferenceSystem(location); if (isEmpty()) { return false; } return location.getOrdinate(0) >= getMinX() && location.getOrdinate(0) <= getMaxX() && location.getOrdinate(1) >= getMinY() && location.getOrdinate(1) <= getMaxY(); }
result.setEnvelope( envelope.getMinX() + step, envelope.getMinY() + step, envelope.getMaxX() - step, envelope.getMaxY() - step);
public boolean contains(BoundingBox bounds) { ensureCompatibleReferenceSystem(bounds); if (isEmpty() || bounds.isEmpty()) { return false; } return bounds.getMinX() >= this.getMinX() && bounds.getMaxX() <= this.getMaxX() && bounds.getMinY() >= this.getMinY() && bounds.getMaxY() <= this.getMaxY(); }
public static JGrassRegion getJGrassRegionFromGridCoverage(GridCoverage2D gridCoverage2D) throws InvalidGridGeometryException, TransformException { Envelope2D env = gridCoverage2D.getEnvelope2D(); GridEnvelope2D worldToGrid = gridCoverage2D.getGridGeometry().worldToGrid(env); double xRes = env.getWidth() / worldToGrid.getWidth(); double yRes = env.getHeight() / worldToGrid.getHeight(); JGrassRegion region = new JGrassRegion( env.getMinX(), env.getMaxX(), env.getMinY(), env.getMaxY(), xRes, yRes); return region; }
/** * Returns {@code true} if the interior of this bounds intersects the interior of the provided * bounds. * * <p>Note this method conflicts with {@link Rectangle2D#intersects(Rectangle2D)} so you may * need to call it via envelope2d.intersects( (Envelope2D) bounds ) in order to correctly check * that the coordinate reference systems match. * * @param bounds The bounds to test for intersection. * @return {@code true} if the two bounds intersect. */ public boolean intersects(BoundingBox bounds) { ensureCompatibleReferenceSystem(bounds); if (isNull() || bounds.isEmpty()) { return false; } return !(bounds.getMinX() > this.getMaxX() || bounds.getMaxX() < this.getMinX() || bounds.getMinY() > this.getMaxY() || bounds.getMaxY() < this.getMinY()); }
static GridCoverage2D displace( GridCoverage2D coverage, double tx, double ty, GridCoverageFactory gridCoverageFactory) { // let's compute the new grid geometry GridGeometry2D originalGG = coverage.getGridGeometry(); GridEnvelope gridRange = originalGG.getGridRange(); Envelope2D envelope = originalGG.getEnvelope2D(); double minx = envelope.getMinX() + tx; double miny = envelope.getMinY() + ty; double maxx = envelope.getMaxX() + tx; double maxy = envelope.getMaxY() + ty; ReferencedEnvelope translatedEnvelope = new ReferencedEnvelope( minx, maxx, miny, maxy, envelope.getCoordinateReferenceSystem()); GridGeometry2D translatedGG = new GridGeometry2D(gridRange, translatedEnvelope); GridCoverage2D translatedCoverage = gridCoverageFactory.create( coverage.getName(), coverage.getRenderedImage(), translatedGG, coverage.getSampleDimensions(), new GridCoverage2D[] {coverage}, coverage.getProperties()); return translatedCoverage; }
public void include(BoundingBox bounds) { if (crs == null) { this.crs = bounds.getCoordinateReferenceSystem(); } else { ensureCompatibleReferenceSystem(bounds); } if (bounds.isEmpty()) { return; } if (isNull()) { setBounds(bounds); } else { if (bounds.getMinX() < getMinX()) { this.width = width + (getMinX() - bounds.getMinX()); this.x = bounds.getMinX(); } if (bounds.getMaxX() > getMaxX()) { this.width = width + (bounds.getMaxX() - getMaxX()); } if (bounds.getMinY() < getMinY()) { this.height = height + (getMinY() - bounds.getMinY()); this.y = bounds.getMinY(); } if (bounds.getMaxY() > getMaxY()) { this.height = height + (bounds.getMaxY() - getMaxY()); } } }
/** * Writes the {@link GridCoverage2D supplied coverage} to disk. * * <p>Note that this also takes care to cloes the file handle after writing to disk. * * @param gridCoverage2D the coverage to write. * @throws IOException */ public void writeRaster(GridCoverage2D gridCoverage2D) throws IOException { try { Envelope2D env = gridCoverage2D.getEnvelope2D(); GridEnvelope2D worldToGrid = gridCoverage2D.getGridGeometry().worldToGrid(env); double xRes = env.getWidth() / worldToGrid.getWidth(); double yRes = env.getHeight() / worldToGrid.getHeight(); JGrassRegion region = new JGrassRegion( env.getMinX(), env.getMaxX(), env.getMinY(), env.getMaxY(), xRes, yRes); GrassBinaryImageWriterSpi writerSpi = new GrassBinaryImageWriterSpi(); GrassBinaryImageWriter writer = new GrassBinaryImageWriter(writerSpi, monitor); RenderedImage renderedImage = gridCoverage2D.getRenderedImage(); writer.setOutput(output, region); writer.write(renderedImage); writer.dispose(); } catch (Exception e) { java.util.logging.Logger.getGlobal().log(java.util.logging.Level.INFO, "", e); } }
@Test public void testGeographicLarge() throws Exception { ReferencedEnvelope mapExtent = new ReferencedEnvelope(-360, 360, -90, 90, DefaultGeographicCRS.WGS84); GridCoverageReaderHelper helper = new GridCoverageReaderHelper( reader, new Rectangle(720, 180), mapExtent, Interpolation.getInstance(Interpolation.INTERP_NEAREST)); // read single coverage with no projection handling GridCoverage2D coverage = helper.readCoverage(null); Envelope2D envelope = coverage.getEnvelope2D(); assertEquals(-180, envelope.getMinX(), EPS); assertEquals(180, envelope.getMaxX(), EPS); assertEquals(-90, envelope.getMinY(), EPS); assertEquals(90, envelope.getMaxY(), EPS); // try multiple coverage with projection handling, should not make a difference // since we are already reading everything in a single shot, just in need of coverage // replication // (which has to be performed after the eventual reprojection, so not here in the reader) ProjectionHandler handler = ProjectionHandlerFinder.getHandler( mapExtent, reader.getCoordinateReferenceSystem(), true); List<GridCoverage2D> coverages = helper.readCoverages(null, handler); // System.out.println(coverages); assertEquals(1, coverages.size()); assertEquals(envelope, coverages.get(0).getEnvelope2D()); }