Search in sources :

Example 21 with GridGeometry

use of org.apache.sis.coverage.grid.GridGeometry in project sis by apache.

the class GridAdjustment method scale.

/**
 * Creates a new grid geometry with a scale factor applied in grid coordinates before the "grid to CRS" conversion.
 *
 * @param  grid               the grid geometry to scale.
 * @param  extent             the extent to allocate to the new grid geometry.
 * @param  anchor             the transform to adjust: "center to CRS" or "corner to CRS".
 * @param  dataToGridIndices  value of {@link #dataToGridIndices()}.
 * @return scaled grid geometry.
 */
static GridGeometry scale(final GridGeometry grid, final GridExtent extent, final PixelInCell anchor, final double[] dataToGridIndices) {
    MathTransform gridToCRS = grid.getGridToCRS(anchor);
    final LinearTransform scale = MathTransforms.scale(dataToGridIndices);
    gridToCRS = MathTransforms.concatenate(scale, gridToCRS);
    return new GridGeometry(extent, anchor, gridToCRS, grid.isDefined(GridGeometry.CRS) ? grid.getCoordinateReferenceSystem() : null);
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) MathTransform(org.opengis.referencing.operation.MathTransform) LinearTransform(org.apache.sis.referencing.operation.transform.LinearTransform)

Example 22 with GridGeometry

use of org.apache.sis.coverage.grid.GridGeometry in project sis by apache.

the class CoverageQuery method setSelection.

/**
 * Sets the approximate area of cells or pixels to include in the subset.
 * This convenience method creates a grid geometry containing only the given envelope.
 * Note that the given envelope is approximate:
 * Coverages may expand the envelope to an integer amount of tiles.
 *
 * @param  domain  the approximate area of interest, or {@code null} if none.
 */
@Override
public void setSelection(final Envelope domain) {
    GridGeometry g = null;
    if (domain != null) {
        g = new GridGeometry(null, null, domain, GridRoundingMode.NEAREST);
    }
    setSelection(g);
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry)

Example 23 with GridGeometry

use of org.apache.sis.coverage.grid.GridGeometry in project sis by apache.

the class MemoryGridResourceTest method testRead.

/**
 * Tests {@link MemoryGridResource#read(GridGeometry, int...)}.
 */
@Test
public void testRead() {
    final GridGeometry request = createSubGrid();
    final GridCoverage coverage = resource.read(request);
    /*
         * Note: following lines work only with JDK 16 or above.
         * https://bugs.openjdk.java.net/browse/JDK-8166038
         */
    assertEqualsIgnoreMetadata(request, coverage.getGridGeometry());
    assertInstanceOf("render(null)", BufferedImage.class, coverage.render(null));
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) Test(org.junit.Test)

Example 24 with GridGeometry

use of org.apache.sis.coverage.grid.GridGeometry in project sis by apache.

the class CoverageQueryTest method testWithExpansion.

/**
 * Tests with a sub-grid geometry and a source domain expansion.
 *
 * @throws DataStoreException if query execution failed.
 */
@Test
public void testWithExpansion() throws DataStoreException {
    final int expansion = 3;
    final GridGeometry subGrid = createSubGrid(0);
    final CoverageQuery query = new CoverageQuery();
    query.setSelection(subGrid);
    query.setSourceDomainExpansion(expansion);
    final GridCoverageResource subset = resource.subset(query);
    assertEquals(createSubGrid(expansion), subset.getGridGeometry());
    verifyRead(subset, expansion);
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) Test(org.junit.Test)

Example 25 with GridGeometry

use of org.apache.sis.coverage.grid.GridGeometry in project sis by apache.

the class CoverageQueryTest method testQueryMethods.

/**
 * Tests using only the methods defined in the {@link Query} base class.
 *
 * @throws DataStoreException if query execution failed.
 */
@Test
public void testQueryMethods() throws DataStoreException {
    final GridGeometry subGrid = createSubGrid(0);
    final Query query = new CoverageQuery();
    query.setSelection(subGrid.getEnvelope());
    query.setProjection("0");
    final GridCoverageResource subset = resource.subset(query);
    assertEquals(subGrid, subset.getGridGeometry());
    verifyRead(subset, 0);
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) Test(org.junit.Test)

Aggregations

GridGeometry (org.apache.sis.coverage.grid.GridGeometry)25 GridExtent (org.apache.sis.coverage.grid.GridExtent)10 SampleDimension (org.apache.sis.coverage.SampleDimension)6 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)6 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)5 MathTransform (org.opengis.referencing.operation.MathTransform)5 Test (org.junit.Test)4 TransformException (org.opengis.referencing.operation.TransformException)4 GridDerivation (org.apache.sis.coverage.grid.GridDerivation)3 Point (java.awt.Point)2 RenderedImage (java.awt.image.RenderedImage)2 GridCoverage2D (org.apache.sis.coverage.grid.GridCoverage2D)2 LinearTransform (org.apache.sis.referencing.operation.transform.LinearTransform)2 DataStoreContentException (org.apache.sis.storage.DataStoreContentException)2 FactoryException (org.opengis.util.FactoryException)2 AffineTransform (java.awt.geom.AffineTransform)1 BufferedImage (java.awt.image.BufferedImage)1 DataBuffer (java.awt.image.DataBuffer)1 RasterFormatException (java.awt.image.RasterFormatException)1 IOException (java.io.IOException)1