You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2022/12/07 17:36:34 UTC

[sis] branch geoapi-4.0 updated (d438a0d1b6 -> e2c3b3af00)

This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a change to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


    from d438a0d1b6 Fix JUnit test failures when the tests are run without EPSG database.
     new f51c551462 Fix test failure when running tests on PostgreSQL without EPSG dataset.
     new fa02d98217 Add missing component file (HDR) for ESRI RAW format.
     new e2c3b3af00 Fix a `ClassCastException` and an `EOFException`. The latter was caused by wrong `ChannelData.channelOffset` value.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../sis/gui/metadata/StandardMetadataTree.java      |  2 +-
 .../org/apache/sis/metadata/MetadataStandard.java   | 10 +++++-----
 .../report/CoordinateOperationMethods.java          |  4 ++--
 .../internal/sql/feature/GeometryGetterTest.java    | 19 ++++++++++++++-----
 .../sis/internal/sql/postgis/PostgresTest.java      | 21 ++++++++++++++++-----
 .../sis/internal/storage/esri/RasterStore.java      |  2 +-
 .../sis/internal/storage/esri/RawRasterStore.java   | 12 ++++++++++++
 .../apache/sis/internal/storage/io/ChannelData.java | 16 ++++++++++++++++
 .../sis/internal/storage/io/ChannelDataInput.java   | 12 ++++++++++++
 .../storage/io/ChannelImageInputStream.java         |  6 +++---
 10 files changed, 82 insertions(+), 22 deletions(-)


[sis] 01/03: Fix test failure when running tests on PostgreSQL without EPSG dataset.

Posted by de...@apache.org.
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 f51c5514629837509983e71111d98a12e276b28c
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Dec 7 14:05:10 2022 +0100

    Fix test failure when running tests on PostgreSQL without EPSG dataset.
---
 .../report/CoordinateOperationMethods.java          |  4 ++--
 .../internal/sql/feature/GeometryGetterTest.java    | 19 ++++++++++++++-----
 .../sis/internal/sql/postgis/PostgresTest.java      | 21 ++++++++++++++++-----
 3 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateOperationMethods.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateOperationMethods.java
index ac5e31516f..22313e785d 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateOperationMethods.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateOperationMethods.java
@@ -68,7 +68,7 @@ import org.opengis.metadata.Identifier;
  * first, no HTML characters to escape in non-EPSG identifiers, etc.).</p>
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.1
+ * @version 1.3
  * @since   0.6
  * @module
  */
@@ -556,7 +556,7 @@ public strictfp class CoordinateOperationMethods extends HTMLGenerator {
         if (id == null) {
             id = method.getName().getCode();
         }
-        return id.replace(" ", "_");
+        return id.replace(" ", "_").replace("(", "").replace(")", "");
     }
 
     /**
diff --git a/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/GeometryGetterTest.java b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/GeometryGetterTest.java
index 95ccb22d9b..3657071482 100644
--- a/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/GeometryGetterTest.java
+++ b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/feature/GeometryGetterTest.java
@@ -22,6 +22,7 @@ import java.sql.Statement;
 import java.sql.ResultSet;
 import org.opengis.util.FactoryException;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.NoSuchAuthorityCodeException;
 import org.apache.sis.internal.feature.Geometries;
 import org.apache.sis.internal.feature.GeometryWrapper;
 import org.apache.sis.internal.feature.GeometryWithCRS;
@@ -43,7 +44,7 @@ import static org.junit.Assert.*;
  *
  * @author  Alexis Manin (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.2
+ * @version 1.3
  * @since   1.1
  * @module
  */
@@ -144,8 +145,10 @@ public strictfp final class GeometryGetterTest extends TestCase {
                 final Geometry geometry = (Geometry) reader.getValue(fromSridToCRS, results, 2);
                 final GeometryWrapper<?> expected = GF.parseWKT(wkt);
                 assertEquals("WKT and WKB parsings gave different results.", expected.implementation(), geometry);
-                assertSame("SRID", getExpectedCRS(results.getInt(3)),
-                           GF.castOrWrap(geometry).getCoordinateReferenceSystem());
+                final CoordinateReferenceSystem expectedCRS = getExpectedCRS(results.getInt(3));
+                if (expectedCRS != null) {
+                    assertSame("SRID", expectedCRS, GF.castOrWrap(geometry).getCoordinateReferenceSystem());
+                }
             }
         }
     }
