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 0ac8c06a94e13907ff193e9d84e2b43189561f06
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Wed Nov 22 15:52:33 2023 +0100

    If an envelope cannot be transformed for metadata purpose, consider that as 
a warning rather than a fatal error.
    It happens when the CRS is an engineering CRS with no geodetic, projected, 
vertical or temporal component.
---
 .../sis/storage/geotiff/ImageFileDirectory.java      |  6 ++----
 .../apache/sis/storage/aggregate/GroupAggregate.java |  6 +-----
 .../org/apache/sis/storage/base/MetadataBuilder.java | 20 ++++++++------------
 .../org/apache/sis/storage/base/URIDataStore.java    |  2 ++
 .../main/org/apache/sis/storage/csv/Store.java       |  7 +------
 .../org/apache/sis/storage/esri/RasterStore.java     |  7 +------
 .../org/apache/sis/storage/image/WorldFileStore.java |  6 +-----
 7 files changed, 16 insertions(+), 38 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java
 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java
index a0540b2b90..add3452efe 100644
--- 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java
+++ 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java
@@ -1406,10 +1406,8 @@ final class ImageFileDirectory extends DataCube {
          */
         if (referencing != null) {
             final GridGeometry gridGeometry = getGridGeometry();
-            if (gridGeometry.isDefined(GridGeometry.ENVELOPE)) try {
-                metadata.addExtent(gridGeometry.getEnvelope());
-            } catch (TransformException e) {
-                listeners.warning(e);
+            if (gridGeometry.isDefined(GridGeometry.ENVELOPE)) {
+                metadata.addExtent(gridGeometry.getEnvelope(), listeners);
             }
             referencing.completeMetadata(gridGeometry, metadata);
         }
diff --git 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/aggregate/GroupAggregate.java
 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/aggregate/GroupAggregate.java
index ea5505a4f4..ee635bd588 100644
--- 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/aggregate/GroupAggregate.java
+++ 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/aggregate/GroupAggregate.java
@@ -321,11 +321,7 @@ final class GroupAggregate extends AbstractResource 
implements Aggregate, Aggreg
     protected Metadata createMetadata() throws DataStoreException {
         final MetadataBuilder builder = new MetadataBuilder();
         builder.addTitle(name);
-        try {
-            builder.addExtent(envelope);
-        } catch (TransformException e) {
-            listeners.warning(e);
-        }
+        builder.addExtent(envelope, listeners);
         if (sampleDimensions != null) {
             for (final SampleDimension band : sampleDimensions) {
                 builder.addNewBand(band);
diff --git 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/MetadataBuilder.java
 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/MetadataBuilder.java
index b63afc7f6d..e317e4119f 100644
--- 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/MetadataBuilder.java
+++ 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/MetadataBuilder.java
@@ -825,13 +825,7 @@ public class MetadataBuilder {
     public final void addDefaultMetadata(final AbstractResource resource, 
final StoreListeners listeners) throws DataStoreException {
         // Note: title is mandatory in ISO metadata, contrarily to the 
identifier.
         resource.getIdentifier().ifPresent((name) -> addTitle(new 
Sentence(name)));
-        resource.getEnvelope().ifPresent((envelope) -> {
-            try {
-                addExtent(envelope);
-            } catch (TransformException | UnsupportedOperationException e) {
-                listeners.warning(e);
-            }
-        });
+        resource.getEnvelope().ifPresent((envelope) -> addExtent(envelope, 
listeners));
     }
 
     /**
@@ -1860,16 +1854,18 @@ parse:      for (int i = 0; i < length;) {
      *   <li>{@code metadata/identificationInfo/extent/geographicElement}</li>
      * </ul>
      *
-     * @param  envelope  the extent to add in the metadata, or {@code null} 
for no-operation.
-     * @throws TransformException if an error occurred while converting the 
given envelope to extents.
+     * @param  envelope   the extent to add in the metadata, or {@code null} 
for no-operation.
+     * @param  listeners  the listeners to notify in case of warning.
      */
-    public final void addExtent(final Envelope envelope) throws 
TransformException {
+    public final void addExtent(final Envelope envelope, final StoreListeners 
listeners) {
         if (envelope != null) {
             final CoordinateReferenceSystem crs = 
envelope.getCoordinateReferenceSystem();
             addReferenceSystem(crs);
             if (!(envelope instanceof AbstractEnvelope && ((AbstractEnvelope) 
envelope).isAllNaN())) {
-                if (crs != null) {
+                if (crs != null) try {
                     extent().addElements(envelope);
+                } catch (TransformException | UnsupportedOperationException e) 
{
+                    listeners.warning(e);
                 }
                 // Future version could add as a geometry in unspecified CRS.
             }
@@ -2035,7 +2031,7 @@ parse:      for (int i = 0; i < length;) {
      * </ul>
      *
      * This method does not add the envelope provided by {@link 
GridGeometry#getEnvelope()}.
-     * That envelope appears in a separated node, which can be added by {@link 
#addExtent(Envelope)}.
+     * That envelope appears in a separated node, which can be added by {@link 
#addExtent(Envelope, StoreListeners)}.
      * This separation is required by {@link AbstractGridCoverageResource} for 
instance.
      *
      * @param  description    a general description of the "grid to CRS" 
transformation, or {@code null} if none.
diff --git 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/URIDataStore.java
 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/URIDataStore.java
index e7f4bbf143..f59126c0d3 100644
--- 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/URIDataStore.java
+++ 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/URIDataStore.java
@@ -100,6 +100,8 @@ public abstract class URIDataStore extends DataStore 
implements StoreResource, R
             locationAsPath = (Path) storage;
         } else if (storage instanceof File) {
             locationAsPath = ((File) storage).toPath();
+        } else if (storage instanceof CharSequence) {
+            locationAsPath = connector.getStorageAs(Path.class);
         }
         locationIsPath = (locationAsPath != null);
     }
diff --git 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/csv/Store.java
 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/csv/Store.java
index 3ad230072c..b1d5fede5d 100644
--- 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/csv/Store.java
+++ 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/csv/Store.java
@@ -43,7 +43,6 @@ import org.opengis.metadata.Metadata;
 import org.opengis.metadata.maintenance.ScopeCode;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.crs.TemporalCRS;
-import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.feature.DefaultAttributeType;
 import org.apache.sis.feature.DefaultFeatureType;
 import org.apache.sis.feature.FoliationRepresentation;
@@ -641,11 +640,7 @@ final class Store extends URIDataStore implements 
FeatureSet {
             }
             builder.addLanguage(Locale.ENGLISH, encoding, 
MetadataBuilder.Scope.ALL);
             builder.addResourceScope(ScopeCode.FEATURE, null);
-            try {
-                builder.addExtent(envelope);
-            } catch (TransformException e) {
-                throw new DataStoreReferencingException(getLocale(), 
StoreProvider.NAME, getDisplayName(), source).initCause(e);
-            }
+            builder.addExtent(envelope, listeners);
             builder.addFeatureType(featureType, -1);
             addTitleOrIdentifier(builder);
             builder.setISOStandards(false);
diff --git 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/esri/RasterStore.java
 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/esri/RasterStore.java
index d38591ddf1..4d22dfe327 100644
--- 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/esri/RasterStore.java
+++ 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/esri/RasterStore.java
@@ -33,7 +33,6 @@ import java.awt.image.WritableRaster;
 import org.opengis.geometry.Envelope;
 import org.opengis.metadata.Metadata;
 import org.opengis.metadata.maintenance.ScopeCode;
-import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.metadata.sql.MetadataStoreException;
 import org.apache.sis.coverage.SampleDimension;
 import org.apache.sis.coverage.grid.GridGeometry;
@@ -175,11 +174,7 @@ abstract class RasterStore extends PRJDataStore implements 
GridCoverageResource
         builder.addResourceScope(ScopeCode.COVERAGE, null);
         builder.addLanguage(Locale.ENGLISH, encoding, 
MetadataBuilder.Scope.METADATA);
         builder.addSpatialRepresentation(null, gridGeometry, true);
-        try {
-            builder.addExtent(gridGeometry.getEnvelope());
-        } catch (TransformException e) {
-            listeners.warning(e);
-        }
+        builder.addExtent(gridGeometry.getEnvelope(), listeners);
         /*
          * Do not invoke `getSampleDimensions()` because computing sample 
dimensions without statistics
          * may cause the loading of the full image. Even if 
`GridCoverage.getSampleDimensions()` exists
diff --git 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/image/WorldFileStore.java
 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/image/WorldFileStore.java
index 1e966d8ffa..6da2247bb3 100644
--- 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/image/WorldFileStore.java
+++ 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/image/WorldFileStore.java
@@ -36,7 +36,6 @@ import javax.imageio.stream.ImageInputStream;
 import org.opengis.metadata.Metadata;
 import org.opengis.metadata.maintenance.ScopeCode;
 import org.opengis.referencing.datum.PixelInCell;
-import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.coverage.grid.GridExtent;
 import org.apache.sis.coverage.grid.GridGeometry;
 import org.apache.sis.storage.Resource;
@@ -46,7 +45,6 @@ import org.apache.sis.storage.GridCoverageResource;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.storage.DataStoreClosedException;
 import org.apache.sis.storage.DataStoreContentException;
-import org.apache.sis.storage.DataStoreReferencingException;
 import org.apache.sis.storage.ReadOnlyStorageException;
 import org.apache.sis.storage.UnsupportedStorageException;
 import org.apache.sis.storage.internal.Resources;
@@ -539,15 +537,13 @@ loop:   for (int convention=0;; convention++) {
             builder.addResourceScope(ScopeCode.COVERAGE, null);
             builder.addSpatialRepresentation(null, 
getGridGeometry(MAIN_IMAGE), true);
             if (gridGeometry.isDefined(GridGeometry.ENVELOPE)) {
-                builder.addExtent(gridGeometry.getEnvelope());
+                builder.addExtent(gridGeometry.getEnvelope(), listeners);
             }
             addTitleOrIdentifier(builder);
             builder.setISOStandards(false);
             metadata = builder.buildAndFreeze();
         } catch (IOException e) {
             throw new DataStoreException(e);
-        } catch (TransformException e) {
-            throw new DataStoreReferencingException(e);
         }
         return metadata;
     }

Reply via email to