sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: The name of CRS produced by `AbstractCRS.forConvention(…)` should not contain an "EPSG" codespace.
Date Fri, 04 Sep 2020 17:50:26 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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 80afd19  The name of CRS produced by `AbstractCRS.forConvention(…)` should not
contain an "EPSG" codespace.
80afd19 is described below

commit 80afd199af33d989b04451a8dd47d9b7ca2b6d9e
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Fri Sep 4 19:41:29 2020 +0200

    The name of CRS produced by `AbstractCRS.forConvention(…)` should not contain an "EPSG"
codespace.
---
 .../org/apache/sis/coverage/grid/GridGeometry.java  |  2 +-
 .../org/apache/sis/referencing/crs/AbstractCRS.java | 21 +++++++++++++++++++--
 .../sis/referencing/crs/DefaultGeographicCRS.java   |  3 ++-
 3 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
index 07a1e30..bd89b61 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
@@ -1526,7 +1526,7 @@ public class GridGeometry implements LenientComparable, Serializable
{
                 if (id != null) {
                     buffer.append(IdentifiedObjects.toString(id)).append(" — ");
                 }
-                buffer.append(crs.getName());
+                buffer.append(crs.getName().getCode());
                 writeNode();
             }
             /*
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
index 30c7b97..432bfc9 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
@@ -18,12 +18,14 @@ package org.apache.sis.referencing.crs;
 
 import java.util.Map;
 import java.util.EnumMap;
+import java.util.HashMap;
 import java.util.Objects;
 import java.util.ConcurrentModificationException;
 import javax.measure.Unit;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlSeeAlso;
+import org.opengis.metadata.Identifier;
 import org.opengis.referencing.datum.Datum;
 import org.opengis.referencing.cs.AffineCS;
 import org.opengis.referencing.cs.CartesianCS;
@@ -35,6 +37,7 @@ import org.apache.sis.internal.referencing.ReferencingUtilities;
 import org.apache.sis.internal.metadata.MetadataUtilities;
 import org.apache.sis.referencing.AbstractReferenceSystem;
 import org.apache.sis.referencing.IdentifiedObjects;
+import org.apache.sis.referencing.NamedIdentifier;
 import org.apache.sis.referencing.cs.AxesConvention;
 import org.apache.sis.referencing.cs.AbstractCS;
 import org.apache.sis.util.ComparisonMode;
@@ -78,7 +81,7 @@ import static org.apache.sis.internal.referencing.WKTUtilities.toFormattable;
  * without synchronization.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
- * @version 0.7
+ * @version 1.1
  *
  * @see AbstractCS
  * @see org.apache.sis.referencing.datum.AbstractDatum
@@ -336,7 +339,21 @@ public class AbstractCRS extends AbstractReferenceSystem implements CoordinateRe
             if (candidate == cs) {
                 crs = this;
             } else {
-                crs = createSameType(IdentifiedObjects.getProperties(this, IDENTIFIERS_KEY),
candidate);
+                /*
+                 * Copy properties (scope, domain of validity) except the identifier (e.g.
"EPSG:4326")
+                 * because the modified CRS is no longer conform to the authoritative definition.
+                 * If name contains a namespace (e.g. "EPSG"), remove that namespace for
the same reason.
+                 * For example "EPSG:WGS 84" will become simply "WGS 84".
+                 */
+                Map<String,?> properties = IdentifiedObjects.getProperties(this, IDENTIFIERS_KEY);
+                Identifier name = getName();
+                if (name.getCodeSpace() != null || name.getAuthority() != null) {
+                    name = new NamedIdentifier(null, name.getCode());
+                    final Map<String,Object> copy = new HashMap<>(properties);
+                    copy.put(NAME_KEY, name);
+                    properties = copy;
+                }
+                crs = createSameType(properties, candidate);
             }
             crs = setCached(convention, crs);
         }
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
index 44ce788..b6f8bf1 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
@@ -95,6 +95,7 @@ import static org.apache.sis.internal.util.Constants.CRS84;
 public class DefaultGeographicCRS extends DefaultGeodeticCRS implements GeographicCRS {
     /**
      * Some codes in the EPSG namespace, in ascending order.
+     * Used for mapping to {@link #CRS_CODES}.
      */
     private static final short[] EPSG_CODES = {4267, 4269, 4326};
 
@@ -256,7 +257,7 @@ public class DefaultGeographicCRS extends DefaultGeodeticCRS implements
Geograph
     final AbstractCRS createSameType(Map<String,?> properties, final CoordinateSystem
cs) {
         final CoordinateSystemAxis axis = cs.getAxis(0);
         if (axis.getMinimumValue() == Longitude.MIN_VALUE &&
-            axis.getMaximumValue() == Longitude.MAX_VALUE) // For excluding the AxesConvention.POSITIVE_RANGE
case.
+            axis.getMaximumValue() == Longitude.MAX_VALUE)    // For excluding the AxesConvention.POSITIVE_RANGE
case.
         {
             for (final Identifier identifier : super.getIdentifiers()) {
                 if (EPSG.equals(identifier.getCodeSpace())) try {


Mime
View raw message