sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jso...@apache.org
Subject [sis] 01/01: Best effort implementation of coverage query source domain expansion parameter
Date Mon, 31 Aug 2020 15:22:46 GMT
This is an automated email from the ASF dual-hosted git repository.

jsorel pushed a commit to branch feat/sourceDomainExpansion
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 6e8b8eb3eb97bb944e194d8e9f603c2c8bf64473
Author: jsorel <johann.sorel@geomatys.com>
AuthorDate: Mon Aug 31 17:21:56 2020 +0200

    Best effort implementation of coverage query source domain expansion parameter
---
 .../sis/internal/storage/query/CoverageQuery.java  |  6 +++---
 .../sis/internal/storage/query/CoverageSubset.java | 23 ++++++++++++++++++----
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/CoverageQuery.java
b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/CoverageQuery.java
index 08724c0..53ba1dd 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/CoverageQuery.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/CoverageQuery.java
@@ -145,15 +145,15 @@ public final class CoverageQuery extends Query implements Cloneable
{
     /**
      * Applies this query on the given coverage.
      *
+     * Current implementation apply the source domain expansion when the source
+     * grid geometry extent is defined, otherwise it is ignored.
+     *
      * @param  source  the coverage resource to filter.
      * @return a view over the given coverage resource containing only the given domain and
range.
      * @throws UnsupportedQueryException if this query contains filtering options not yet
supported.
      */
     public GridCoverageResource execute(final GridCoverageResource source) throws UnsupportedQueryException
{
         ArgumentChecks.ensureNonNull("source", source);
-        if (getSourceDomainExpansion() != 0) {
-            throw new UnsupportedQueryException("Source domain expansion not yet supported.");
-        }
         return new CoverageSubset(source, clone());
     }
 
diff --git 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
index 143e1c5..701b9b8 100644
--- 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
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.internal.storage.query;
 
+import java.util.Arrays;
 import java.util.List;
 import org.apache.sis.coverage.SampleDimension;
 import org.apache.sis.coverage.grid.GridCoverage;
@@ -80,7 +81,10 @@ final class CoverageSubset extends AbstractGridResource {
      */
     @Override
     public GridGeometry getGridGeometry() throws DataStoreException {
-        return clip(source.getGridGeometry(), query.getDomain(), GridRoundingMode.NEAREST);
+        return clip(source.getGridGeometry(),
+                query.getDomain(),
+                GridRoundingMode.NEAREST,
+                query.getSourceDomainExpansion());
     }
 
     /**
@@ -89,16 +93,23 @@ final class CoverageSubset extends AbstractGridResource {
      * @param  domain          the domain to clip, or {@code null}.
      * @param  areaOfInterest  the area of interest, or {@code null}.
      * @param  rounding        whether to clip to nearest box or an enclosing box.
+     * @param  expansion       domain expansion, applied only if domain extent is defined.
      * @return intersection of the given grid geometry.
      * @throws DataStoreException if the intersection can not be computed.
      */
     private GridGeometry clip(final GridGeometry domain, final GridGeometry areaOfInterest,
-            final GridRoundingMode rounding) throws DataStoreException
+            final GridRoundingMode rounding, int expansion) throws DataStoreException
     {
         if (domain == null) return areaOfInterest;
         if (areaOfInterest == null) return domain;
         try {
-            return domain.derive().rounding(rounding).subgrid(areaOfInterest).build();
+            if (expansion > 0 && domain.isDefined(GridGeometry.EXTENT)) {
+                final int[] margins = new int[domain.getDimension()];
+                Arrays.fill(margins, expansion);
+                return domain.derive().rounding(rounding).margin(margins).subgrid(areaOfInterest).build();
+            } else {
+                return domain.derive().rounding(rounding).subgrid(areaOfInterest).build();
+            }
         } catch (IllegalArgumentException | IllegalStateException e) {
             final String msg = Resources.forLocale(getLocale())
                     .getString(Resources.Keys.CanNotIntersectDataWithQuery_1, getSourceName());
@@ -149,7 +160,11 @@ final class CoverageSubset extends AbstractGridResource {
      */
     @Override
     public GridCoverage read(GridGeometry domain, int... range) throws DataStoreException
{
-        domain = clip(domain, query.getDomain(), GridRoundingMode.ENCLOSING);
+        domain = clip(domain, query.getDomain(), GridRoundingMode.ENCLOSING, 0);
+        if (domain != null && query.getSourceDomainExpansion() > 0) {
+            domain = clip(getGridGeometry(), domain, GridRoundingMode.ENCLOSING, query.getSourceDomainExpansion());
+        }
+
         final int[] qr = query.getRange();
         if (range == null) {
             range = qr;


Mime
View raw message