@@ -157,14 +160,20 @@ public strictfp final class GeometryGetterTest extends TestCase {
      * used for the test. Other databases may have different mapping.
      *
      * @param  srid  the SRID for which to get the CRS.
-     * @return the CRS for the given SRID.
+     * @return the CRS for the given SRID, or {@code null} if not available.
      * @throws FactoryException if an error occurred while fetching the CRS.
      */
     public static CoordinateReferenceSystem getExpectedCRS(final int srid) throws FactoryException {
+        final String code;
         switch (srid) {
-            case 3395: return CRS.forCode("EPSG:3395");
+            case 3395: code = "EPSG:3395"; break;
             case 4326: return CommonCRS.WGS84.normalizedGeographic();
             default:   throw new AssertionError(srid);
         }
+        try {
+            return CRS.forCode(code);
+        } catch (NoSuchAuthorityCodeException ignore) {
+            return null;     // No EPSG database available.
+        }
     }
 }
diff --git a/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/postgis/PostgresTest.java b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/postgis/PostgresTest.java
index abcf98d4f1..0c86f82300 100644
--- a/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/postgis/PostgresTest.java
+++ b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/postgis/PostgresTest.java
@@ -26,6 +26,8 @@ import java.lang.reflect.Method;
 import java.util.stream.Stream;
 import org.opengis.geometry.Envelope;
 import org.opengis.util.FactoryException;
+import org.opengis.referencing.crs.ProjectedCRS;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.apache.sis.setup.OptionKey;
 import org.apache.sis.setup.GeometryLibrary;
 import org.apache.sis.storage.FeatureSet;
@@ -39,7 +41,6 @@ import org.apache.sis.internal.storage.io.ChannelDataInput;
 import org.apache.sis.internal.sql.feature.BinaryEncoding;
 import org.apache.sis.internal.sql.feature.GeometryGetterTest;
 import org.apache.sis.internal.feature.jts.JTS;
-import org.apache.sis.referencing.CRS;
 import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.referencing.crs.HardCodedCRS;
 import org.apache.sis.test.sql.TestDatabase;
@@ -55,7 +56,7 @@ import org.opengis.feature.Feature;
 import org.locationtech.jts.geom.Point;
 import org.locationtech.jts.geom.Geometry;
 
-import static org.junit.Assert.*;
+import static org.opengis.test.Assert.*;
 
 
 /**
@@ -63,7 +64,7 @@ import static org.junit.Assert.*;
  *
  * @author  Alexis Manin (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.2
+ * @version 1.3
  * @since   1.1
  * @module
  */
