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 4e0580c9571d5bb24e91be3cc65742ec948529a6
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Sun Jun 16 09:16:17 2024 +0200

    Actually, `GeometryGetter` does not need to invoke `ByteBuffer.slice()`
    because WKB readers should start reading from current buffer position.
---
 .../main/org/apache/sis/geometry/wrapper/Geometries.java             | 1 +
 .../main/org/apache/sis/geometry/wrapper/esri/Factory.java           | 5 ++++-
 .../main/org/apache/sis/storage/sql/feature/GeometryGetter.java      | 5 ++---
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/Geometries.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/Geometries.java
index f8a4d2b039..642414422f 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/Geometries.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/Geometries.java
@@ -310,6 +310,7 @@ public abstract class Geometries<G> implements Serializable 
{
 
     /**
      * Reads the given bytes as a Well Known Binary (WKB) encoded geometry.
+     * The reading starts from the current buffer position.
      * Whether this method changes the buffer position or not is 
implementation-dependent.
      *
      * @param  data  the binary data in WKB format. Cannot be null.
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/esri/Factory.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/esri/Factory.java
index 720b09ee1e..0b513f3691 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/esri/Factory.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/esri/Factory.java
@@ -291,7 +291,10 @@ public final class Factory extends Geometries<Geometry> {
      * @return the geometry object for the given WKB.
      */
     @Override
-    public GeometryWrapper parseWKB(final ByteBuffer data) {
+    public GeometryWrapper parseWKB(ByteBuffer data) {
+        if (data.position() != 0) {
+            data = data.slice();    // ESRI implementation seems to ignore the 
position and always starts reading at 0.
+        }
         return new 
Wrapper(OperatorImportFromWkb.local().execute(WkbImportFlags.wkbImportDefaults, 
Geometry.Type.Unknown, data, null));
     }
 }
diff --git 
a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/GeometryGetter.java
 
b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/GeometryGetter.java
index 3aa316295e..451ad045b9 100644
--- 
a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/GeometryGetter.java
+++ 
b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/GeometryGetter.java
@@ -107,7 +107,7 @@ final class GeometryGetter<G, V extends G> extends 
ValueGetter<V> {
     public V getValue(final InfoStatements stmts, final ResultSet source, 
final int columnIndex) throws Exception {
         final byte[] wkb = encoding.getBytes(source, columnIndex);
         if (wkb == null) return null;
-        ByteBuffer buffer = ByteBuffer.wrap(wkb);
+        final ByteBuffer buffer = ByteBuffer.wrap(wkb);
         /*
          * The bytes should describe a geometry encoded in Well Known Binary 
(WKB) format,
          * but this implementation accepts also the Geopackage geometry 
encoding:
@@ -141,8 +141,7 @@ final class GeometryGetter<G, V extends G> extends 
ValueGetter<V> {
                 default: throw new 
DataStoreContentException(Errors.forLocale(stmts.getLocale())
                             .getString(Errors.Keys.UnexpectedValueInElement_2, 
"envelope contents indicator"));
             }
-            buffer = buffer.position(offset).slice();
-            // Result of slice is in BIG_ENDIAN.
+            buffer.position(offset).order(ByteOrder.BIG_ENDIAN);
         }
         final GeometryWrapper geom = geometryFactory.parseWKB(buffer);
         CoordinateReferenceSystem crs = defaultCRS;

Reply via email to