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 90aaa358f115c2e64a61861bd6012a28dee579e5
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Thu Apr 24 15:14:45 2025 +0200

    Clarification about the circumstances when `guessCRS` may be invoked.
---
 .../org/apache/sis/storage/sql/feature/InfoStatements.java |  8 +++++++-
 .../org/apache/sis/storage/sql/feature/QueryAnalyzer.java  | 11 +++++------
 .../org/apache/sis/storage/sql/feature/TableAnalyzer.java  | 14 ++++++++++----
 3 files changed, 22 insertions(+), 11 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/InfoStatements.java
 
b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/InfoStatements.java
index f2b5275f52..9b7981d788 100644
--- 
a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/InfoStatements.java
+++ 
b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/InfoStatements.java
@@ -378,7 +378,13 @@ public class InfoStatements implements Localized, 
AutoCloseable {
 
     /**
      * Tries to guess the <abbr>CRS</abbr> for the specified column in an 
unknown table.
-     * This is used for queries when the <abbr>JDBC</abbr> driver is 
incomplete.
+     * This is invoked (indirectly) by {@link QueryAnalyzer} when the 
<abbr>JDBC</abbr>
+     * driver is an incomplete implementation.
+     *
+     * <h4>Algorithm</h4>
+     * This method lists the <abbr>CRS</abbr> of all columns of the given name,
+     * regardless the table, schema or catalog containing a column of that 
name.
+     * If the <abbr>CRS</abbr> is equivalent in all cases, then it is returned.
      *
      * @param  column  name of the column in unknown table.
      * @return the <abbr>CRS</abbr>, or {@code null} if none or ambiguous.
diff --git 
a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/QueryAnalyzer.java
 
b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/QueryAnalyzer.java
index 6ebbd52955..d6e03faca7 100644
--- 
a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/QueryAnalyzer.java
+++ 
b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/QueryAnalyzer.java
@@ -157,10 +157,12 @@ final class QueryAnalyzer extends FeatureAnalyzer {
          * Identify geometry columns. Must be done before the calls to 
`Analyzer.setValueGetterOf(column)`.
          * If the database does not have a "geometry columns" table, parse 
field type names as a fallback.
          */
-        boolean fallback = true;
         final InfoStatements spatialInformation = analyzer.spatialInformation;
-        if (spatialInformation != null) {
-            fallback = columnsPerTable.isEmpty();
+        if (spatialInformation == null || columnsPerTable.isEmpty()) {
+            for (final Column column : columns) {
+                column.tryMakeSpatial(analyzer);
+            }
+        } else {
             for (final Map.Entry<TableReference, Map<String,Column>> entry : 
columnsPerTable.entrySet()) {
                 spatialInformation.completeIntrospection(analyzer, 
entry.getKey(), entry.getValue());
             }
@@ -170,9 +172,6 @@ final class QueryAnalyzer extends FeatureAnalyzer {
          */
         final var attributes = new ArrayList<Column>();
         for (final Column column : columns) {
-            if (fallback) {
-                column.tryMakeSpatial(analyzer);
-            }
             if (createAttribute(column)) {
                 attributes.add(column);
             }
diff --git 
a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/TableAnalyzer.java
 
b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/TableAnalyzer.java
index 28d53c2180..701ef01db7 100644
--- 
a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/TableAnalyzer.java
+++ 
b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/TableAnalyzer.java
@@ -182,15 +182,21 @@ final class TableAnalyzer extends FeatureAnalyzer {
         if (spatialInformation != null) {
             spatialInformation.completeIntrospection(analyzer, id, columns);
         }
+        /*
+         * If the database has no "geometry columns" table, tries to infer the 
geometry type
+         * from the `Column.typeName`. Note that this loop cannot resolve the 
CRS because of
+         * the absence of geometry columns.
+         */
+        if (spatialInformation == null || spatialInformation.geometryColumns 
== null) {
+            for (final Column column : columns.values()) {
+                column.tryMakeSpatial(analyzer);
+            }
+        }
         /*
          * Analyze the type of each column, which may be geometric as a 
consequence of above call.
          */
         final var attributes = new ArrayList<Column>();
         for (final Column column : columns.values()) {
-            if (spatialInformation == null || 
spatialInformation.geometryColumns == null) {
-                // Fallback for databases without "geometry columns" table.
-                column.tryMakeSpatial(analyzer);
-            }
             if (createAttribute(column)) {
                 attributes.add(column);
             }

Reply via email to