@@ -128,7 +129,12 @@ public final strictfp class PostgresTest extends TestCase {
      */
     private static void testInfoStatements(final ExtendedInfo info) throws Exception {
         assertEquals("findSRID", 4326, info.findSRID(HardCodedCRS.WGS84));
-        assertSame("fetchCRS", CRS.forCode("EPSG:3395"), info.fetchCRS(3395));
+        final CoordinateReferenceSystem expected = GeometryGetterTest.getExpectedCRS(3395);
+        final CoordinateReferenceSystem actual   = info.fetchCRS(3395);
+        assertInstanceOf("findSRID", ProjectedCRS.class, actual);
+        if (expected != null) {
+            assertSame("fetchCRS", expected, actual);
+        }
     }
 
     /**
@@ -192,7 +198,12 @@ public final strictfp class PostgresTest extends TestCase {
             default: throw new AssertionError(filename);
         }
         try {
-            assertEquals(GeometryGetterTest.getExpectedCRS(geomSRID), JTS.getCoordinateReferenceSystem(geometry));
+            final CoordinateReferenceSystem expected = GeometryGetterTest.getExpectedCRS(geomSRID);
+            final CoordinateReferenceSystem actual = JTS.getCoordinateReferenceSystem(geometry);
+            assertNotNull(actual);
+            if (expected != null) {
+                assertEquals(expected, actual);
+            }
         } catch (FactoryException e) {
             throw new AssertionError(e);
         }


[sis] 03/03: Fix a `ClassCastException` and an `EOFException`. The latter was caused by wrong `ChannelData.channelOffset` value.

Posted by de...@apache.org.
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 e2c3b3af00e1c4f28574719a6d634fd36f8df5ae
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Dec 7 18:30:25 2022 +0100

    Fix a `ClassCastException` and an `EOFException`.
    The latter was caused by wrong `ChannelData.channelOffset` value.
---
 .../apache/sis/gui/metadata/StandardMetadataTree.java    |  2 +-
 .../java/org/apache/sis/metadata/MetadataStandard.java   | 10 +++++-----
 .../org/apache/sis/internal/storage/io/ChannelData.java  | 16 ++++++++++++++++
 .../apache/sis/internal/storage/io/ChannelDataInput.java | 12 ++++++++++++
 .../sis/internal/storage/io/ChannelImageInputStream.java |  6 +++---
 5 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/StandardMetadataTree.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/StandardMetadataTree.java
index ea4acb7a42..98963bd146 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/StandardMetadataTree.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/StandardMetadataTree.java
@@ -106,7 +106,7 @@ public class StandardMetadataTree extends MetadataTree {
             tree = ((AbstractMetadata) metadata).asTreeTable();
         } else {
             // `COMPACT` is the default policy of `AbstractMetadata.asTreeTable()`.
-            tree = MetadataStandard.ISO_19115.asTreeTable(metadata, null, ValueExistencePolicy.COMPACT);
+            tree = MetadataStandard.ISO_19115.asTreeTable(metadata, Metadata.class, ValueExistencePolicy.COMPACT);
         }
         setContent(tree);
     }
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
index e931ee9325..88a2d59c1f 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
@@ -442,7 +442,7 @@ public class MetadataStandard implements Serializable {
         }
         /*
          * At this point, all cached values (including those in dependencies) have been checked.
-         * Performs the 'findInterface' computation only in last resort. Current implementation
+         * Performs the `findInterface(…)` computation only in last resort. Current implementation
          * does not store negative results in order to avoid filling the cache with unrelated classes.
          */
         final Class<?> standardType = findInterface(key);
@@ -489,7 +489,7 @@ public class MetadataStandard implements Serializable {
             }
         } else {
             /*
-             * Gets every interfaces from the supplied package in declaration order,
+             * Gets every interfaces from the supplied class in declaration order,
              * including the ones declared in the super-class.
              */
             final Set<Class<?>> interfaces = new LinkedHashSet<>();
@@ -517,7 +517,7 @@ public class MetadataStandard implements Serializable {
                 }
                 /*
                  * Found more than one interface; we don't know which one to pick.
-                 * Returns 'null' for now; the caller will thrown an exception.
+                 * Returns `null` for now; the caller will thrown an exception.
                  */
             } else if (IMPLEMENTATION_CAN_ALTER_API) {
                 /*
@@ -1049,7 +1049,7 @@ public class MetadataStandard implements Serializable {
             }
         } else {
             /*
-             * If we get here, a cycle has been found. Returns 'true' in order to allow the caller to continue
+             * If we get here, a cycle has been found. Returns `true` in order to allow the caller to continue
              * comparing other properties. It is okay because someone else is comparing those two same objects,
              * and that later comparison will do the actual check for property values.
              */
@@ -1074,7 +1074,7 @@ public class MetadataStandard implements Serializable {
             final Integer hash = HashCode.getOrCreate().walk(this, null, metadata, true);
             if (hash != null) return hash;
             /*
-             * 'hash' may be null if a cycle has been found. Example: A depends on B which depends on A,
+             * `hash` may be null if a cycle has been found. Example: A depends on B which depends on A,
              * in which case the null value is returned for the second occurrence of A (not the first one).
              * We cannot compute a hash code value here, but it should be okay since that metadata is part
              * of a bigger metadata object, and that enclosing object should have other properties for computing
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/ChannelData.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/ChannelData.java
index aca1c0db2b..cc4150ea86 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/ChannelData.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/ChannelData.java
@@ -125,6 +125,22 @@ public abstract class ChannelData implements Markable {
         this.channelOffset = (channel instanceof SeekableByteChannel) ? ((SeekableByteChannel) channel).position() : 0;
     }
 
+    /**
+     * Creates a new instance from the given {@code ChannelData}.
+     * This constructor is invoked when we need to change the implementation class.
+     * The old {@code ChannelData} should not be used anymore after this constructor.
+     *
+     * @param  old  the existing instance from which to takes the channel and buffer.
+     */
+    ChannelData(final ChannelData old) {
+        filename      = old.filename;
+        buffer        = old.buffer;
+        channelOffset = old.channelOffset;
+        bufferOffset  = old.bufferOffset;
+        bitPosition   = old.bitPosition;
+        mark          = old.mark;
+    }
+
     /**
      * Creates a new instance for a buffer filled with the bytes to use.
      * This constructor uses an independent, read-only view of the given buffer.
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/ChannelDataInput.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/ChannelDataInput.java
index 314f2decc3..99e54c8be8 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/ChannelDataInput.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/ChannelDataInput.java
@@ -106,6 +106,18 @@ public class ChannelDataInput extends ChannelData {
         }
     }
 
+    /**
+     * Creates a new input stream from the given {@code ChannelDataInput}.
+     * This constructor is invoked when we need to change the implementation class.
+     * The old input should not be used anymore after this constructor has been invoked.
+     *
+     * @param  input  the existing instance from which to takes the channel and buffer.
+     */
+    ChannelDataInput(final ChannelDataInput input) {
+        super(input);
+        channel = input.channel;
+    }
+
     /**
      * Creates a new instance for a buffer filled with the bytes to use.
      * This constructor uses an independent, read-only view of the given buffer.
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/ChannelImageInputStream.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/ChannelImageInputStream.java
index 00ca785041..a2b26a6c3d 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/ChannelImageInputStream.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/ChannelImageInputStream.java
@@ -84,12 +84,12 @@ public class ChannelImageInputStream extends ChannelDataInput implements ImageIn
      * Creates a new input stream from the given {@code ChannelDataInput}.
      * This constructor is invoked when we need to change the implementation class
      * from {@code ChannelDataInput} to {@code ChannelImageInputStream}.
+     * The old input should not be used anymore after this constructor has been invoked.
      *
      * @param  input  the existing instance from which to takes the channel and buffer.
-     * @throws IOException if an error occurred while reading the channel.
      */
-    public ChannelImageInputStream(final ChannelDataInput input) throws IOException {
-        super(input.filename, input.channel, input.buffer, true);
+    public ChannelImageInputStream(final ChannelDataInput input) {
+        super(input);
     }
 
     /**


[sis] 02/03: Add missing component file (HDR) for ESRI RAW format.

Posted by de...@apache.org.
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 fa02d98217c948efd2c1d2a219590334934998ab
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Dec 7 15:25:40 2022 +0100

    Add missing component file (HDR) for ESRI RAW format.
---
 .../org/apache/sis/internal/storage/esri/RasterStore.java    |  2 +-
 .../org/apache/sis/internal/storage/esri/RawRasterStore.java | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/esri/RasterStore.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/esri/RasterStore.java
index fba0839862..460a8931ed 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/esri/RasterStore.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/esri/RasterStore.java
@@ -95,7 +95,7 @@ abstract class RasterStore extends PRJDataStore implements GridCoverageResource
      *
      * @see #getComponentFiles()
      */
-    private static final String STX = "stx", CLR = "clr";
+    static final String STX = "stx", CLR = "clr";
 
     /**
      * The color model, created from the {@code "*.clr"} file content when first needed.
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/esri/RawRasterStore.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/esri/RawRasterStore.java
index 6e90480e80..7af2e2f21b 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/esri/RawRasterStore.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/esri/RawRasterStore.java
@@ -19,6 +19,7 @@ package org.apache.sis.internal.storage.esri;
 import java.util.List;
 import java.util.Locale;
 import java.io.IOException;
+import java.nio.file.Path;
 import java.nio.ByteOrder;
 import java.awt.image.DataBuffer;
 import java.awt.image.SampleModel;
@@ -191,6 +192,17 @@ final class RawRasterStore extends RasterStore {
         input = connector.commit(ChannelDataInput.class, RawRasterStoreProvider.NAME);
     }
 
+    /**
+     * Returns the {@linkplain #location} as a {@code Path} component together with auxiliary files.
+     *
+     * @return the main file and auxiliary files as paths, or an empty array if unknown.
+     * @throws DataStoreException if the URI cannot be converted to a {@link Path}.
+     */
+    @Override
+    public Path[] getComponentFiles() throws DataStoreException {
+        return listComponentFiles(RawRasterStoreProvider.HDR, PRJ, STX, CLR);
+    }
+
     /**
      * Returns the metadata associated to the raw binary file.
      *