/** * Returns the envelope span (typically width or height) along the specified dimension. The * result should be equals (minus rounding error) to <code>{@linkplain #getMaximum * getMaximum}(dimension) - {@linkplain #getMinimum getMinimum}(dimension)</code>. * * @param dimension The dimension to query. * @return The difference along maximal and minimal ordinates in the given dimension. * @throws IndexOutOfBoundsException If the given index is out of bounds. */ public final double getSpan(final int dimension) throws IndexOutOfBoundsException { switch (dimension) { case 0: return getWidth(); case 1: return getHeight(); 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); } }
static Envelope2D doInscribeFullDisk(Envelope2D circumscribed) { double dx = circumscribed.getWidth() / SQRT2; double dy = circumscribed.getHeight() / SQRT2; return new Envelope2D( circumscribed.getCoordinateReferenceSystem(), circumscribed.getCenterX() - dx / 2., circumscribed.getCenterY() - dy / 2., dx, dy); }
/** * 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 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; }
/** * 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); } }
int fitRectHeight = (int) (sceneDescription.getSceneEnvelope().getHeight() / (layoutRatioY * getProductResolution().resolution));
int fitRectHeight = (int) (sceneDescription.getSceneEnvelope().getHeight() / (layoutRatioY * getProductResolution().resolution));
props.setProperty("Name", mosaic.getName()); props.setProperty("Levels", String.format("%f,%f", first.getEnvelope().getWidth()/width, first.getEnvelope().getHeight()/height)); props.setProperty("LevelsNum", "1"); props.setProperty("LocationAttribute", "location");
public RasterCoverage(String sourceURL, GridCoverage2D coverage, GridSampleDimension dimension, boolean isSingleBand) { this.sourceURL = sourceURL; /* add band fragment ONLY if there is more than one band */ if (!isSingleBand) { this.sourceURL += "#" + Escape.forURL(dimension.toString()); } this.coverage = coverage; this.dimension = dimension; this.crs = coverage.getCoordinateReferenceSystem2D(); this.gridGeometry = coverage.getGridGeometry(); /* no data values */ noData = dimension.getNoDataValues(); /* TODO see if we have to add the band info */ this.layerName = MiscUtilities.getURLBaseName(sourceURL).toLowerCase(); xCellSize = coverage.getEnvelope2D().getWidth() / getXCells(); yCellSize = coverage.getEnvelope2D().getHeight() / getYCells(); this.boundingBox = new ReferencedEnvelope(coverage.getEnvelope2D().getMinX(), coverage .getEnvelope2D().getMaxX(), coverage.getEnvelope2D().getMinY(), coverage.getEnvelope2D() .getMaxY(), crs); }
public RasterCoverage(String name, GridCoverage2D raster) { this.coverage = raster; this.layerName = name; this.dimension = raster.getSampleDimension(0); // this.dimension = dimension; this.crs = coverage.getCoordinateReferenceSystem2D(); this.gridGeometry = coverage.getGridGeometry(); /* no data values */ noData = dimension.getNoDataValues(); xCellSize = coverage.getEnvelope2D().getWidth() / getXCells(); yCellSize = coverage.getEnvelope2D().getHeight() / getYCells(); this.boundingBox = new ReferencedEnvelope(coverage.getEnvelope2D().getMinX(), coverage .getEnvelope2D().getMaxX(), coverage.getEnvelope2D().getMinY(), coverage.getEnvelope2D() .getMaxY(), crs); // coverage.show(); }
@Test public void testRequestCoverage() throws Exception { // http response from the request inside the string MockHttpServletResponse response = getAsServletResponse("ows?request=GetCoverage&service=WCS&version=2.0.1" + "&coverageId=wcs__2DLatLonCoverage&format=application/custom&subset=time,http://www.opengis.net/def/trs/ISO-8601/0/Gregorian UTC(\"2013-11-01T00:00:00.000Z\")&subset=BANDS(\"MyBand\")"); assertNotNull(response); GridCoverage2D lastResult = applicationContext.getBean(WCSResponseInterceptor.class).getLastResult(); assertTrue(lastResult instanceof GranuleStack); GranuleStack stack = (GranuleStack) lastResult; //we expect a single granule which covers the entire mosaic for(GridCoverage2D c : stack.getGranules()){ assertEquals(30., c.getEnvelope2D().getHeight(),0.001); assertEquals(45., c.getEnvelope2D().getWidth(),0.001); } assertEquals(1, stack.getGranules().size()); }
@Test public void testRequestCoverage() throws Exception { // http response from the request inside the string MockHttpServletResponse response = getAsServletResponse( "ows?request=GetCoverage&service=WCS&version=2.0.1" + "&coverageId=wcs__2DLatLonCoverage&format=application/custom&subset=time,http://www.opengis.net/def/trs/ISO-8601/0/Gregorian UTC(\"2013-11-01T00:00:00.000Z\")&subset=BANDS(\"MyBand\")"); assertNotNull(response); GridCoverage2D lastResult = applicationContext.getBean(WCSResponseInterceptor.class).getLastResult(); assertTrue(lastResult instanceof GranuleStack); GranuleStack stack = (GranuleStack) lastResult; // we expect a single granule which covers the entire mosaic for (GridCoverage2D c : stack.getGranules()) { assertEquals(30., c.getEnvelope2D().getHeight(), 0.001); assertEquals(45., c.getEnvelope2D().getWidth(), 0.001); } assertEquals(1, stack.getGranules().size()); }
if (covEnvelope.contains(readBoundingBox) && (covEnvelope.getWidth() > readBoundingBox.getWidth() || covEnvelope.getHeight() > readBoundingBox.getHeight())) { cropped = cropOnEnvelope(cov, readEnvelope);
yCellSize = coverage.getEnvelope2D().getHeight() / getYCells();
@Test public void testRequestCoverageLatLon() throws Exception { final WCSInfo wcsInfo = getWCS(); final boolean oldLatLon = wcsInfo.isLatLon(); wcsInfo.setLatLon(true); getGeoServer().save(wcsInfo); try { // http response from the request inside the string MockHttpServletResponse response = getAsServletResponse("ows?request=GetCoverage&service=WCS&version=2.0.1" + "&coverageId=wcs__2DLatLonCoverage&format=application/custom&subset=time,http://www.opengis.net/def/trs/ISO-8601/0/Gregorian UTC(\"2013-11-01T00:00:00.000Z\")&subset=BANDS(\"MyBand\")"); assertNotNull(response); GridCoverage2D lastResult = applicationContext.getBean(WCSResponseInterceptor.class) .getLastResult(); assertTrue(lastResult instanceof GranuleStack); GranuleStack stack = (GranuleStack) lastResult; // we expect a single granule which covers the entire mosaic for (GridCoverage2D c : stack.getGranules()) { System.out.println(c.getEnvelope()); assertEquals(45., c.getEnvelope2D().getHeight(), 0.001); assertEquals(30., c.getEnvelope2D().getWidth(), 0.001); } assertEquals(1, stack.getGranules().size()); } finally { wcsInfo.setLatLon(oldLatLon); getGeoServer().save(wcsInfo); } }
@Test public void testRequestCoverageLatLon() throws Exception { final WCSInfo wcsInfo = getWCS(); final boolean oldLatLon = wcsInfo.isLatLon(); wcsInfo.setLatLon(true); getGeoServer().save(wcsInfo); try { // http response from the request inside the string MockHttpServletResponse response = getAsServletResponse( "ows?request=GetCoverage&service=WCS&version=2.0.1" + "&coverageId=wcs__2DLatLonCoverage&format=application/custom&subset=time,http://www.opengis.net/def/trs/ISO-8601/0/Gregorian UTC(\"2013-11-01T00:00:00.000Z\")&subset=BANDS(\"MyBand\")"); assertNotNull(response); GridCoverage2D lastResult = applicationContext.getBean(WCSResponseInterceptor.class).getLastResult(); assertTrue(lastResult instanceof GranuleStack); GranuleStack stack = (GranuleStack) lastResult; // we expect a single granule which covers the entire mosaic for (GridCoverage2D c : stack.getGranules()) { System.out.println(c.getEnvelope()); assertEquals(45., c.getEnvelope2D().getHeight(), 0.001); assertEquals(30., c.getEnvelope2D().getWidth(), 0.001); } assertEquals(1, stack.getGranules().size()); } finally { wcsInfo.setLatLon(oldLatLon); getGeoServer().save(wcsInfo); } }