This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit 86ad66def3af562afa26b35231a16b2152347296
Merge: 0b29f05 53b168a
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Fri Sep 11 19:41:35 2020 +0200
Merge branch 'fix/sourceExpansion' into geoapi-4.0 together with the fix for the problem
shown by the new test.
.../sis/internal/storage/MemoryGridResource.java | 2 +-
.../sis/internal/storage/query/CoverageSubset.java | 3 +
.../internal/storage/query/CoverageQueryTest.java | 41 ++++----
.../internal/storage/query/GridResourceMock.java | 110 +++++++++++++++++++++
4 files changed, 135 insertions(+), 21 deletions(-)
diff --cc storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MemoryGridResource.java
index 5ca5d2f,5ca5d2f..5efd4ab
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MemoryGridResource.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MemoryGridResource.java
@@@ -86,7 -86,7 +86,7 @@@ public class MemoryGridResource extend
* In current implementation this is either a {@link org.apache.sis.coverage.grid.GridCoverage2D}
or
* the original grid coverage.
*
-- * @param domain desired grid extent and resolution, or {@code null} for reading the
whole domain.
++ * @param domain desired grid extent and resolution, or {@code null} for the whole
domain.
* @param range 0-based indices of sample dimensions to read, or {@code null} or
an empty sequence for reading them all.
* @return the grid coverage for the specified domain and range.
*/
diff --cc storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/CoverageSubset.java
index 2f59592,2f59592..3926441
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/CoverageSubset.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/CoverageSubset.java
@@@ -161,6 -161,6 +161,9 @@@ final class CoverageSubset extends Abst
*/
@Override
public GridCoverage read(GridGeometry domain, int... range) throws DataStoreException
{
++ if (domain == null) {
++ domain = source.getGridGeometry();
++ }
domain = clip(domain, query.getDomain(), GridRoundingMode.ENCLOSING, query.getSourceDomainExpansion());
final int[] qr = query.getRange();
if (range == null) {
diff --cc storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/CoverageQueryTest.java
index 16362b0,478f47d..b515937
--- a/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/CoverageQueryTest.java
+++ b/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/CoverageQueryTest.java
@@@ -16,12 -16,12 +16,10 @@@
*/
package org.apache.sis.internal.storage.query;
- import java.awt.image.BufferedImage;
-import java.awt.image.RenderedImage;
import org.opengis.metadata.spatial.DimensionNameType;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.datum.PixelInCell;
import org.apache.sis.coverage.grid.GridCoverage;
--import org.apache.sis.coverage.grid.GridCoverage2D;
import org.apache.sis.coverage.grid.GridExtent;
import org.apache.sis.coverage.grid.GridGeometry;
import org.apache.sis.internal.referencing.j2d.AffineTransform2D;
@@@ -67,8 -66,7 +64,7 @@@ public final strictfp class CoverageQue
final int width = 32;
final int height = 37;
final GridGeometry grid = new GridGeometry(new GridExtent(width, height), PixelInCell.CELL_CENTER,
gridToCRS, crs);
- final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
- resource = new MemoryGridResource(null, new GridCoverage2D(grid, null, image));
- resource = new MockGridResource(grid);
++ resource = new GridResourceMock(grid);
}
/**
@@@ -81,7 -79,7 +77,7 @@@
final CoverageQuery query = new CoverageQuery();
final GridCoverageResource subset = resource.subset(query);
assertSame(resource.getGridGeometry(), subset.getGridGeometry());
-- verifyRead(subset);
++ verifyRead(subset, 0);
}
/**
@@@ -109,7 -107,7 +105,7 @@@
final GridCoverageResource subset = resource.subset(query);
assertEquals(subGrid, subset.getGridGeometry());
-- verifyRead(subset);
++ verifyRead(subset, 0);
}
/**
@@@ -119,31 -117,40 +115,36 @@@
*/
@Test
public void testWithExpansion() throws DataStoreException {
++ final int expansion = 3;
final GridGeometry subGrid = createSubGrid(0);
final CoverageQuery query = new CoverageQuery();
query.setDomain(subGrid);
-- query.setSourceDomainExpansion(3);
++ query.setSourceDomainExpansion(expansion);
final GridCoverageResource subset = resource.subset(query);
-- assertEquals(createSubGrid(3), subset.getGridGeometry());
-- verifyRead(subset);
-
- /*
- Current implementation returns the full image
- but still, the expansion should be visible in the image offset
- */
- GridCoverage coverage = subset.read(null);
- RenderedImage image = coverage.render(null);
- System.out.println(image);
++ assertEquals(createSubGrid(expansion), subset.getGridGeometry());
++ verifyRead(subset, expansion);
}
/**
* Verifies that the read operation adds the expected margins.
-- * This is an anti-regression test; in current implementation,
-- * {@link GridCoverage2D} returns a larger area then requested.
*/
-- private void verifyRead(final GridCoverageResource subset) throws DataStoreException
{
- final GridGeometry request = createSubGrid(-4);
- final GridCoverage coverage = subset.read(request);
-
- { //must be the same as subset grid geometry
- final GridCoverage coverage = subset.read(null);
- assertEquals(subset.getGridGeometry(), coverage.getGridGeometry());
- }
-
- {
- final GridGeometry request = createSubGrid(-4);
- final GridCoverage coverage = subset.read(request);
- assertEquals(request, coverage.getGridGeometry());
++ private void verifyRead(final GridCoverageResource subset, final int expansion) throws
DataStoreException {
++ /*
++ * Test reading the whole image. The grid geometry of returned coverage
++ * must be the same than the grid geometry of the GridCoverageResource,
++ * which has been verified by the caller to contain the expansion.
++ */
++ assertEquals(subset.getGridGeometry(), subset.read(null).getGridGeometry());
+ /*
- * PENDING_JDK_FIX: replace following lines by new tests
- * after https://bugs.openjdk.java.net/browse/JDK-8166038 is fixed.
++ * Request for a smaller area and verify that the request has the expected size,
++ * including expansion.
+ */
- if (coverage.render(null) instanceof BufferedImage) {
- final GridGeometry expected = resource.getGridGeometry();
- assertEquals(expected, coverage.getGridGeometry());
++ GridGeometry request = createSubGrid(-4);
++ final GridCoverage coverage = subset.read(request);
++ if (expansion != 0) {
++ request = createSubGrid(-4 + expansion);
}
++ assertEquals(request, coverage.getGridGeometry());
}
}
diff --cc storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/GridResourceMock.java
index 0000000,0000000..bb98f4a
new file mode 100644
--- /dev/null
+++ b/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/GridResourceMock.java
@@@ -1,0 -1,0 +1,110 @@@
++/*
++ * Licensed to the Apache Software Foundation (ASF) under one or more
++ * contributor license agreements. See the NOTICE file distributed with
++ * this work for additional information regarding copyright ownership.
++ * The ASF licenses this file to You under the Apache License, Version 2.0
++ * (the "License"); you may not use this file except in compliance with
++ * the License. You may obtain a copy of the License at
++ *
++ * http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing, software
++ * distributed under the License is distributed on an "AS IS" BASIS,
++ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
++ * See the License for the specific language governing permissions and
++ * limitations under the License.
++ */
++package org.apache.sis.internal.storage.query;
++
++import java.util.List;
++import java.util.Collections;
++import java.awt.image.BufferedImage;
++import org.apache.sis.coverage.SampleDimension;
++import org.apache.sis.coverage.grid.GridCoverage;
++import org.apache.sis.coverage.grid.GridCoverage2D;
++import org.apache.sis.coverage.grid.GridExtent;
++import org.apache.sis.coverage.grid.GridGeometry;
++import org.apache.sis.coverage.grid.GridRoundingMode;
++import org.apache.sis.internal.storage.AbstractGridResource;
++
++import static org.junit.Assert.*;
++
++
++/**
++ * A resource for one-banded images generated on-the-fly when {@link #read(GridGeometry,
int...)} is invoked.
++ * This class has some similarities with {@link org.apache.sis.internal.storage.MemoryGridResource}
except that
++ * the {@link GridCoverage} returned by {@link #read read(…)} is guaranteed to wrap an
image having exactly the
++ * requested size (i.e. the size specified by {@link GridGeometry#getExtent()}).
++ * By contrast {@code org.apache.sis.internal.storage.MemoryGridResource} may return images
larger than requested,
++ * which make testing more difficult.
++ *
++ * @author Johann Sorel (Geomatys)
++ * @version 1.1
++ * @since 1.1
++ */
++final strictfp class GridResourceMock extends AbstractGridResource {
++ /**
++ * Grid geometry of this resource, specified at construction time.
++ */
++ private final GridGeometry gridGeometry;
++
++ /**
++ * A dummy sample dimension.
++ */
++ private final List<SampleDimension> sampleDimensions;
++
++ /**
++ * Creates a resource mock with the given grid geometry.
++ */
++ GridResourceMock(final GridGeometry gridGeometry) {
++ super(null);
++ assertNotNull(gridGeometry);
++ this.gridGeometry = gridGeometry;
++ this.sampleDimensions = Collections.singletonList(new SampleDimension.Builder().setName(0).build());
++ }
++
++ /**
++ * Returns the grid geometry specified at construction time.
++ */
++ @Override
++ public GridGeometry getGridGeometry() {
++ return gridGeometry;
++ }
++
++ /**
++ * Returns a dummy sample dimension. This resource always provide exactly one band.
++ */
++ @Override
++ @SuppressWarnings("ReturnOfCollectionOrArrayField") // The list is unmodifiable.
++ public List<SampleDimension> getSampleDimensions() {
++ return sampleDimensions;
++ }
++
++ /**
++ * Returns a grid geometry wrapping a dummy image having exactly the requested size.
++ * The image will always be a {@link BufferedImage} with pixel coordinates starting
at (0,0).
++ *
++ * @param domain desired grid extent and resolution, or {@code null} for the whole
domain.
++ * @param range must be null, empty or a singleton containing only value 0.
++ * @return the grid coverage for the specified domain.
++ */
++ @Override
++ public GridCoverage read(GridGeometry domain, final int... range) {
++ assertTrue(range == null || range.length == 0 || (range.length == 1 && range[0]
== 0));
++ if (domain == null) {
++ domain = gridGeometry;
++ } else {
++ domain = gridGeometry.derive()
++ .rounding(GridRoundingMode.ENCLOSING)
++ .subgrid(domain)
++ .build();
++ }
++ final GridExtent extent = domain.getExtent();
++ final BufferedImage img = new BufferedImage(
++ StrictMath.toIntExact(extent.getSize(0)),
++ StrictMath.toIntExact(extent.getSize(1)),
++ BufferedImage.TYPE_BYTE_BINARY);
++
++ return new GridCoverage2D(domain, sampleDimensions, img);
++ }
++}
|