sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 02/02: Add `GeometryWrapper.getSRID()` method.
Date Thu, 15 Jul 2021 16:05:25 GMT
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 9c03b4f439cfbdca16f8d52dc10a3db950f7a050
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu Jul 15 11:27:05 2021 +0200

    Add `GeometryWrapper.getSRID()` method.
---
 .../apache/sis/internal/feature/GeometryWrapper.java | 20 ++++++++++++++++++++
 .../org/apache/sis/internal/feature/jts/Wrapper.java | 13 +++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/GeometryWrapper.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/GeometryWrapper.java
index 1b03e97..cbfb5c4 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/GeometryWrapper.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/GeometryWrapper.java
@@ -19,6 +19,7 @@ package org.apache.sis.internal.feature;
 import java.util.Set;
 import java.util.Objects;
 import java.util.Iterator;
+import java.util.OptionalInt;
 import javax.measure.Unit;
 import javax.measure.Quantity;
 import javax.measure.quantity.Length;
@@ -91,6 +92,25 @@ public abstract class GeometryWrapper<G> extends AbstractGeometry
implements Geo
     public abstract Object implementation();
 
     /**
+     * Returns the Spatial Reference System Identifier (SRID) if available.
+     * The SRID is used in database such as PostGIS and is generally database-dependent.
+     * This is <em>not</em> necessarily an EPSG code, even it is common practice
to use
+     * the same numerical values than EPSG. Note that the absence of SRID does not mean
+     * that {@link #getCoordinateReferenceSystem()} would return no CRS.
+     *
+     * <p>Users should invoke the {@link #getCoordinateReferenceSystem()} method instead.
+     * This {@code getSRID()} method is provided for classes such as {@code DataStore} backed
by an SQL database.
+     * Those classes have a connection to a {@code "spatial_ref_sys} table providing the
mapping from SRID codes
+     * to authority codes such as EPSG. Those {@code DataStore} will typically get the SRID
soon after geometry
+     * creation, resolves its CRS and invoke {@link #setCoordinateReferenceSystem(CoordinateReferenceSystem)}.</p>
+     *
+     * @return the Spatial Reference System Identifier of the geometry.
+     */
+    public OptionalInt getSRID() {
+        return OptionalInt.empty();
+    }
+
+    /**
      * Gets the Coordinate Reference System (CRS) of this geometry. In some libraries (for
example JTS) the CRS
      * is stored in the {@link Geometries#rootClass} instances of that library. In other
libraries (e.g. Java2D)
      * the CRS is stored only in this {@code GeometryWrapper} instance.
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/Wrapper.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/Wrapper.java
index cbf90b9..c68bafb 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/Wrapper.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/Wrapper.java
@@ -20,6 +20,7 @@ import java.util.List;
 import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.OptionalInt;
 import java.util.function.BiFunction;
 import java.util.function.BiPredicate;
 import java.util.function.IntFunction;
@@ -116,6 +117,18 @@ final class Wrapper extends GeometryWrapper<Geometry> {
     }
 
     /**
+     * Returns the Spatial Reference System Identifier (SRID) if available.
+     * This is <em>not</em> necessarily an EPSG code, even it is common practice
to use
+     * the same numerical values than EPSG. Note that the absence of SRID does not mean
+     * that {@link #getCoordinateReferenceSystem()} would return no CRS.
+     */
+    @Override
+    public OptionalInt getSRID() {
+        final int srid = geometry.getSRID();
+        return (srid != 0) ? OptionalInt.of(srid) : OptionalInt.empty();
+    }
+
+    /**
      * Returns the geometry coordinate reference system, or {@code null} if none.
      *
      * @return the coordinate reference system, or {@code null} if none.

Mime
View raw message