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);
}
}
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);
}
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;
}
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);
}
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));
}
Aggregations