Search in sources :

Example 11 with GridCoverage

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

the class ImageRequest method configure.

/**
 * Configures the given status bar with the geometry of the grid coverage we have just read.
 * This method is invoked in JavaFX thread after {@link GridView#setImage(ImageRequest)}
 * loaded in background thread a new image, successfully or not.
 */
final void configure(final StatusBar bar) {
    final Long id = LogHandler.loadingStart(resource);
    try {
        final GridCoverage cv = coverage;
        final GridExtent ex = sliceExtent;
        bar.applyCanvasGeometry(cv != null ? cv.getGridGeometry() : null);
        /*
             * By `GridCoverage.render(GridExtent)` contract, the `RenderedImage` pixel coordinates are relative
             * to the requested `GridExtent`. Consequently we need to translate the image coordinates so that it
             * become the coordinates of the original `GridGeometry` before to apply `gridToCRS`.  It is okay to
             * modify `StatusBar.localToObjectiveCRS` because we do not associate it to a `MapCanvas`, so it will
             * not be overwritten by gesture events (zoom, pan, etc).
             */
        if (ex != null) {
            final double[] origin = new double[ex.getDimension()];
            for (int i = 0; i < origin.length; i++) {
                origin[i] = ex.getLow(i);
            }
            bar.localToObjectiveCRS.set(MathTransforms.concatenate(MathTransforms.translation(origin), bar.localToObjectiveCRS.get()));
        }
    } finally {
        LogHandler.loadingStop(id);
    }
}
Also used : GridExtent(org.apache.sis.coverage.grid.GridExtent) GridCoverage(org.apache.sis.coverage.grid.GridCoverage)

Example 12 with GridCoverage

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

the class CoverageControls method load.

/**
 * Sets the view content to the given coverage.
 * This method is invoked when a new source of data (either a resource or a coverage) is specified,
 * or when a previously hidden view is made visible. This implementation starts a background thread.
 *
 * @param  request  the resource or coverage to set, or {@code null} for clearing the view.
 */
@Override
final void load(final ImageRequest request) {
    final GridCoverageResource resource;
    final GridCoverage coverage;
    if (request != null) {
        resource = request.resource;
        coverage = request.getCoverage().orElse(null);
    } else {
        resource = null;
        coverage = null;
    }
    view.setCoverage(resource, coverage);
}
Also used : GridCoverage(org.apache.sis.coverage.grid.GridCoverage) GridCoverageResource(org.apache.sis.storage.GridCoverageResource)

Example 13 with GridCoverage

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

the class DataCube method read.

/**
 * Creates a {@link GridCoverage} which will load pixel data in the given domain.
 *
 * @param  domain  desired grid extent and resolution, or {@code null} for reading the whole domain.
 * @param  range   0-based index of sample dimensions to read, or an empty sequence for reading all ranges.
 * @return the grid coverage for the specified domain and range.
 * @throws DataStoreException if an error occurred while reading the grid coverage data.
 */
@Override
public final GridCoverage read(final GridGeometry domain, final int... range) throws DataStoreException {
    final long startTime = System.nanoTime();
    GridCoverage coverage;
    try {
        synchronized (getSynchronizationLock()) {
            final Subset subset = new Subset(domain, range);
            final Compression compression = getCompression();
            if (compression == null) {
                throw new DataStoreContentException(reader.resources().getString(Resources.Keys.MissingValue_2, Tags.name(Tags.Compression)));
            }
            /*
                 * The `DataSubset` parent class is the most efficient but has many limitations
                 * documented in the javadoc of its `readSlice(…)` method. If any pre-condition
                 * is not met, we need to fallback on the less direct `CompressedSubset` class.
                 */
            if (compression == Compression.NONE && getPredictor() == Predictor.NONE && canReadDirect(subset)) {
                coverage = new DataSubset(this, subset);
            } else {
                coverage = new CompressedSubset(this, subset);
            }
            coverage = preload(coverage);
        }
    } catch (RuntimeException e) {
        throw canNotRead(reader.input.filename, domain, e);
    }
    logReadOperation(reader.store.path, coverage.getGridGeometry(), startTime);
    return coverage;
}
Also used : Compression(org.apache.sis.internal.geotiff.Compression) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) DataStoreContentException(org.apache.sis.storage.DataStoreContentException)

Example 14 with GridCoverage

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

the class PostgresTest method validate.

/**
 * Invoked for each feature instances for performing some checks on the feature.
 * This method performs only a superficial verification of geometries.
 */
private static void validate(final AbstractFeature feature) {
    final String filename = feature.getPropertyValue("filename").toString();
    final Geometry geometry = (Geometry) feature.getPropertyValue("geometry");
    final GridCoverage raster = (GridCoverage) feature.getPropertyValue("image");
    final int geomSRID;
    switch(filename) {
        case "raster-ushort.wkb":
            {
                assertNull(geometry);
                RasterReaderTest.compareReadResult(TestRaster.USHORT, raster);
                assertSame(CommonCRS.WGS84.normalizedGeographic(), raster.getCoordinateReferenceSystem());
                return;
            }
        case "point-prj":
            {
                final Point p = (Point) geometry;
                assertEquals(2, p.getX(), STRICT);
                assertEquals(3, p.getY(), STRICT);
                geomSRID = 3395;
                break;
            }
        case "polygon-prj":
            geomSRID = 3395;
            break;
        case "linestring":
        case "polygon":
        case "multi-linestring":
        case "multi-polygon":
            geomSRID = 4326;
            break;
        default:
            throw new AssertionError(filename);
    }
    try {
        assertEquals(GeometryGetterTest.getExpectedCRS(geomSRID), JTS.getCoordinateReferenceSystem(geometry));
    } catch (FactoryException e) {
        throw new AssertionError(e);
    }
    assertNull(raster);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) FactoryException(org.opengis.util.FactoryException) Point(org.locationtech.jts.geom.Point) Point(org.locationtech.jts.geom.Point)

Example 15 with GridCoverage

use of org.apache.sis.coverage.grid.GridCoverage 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)

Aggregations

GridCoverage (org.apache.sis.coverage.grid.GridCoverage)15 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)5 GridExtent (org.apache.sis.coverage.grid.GridExtent)3 GridCoverageResource (org.apache.sis.storage.GridCoverageResource)2 MathTransform (org.opengis.referencing.operation.MathTransform)2 Point (java.awt.Point)1 NumberFormat (java.text.NumberFormat)1 LogRecord (java.util.logging.LogRecord)1 Length (javax.measure.quantity.Length)1 GridDerivation (org.apache.sis.coverage.grid.GridDerivation)1 CoverageCanvas (org.apache.sis.gui.coverage.CoverageCanvas)1 PixelIterator (org.apache.sis.image.PixelIterator)1 Compression (org.apache.sis.internal.geotiff.Compression)1 TableAppender (org.apache.sis.io.TableAppender)1 Statistics (org.apache.sis.math.Statistics)1 DataStoreContentException (org.apache.sis.storage.DataStoreContentException)1 Test (org.junit.Test)1 Geometry (org.locationtech.jts.geom.Geometry)1 Point (org.locationtech.jts.geom.Point)1 FactoryException (org.opengis.util.FactoryException)1