sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1802928 - in /sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal: Proj4Factory.java Proj4Parser.java
Date Tue, 25 Jul 2017 12:45:03 GMT
Author: desruisseaux
Date: Tue Jul 25 12:45:03 2017
New Revision: 1802928

URL: http://svn.apache.org/viewvc?rev=1802928&view=rev
Log:
Fix the Coordinate Reference System name by creating it from the datum name (if available)
and the projection code.

Modified:
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Factory.java
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Parser.java

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Factory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Factory.java?rev=1802928&r1=1802927&r2=1802928&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Factory.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Factory.java
[UTF-8] Tue Jul 25 12:45:03 2017
@@ -103,6 +103,11 @@ public class Proj4Factory extends Geodet
     static final String AXIS_ORDER_PARAM = "+axis=";
 
     /**
+     * The name to use when no specific name were found for an object.
+     */
+    static final String UNNAMED = "Unnamed";
+
+    /**
      * The default factory instance.
      */
     static final Proj4Factory INSTANCE = new Proj4Factory();
@@ -523,7 +528,7 @@ public class Proj4Factory extends Geodet
     private Map<String,Object> identifier(final String code) {
         Identifier id = identifiers.computeIfAbsent(code, (k) -> {
             short i18n = 0;
-            if (k.equalsIgnoreCase("Unnamed")) i18n = Vocabulary.Keys.Unnamed;
+            if (k.equalsIgnoreCase( UNNAMED )) i18n = Vocabulary.Keys.Unnamed;
             if (k.equalsIgnoreCase("Unknown")) i18n = Vocabulary.Keys.Unknown;
             return new ImmutableIdentifier(Citations.PROJ4, Constants.PROJ4, k, null,
                     (i18n != 0) ? Vocabulary.formatInternational(i18n) : null);
@@ -546,11 +551,11 @@ public class Proj4Factory extends Geodet
         if (greenwichLongitude == 0) {
             pm = CommonCRS.WGS84.datum().getPrimeMeridian();
         } else {
-            pm = datumFactory.createPrimeMeridian(identifier("Unnamed"), greenwichLongitude,
Units.DEGREE);
+            pm = datumFactory.createPrimeMeridian(identifier(UNNAMED), greenwichLongitude,
Units.DEGREE);
         }
         final double[] def = pj.getEllipsoidDefinition();
-        return datumFactory.createGeodeticDatum(identifier(parser.value("datum", "Unnamed")),
-               datumFactory.createEllipsoid    (identifier(parser.value("ellps", "Unnamed")),
+        return datumFactory.createGeodeticDatum(identifier(parser.value("datum", UNNAMED)),
+               datumFactory.createEllipsoid    (identifier(parser.value("ellps", UNNAMED)),
                     def[0],                             // Semi-major axis length
                     def[0] * Math.sqrt(1 - def[1]),     // Semi-minor axis length
                     Units.METRE), pm);
@@ -597,8 +602,8 @@ public class Proj4Factory extends Geodet
          * will be stored as the CRS identifier for allowing OperationFactory to get it back
before to
          * attempt to create a new one for a given CRS.
          */
-        final Map<String,Object> csName = identifier("Unnamed");
-        final Map<String,Object> name = new HashMap<>(identifier(String.valueOf(pj.getDescription())));
+        final Map<String,Object> csName = identifier(UNNAMED);
+        final Map<String,Object> name = new HashMap<>(identifier(parser.name(type
== PJ.Type.PROJECTED)));
         name.put(CoordinateReferenceSystem.IDENTIFIERS_KEY, pj);
         switch (type) {
             case GEOGRAPHIC: {
@@ -748,7 +753,7 @@ public class Proj4Factory extends Geodet
         final Transform tr = new Transform(source, is3D("sourceCRS", sourceCRS),
                                            target, is3D("targetCRS", targetCRS));
         Identifier id;
-        String src = null, tgt = null, name = "Unnamed";
+        String src = null, tgt = null, name = UNNAMED;
         if ((id = sourceCRS.getName()) != null) src = id.getCode();
         if ((id = targetCRS.getName()) != null) tgt = id.getCode();
         if (src != null || tgt != null) {

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Parser.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Parser.java?rev=1802928&r1=1802927&r2=1802928&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Parser.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Parser.java
[UTF-8] Tue Jul 25 12:45:03 2017
@@ -90,9 +90,11 @@ final class Proj4Parser {
             if (end >= 0 && (next < 0 || end < next)) {
                 final String keyword = CharSequences.trimWhitespaces(definition, start, end).toString().toLowerCase(Locale.US);
                 final String value   = CharSequences.trimWhitespaces(definition, end+1, (next
>= 0) ? next : length).toString();
-                final String old = parameters.put(keyword, value);
-                if (old != null && !old.equals(value)) {
-                    throw new InvalidGeodeticParameterException(Errors.format(Errors.Keys.DuplicatedElement_1,
keyword));
+                if (!value.isEmpty()) {
+                    final String old = parameters.put(keyword, value);
+                    if (old != null && !old.equals(value)) {
+                        throw new InvalidGeodeticParameterException(Errors.format(Errors.Keys.DuplicatedElement_1,
keyword));
+                    }
                 }
             }
             start = next;
@@ -100,12 +102,32 @@ final class Proj4Parser {
     }
 
     /**
+     * Returns a suggested name for the coordinate reference system object to build.
+     */
+    final String name(final boolean isProjected) {
+        String name = parameters.get("datum");
+        if (name == null) {
+            name = parameters.get("ellps");
+            if (name == null) {
+                name = Proj4Factory.UNNAMED;
+            }
+        }
+        if (isProjected) {
+            final String proj = parameters.get(PROJ);
+            if (proj != null) {
+                name = name + ' ' + Proj4Factory.PROJ_PARAM + proj;
+            }
+        }
+        return name;
+    }
+
+    /**
      * Returns the parameter value for the given keyword, or the given default value if none.
      * The parameter value is removed from the map.
      */
     final String value(final String keyword, final String defaultValue) {
         final String value = parameters.remove(keyword);
-        return (value != null && !value.isEmpty()) ? value : defaultValue;
+        return (value != null) ? value : defaultValue;
     }
 
     /**
@@ -133,11 +155,8 @@ final class Proj4Parser {
         for (final Map.Entry<String,String> entry : parameters.entrySet()) {
             final String keyword = entry.getKey();
             if (!EXCLUDES.contains(keyword)) {
-                final String v = entry.getValue();
-                if (!v.isEmpty()) {
-                    final ParameterValue<?> value = pg.parameter(keyword);
-                    value.setValue(Double.parseDouble(v));
-                }
+                final ParameterValue<?> value = pg.parameter(keyword);
+                value.setValue(Double.parseDouble(entry.getValue()));
             }
         }
         return pg;
@@ -154,11 +173,11 @@ final class Proj4Parser {
      */
     final Unit<?> unit(final boolean vertical) throws ParserException {
         String v = parameters.remove(vertical ? "vto_meter" : "to_meter");
-        if (v != null && !v.isEmpty()) {
+        if (v != null) {
             return Units.METRE.divide(Double.parseDouble(v));
         }
         v = parameters.remove(vertical ? "vunits" : "units");
-        if (v != null && !v.isEmpty()) {
+        if (v != null) {
             return Units.valueOf(v);
         }
         return Units.METRE;



Mime
View raw message