sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1802826 - in /sis/branches/JDK8: core/sis-referencing/src/main/java/org/apache/sis/referencing/ core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ core/sis-utility/src/main/java/org/apache/sis/util/resources/ storage/si...
Date Mon, 24 Jul 2017 15:10:44 GMT
Author: desruisseaux
Date: Mon Jul 24 15:10:43 2017
New Revision: 1802826

URL: http://svn.apache.org/viewvc?rev=1802826&view=rev
Log:
Add integration test and documentation about use of CRS in "Proj4::" namespace.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJ.java
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4.java
    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/package-info.java
    sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/IntegrationTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java?rev=1802826&r1=1802825&r2=1802826&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
[UTF-8] Mon Jul 24 15:10:43 2017
@@ -187,6 +187,8 @@ public final class CRS extends Static {
      *
      * Note that the {@link IdentifiedObjects#lookupURN(IdentifiedObject, Citation)}
      * method can be seen as a converse of this method.
+     * More codes may also be supported depending on which extension modules are available.
+     * See for example the {@linkplain org.apache.sis.storage.gdal bindings to Proj.4 library}.
      *
      * @param  code  the authority code.
      * @return the Coordinate Reference System for the given authority code.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java?rev=1802826&r1=1802825&r2=1802826&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
[UTF-8] Mon Jul 24 15:10:43 2017
@@ -778,6 +778,9 @@ public class MultiAuthoritiesFactory ext
             end = CharSequences.skipTrailingWhitespaces(code, start, afterVersion);
             version = (start < end && !code.regionMatches(start, DefinitionURI.NO_VERSION,
0,
                     DefinitionURI.NO_VERSION.length())) ? code.substring(start, end) : null;
+            if (version != null && !Character.isUnicodeIdentifierPart(version.codePointAt(0)))
{
+                throw new NoSuchAuthorityCodeException(Errors.format(Errors.Keys.InvalidVersionIdentifier_1,
version), authority, code);
+            }
             /*
              * Separate the code from the authority and the version.
              */

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1802826&r1=1802825&r2=1802826&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] Mon Jul 24 15:10:43 2017
@@ -464,6 +464,11 @@ public final class Errors extends Indexe
         public static final short InsufficientArgumentSize_3 = 74;
 
         /**
+         * “{0}” is an invalid version identifier.
+         */
+        public static final short InvalidVersionIdentifier_1 = 179;
+
+        /**
          * A different value is already associated to the “{0}” key.
          */
         public static final short KeyCollision_1 = 75;

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1802826&r1=1802825&r2=1802826&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] Mon Jul 24 15:10:43 2017
@@ -103,6 +103,7 @@ IndexOutOfBounds_1                = Inde
 IndicesOutOfBounds_2              = Indices ({0}, {1}) are out of bounds.
 InfiniteArgumentValue_1           = Argument \u2018{0}\u2019 can not take an infinite value.
 InsufficientArgumentSize_3        = Argument \u2018{0}\u2019 shall contain at least {1} elements.
A number of {2} is insufficient.
+InvalidVersionIdentifier_1        = \u201c{0}\u201d is an invalid version identifier.
 KeyCollision_1                    = A different value is already associated to the \u201c{0}\u201d
key.
 MandatoryAttribute_2              = Attribute \u201c{0}\u201d is mandatory for an object
of type \u2018{1}\u2019.
 MismatchedArrayLengths            = Mismatched array lengths.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1802826&r1=1802825&r2=1802826&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] Mon Jul 24 15:10:43 2017
@@ -100,6 +100,7 @@ IndexOutOfBounds_1                = L\u2
 IndicesOutOfBounds_2              = Les index ({0}, {1}) sont en dehors des limites permises.
 InfiniteArgumentValue_1           = L\u2019argument \u2018{0}\u2019 ne peut pas prendre une
valeur infinie.
 InsufficientArgumentSize_3        = L\u2019argument \u2018{0}\u2019 doit contenir au moins
{1} \u00e9l\u00e9ments. Un nombre de {2} est insuffisant.
+InvalidVersionIdentifier_1        = \u00ab\u202f{0}\u202f\u00bb n\u2019est pas un identifiant
de version valide.
 KeyCollision_1                    = Une valeur diff\u00e9rente est d\u00e9j\u00e0 associ\u00e9e
\u00e0 la cl\u00e9 \u00ab\u202f{0}\u202f\u00bb.
 MandatoryAttribute_2              = L\u2019attribut \u00ab\u202f{0}\u202f\u00bb est obligatoire
pour un objet de type \u2018{1}\u2019.
 MismatchedArrayLengths            = Les dimensions des tableaux ne correspondent pas.

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJ.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJ.java?rev=1802826&r1=1802825&r2=1802826&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJ.java [UTF-8]
(original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJ.java [UTF-8]
Mon Jul 24 15:10:43 2017
@@ -426,18 +426,11 @@ final class PJ implements Identifier, Se
          * from the {@literal Proj.4} definition string.
          */
         protected final Object readResolve() throws ObjectStreamException {
-            final String message;
-            final Throwable cause;
             try {
                 return new PJ(definition);
-            } catch (UnsatisfiedLinkError | NoClassDefFoundError e) {
-                message = Proj4.unavailable();
-                cause = e;
-            } catch (InvalidGeodeticParameterException e) {
-                message = e.getLocalizedMessage();
-                cause = e;
+            } catch (UnsatisfiedLinkError | NoClassDefFoundError | InvalidGeodeticParameterException
e) {
+                throw (InvalidObjectException) new InvalidObjectException(Proj4.unavailable(e)).initCause(e);
             }
-            throw (InvalidObjectException) new InvalidObjectException(message).initCause(cause);
         }
     }
 

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4.java?rev=1802826&r1=1802825&r2=1802826&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4.java
[UTF-8] Mon Jul 24 15:10:43 2017
@@ -312,7 +312,7 @@ public final class Proj4 extends Static
         try {
             return Proj4Factory.INSTANCE.createCRS(definition, dimension >= 3);
         } catch (UnsatisfiedLinkError | NoClassDefFoundError e) {
-            throw new UnavailableFactoryException(unavailable(), e);
+            throw new UnavailableFactoryException(unavailable(e), e);
         }
     }
 
@@ -362,14 +362,18 @@ public final class Proj4 extends Static
         try {
             return Proj4Factory.INSTANCE.createOperation(sourceCRS, targetCRS, force);
         } catch (UnsatisfiedLinkError | NoClassDefFoundError e) {
-            throw new UnavailableFactoryException(unavailable(), e);
+            throw new UnavailableFactoryException(unavailable(e), e);
         }
     }
 
     /**
      * Returns the error message for a {@literal Proj.4} not found.
      */
-    static String unavailable() {
-        return Errors.format(Errors.Keys.NativeInterfacesNotFound_2, OS.uname(), "libproj");
+    static String unavailable(final Throwable e) {
+        String message = e.getLocalizedMessage();
+        if (message == null || message.indexOf(' ') < 0) {      // Keep existing message
if it is a sentence.
+            message = Errors.format(Errors.Keys.NativeInterfacesNotFound_2, OS.uname(), "libproj");
+        }
+        return message;
     }
 }

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=1802826&r1=1802825&r2=1802826&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] Mon Jul 24 15:10:43 2017
@@ -43,6 +43,7 @@ import org.apache.sis.referencing.factor
 import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.metadata.iso.citation.Citations;
+import org.apache.sis.metadata.iso.citation.DefaultCitation;
 import org.apache.sis.metadata.iso.ImmutableIdentifier;
 import org.apache.sis.internal.metadata.AxisDirections;
 import org.apache.sis.internal.metadata.ReferencingServices;
@@ -50,6 +51,7 @@ import org.apache.sis.internal.system.De
 import org.apache.sis.internal.system.Modules;
 import org.apache.sis.internal.util.CollectionsExt;
 import org.apache.sis.internal.util.LazySet;
+import org.apache.sis.util.iso.SimpleInternationalString;
 import org.apache.sis.util.collection.WeakValueHashMap;
 import org.apache.sis.util.resources.Vocabulary;
 import org.apache.sis.util.resources.Errors;
@@ -105,6 +107,13 @@ public class Proj4Factory extends Geodet
     static final Proj4Factory INSTANCE = new Proj4Factory();
 
     /**
+     * The {@literal Proj.4} authority completed by the version string. Created when first
needed.
+     *
+     * @see #getAuthority()
+     */
+    private volatile Citation authority;
+
+    /**
      * The default properties, or an empty map if none. This map shall not change after construction
in
      * order to allow usage without synchronization in multi-thread context. But we do not
need to wrap
      * in a unmodifiable map since {@code Proj4Factory} does not provide public access to
it.
@@ -219,7 +228,19 @@ public class Proj4Factory extends Geodet
      */
     @Override
     public Citation getAuthority() {
-        return Citations.PROJ4;
+        Citation c = authority;
+        if (c == null) {
+            c = Citations.PROJ4;
+            final String release = Proj4.version();
+            if (release != null) {
+                final DefaultCitation df = new DefaultCitation(c);
+                df.setEdition(new SimpleInternationalString(release));
+                df.freeze();
+                c = df;
+            }
+            authority = c;
+        }
+        return c;
     }
 
     /**
@@ -408,9 +429,14 @@ public class Proj4Factory extends Geodet
                 }
             }
         }
-        final PJ pj = unique(new PJ(buffer.toString()));
-        final PJ base = unique(new PJ(pj));
-        return new Transform(base, false, pj, false);
+        final String definition = buffer.toString();
+        try {
+            final PJ pj = unique(new PJ(definition));
+            final PJ base = unique(new PJ(pj));
+            return new Transform(base, false, pj, false);
+        } catch (UnsatisfiedLinkError | NoClassDefFoundError e) {
+            throw new UnavailableFactoryException(Proj4.unavailable(e), e);
+        }
     }
 
     /**
@@ -484,7 +510,7 @@ public class Proj4Factory extends Geodet
         try {
             return createCRS(code, hasHeight);
         } catch (UnsatisfiedLinkError | NoClassDefFoundError e) {
-            throw new UnavailableFactoryException(Proj4.unavailable(), e);
+            throw new UnavailableFactoryException(Proj4.unavailable(e), e);
         }
     }
 
@@ -712,10 +738,14 @@ public class Proj4Factory extends Geodet
             throws FactoryException
     {
         final PJ source, target;
-        if ((source = unwrapOrCreate(sourceCRS, force)) == null ||
-            (target = unwrapOrCreate(targetCRS, force)) == null)
-        {
-            return null;            // At least one CRS is not a Proj.4 wrapper and 'force'
is false.
+        try {
+            if ((source = unwrapOrCreate(sourceCRS, force)) == null ||
+                (target = unwrapOrCreate(targetCRS, force)) == null)
+            {
+                return null;            // At least one CRS is not a Proj.4 wrapper and 'force'
is false.
+            }
+        } catch (UnsatisfiedLinkError | NoClassDefFoundError e) {
+            throw new UnavailableFactoryException(Proj4.unavailable(e), e);
         }
         /*
          * Before to create a transform, verify if the target CRS already contains a suitable
transform.

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/package-info.java?rev=1802826&r1=1802825&r2=1802826&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/package-info.java
[UTF-8] Mon Jul 24 15:10:43 2017
@@ -16,7 +16,7 @@
  */
 
 /**
- * Referencing services as wrapper around the C/C++ {@literal Proj.4} library.
+ * Extensions to referencing services as wrapper around the C/C++ {@literal Proj.4} library.
  * Current version wraps only referencing services, but future versions are expected to wrap
more GDAL functionalities.
  * Unless otherwise specified, this optional module requires the native (C/C++) <a href="http://proj.osgeo.org/">Proj.4</a>
  * library to be installed on the local machine. This package allows to:
@@ -32,6 +32,19 @@
  * {@linkplain org.apache.sis.referencing.operation.transform.AbstractMathTransform#derivative
transform derivatives}
  * are not available through the Proj.4 wrappers.
  *
+ * <p>When this optional module is available, the {@link org.apache.sis.referencing.CRS#forCode
CRS.forCode(String)}
+ * method accepts Proj.4 definition strings prefixed by {@code "Proj4::"}. Example:</p>
+ *
+ * {@preformat java
+ *     CoordinateReferenceSystem crs = CRS.forCode("Proj4::+init=epsg:3395");
+ * }
+ *
+ * Calls to {@link org.apache.sis.referencing.CRS#findOperation CRS.findOperation(…)} will
delegate the coordinate
+ * transformation to Proj.4 if an only if {@code sourceCRS} and {@code targetCRS} were both
obtained from a code
+ * in {@code "Proj4"} namespace or by a method in this package. If at least one CRS were
obtained by another way,
+ * then Apache SIS will use its own referencing engine. The backing referencing engine can
be seen by printing
+ * the {@code CoordinateOperation}.
+ *
  * <div class="section">Note on Proj.4 definition strings</div>
  * Proj.4 unconditionally requires 3 letters for the {@code "+axis="} parameter — for example
{@code "neu"} for
  * <cite>North</cite>, <cite>East</cite> and <cite>Up</cite>
respectively — regardless the number of dimensions

Modified: sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/IntegrationTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/IntegrationTest.java?rev=1802826&r1=1802825&r2=1802826&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/IntegrationTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/IntegrationTest.java
[UTF-8] Mon Jul 24 15:10:43 2017
@@ -19,10 +19,11 @@ package org.apache.sis.storage.gdal;
 import org.opengis.util.FactoryException;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.operation.CoordinateOperation;
+import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.referencing.CRS;
 import org.apache.sis.test.TestCase;
+import org.junit.BeforeClass;
 import org.junit.Test;
-import org.opengis.referencing.operation.TransformException;
 
 import static org.opengis.test.Assert.*;
 
@@ -37,16 +38,24 @@ import static org.opengis.test.Assert.*;
  */
 public final strictfp class IntegrationTest extends TestCase {
     /**
-     * Tests usage of {@link CRS#forCode(String)}.
+     * Verifies if the {@literal Proj.4} library is available.
+     */
+    @BeforeClass
+    public static void verifyNativeLibraryAvailability() {
+        PJTest.verifyNativeLibraryAvailability();
+    }
+
+    /**
+     * Tests usage of {@link CRS#forCode(String)}. Note that the {@code "Proj4::"} prefix
needs two colons,
+     * otherwise the text between {@code "Proj4:"} and {@code ":4326"} is interpreted as
a version string.
      *
      * @throws FactoryException if the coordinate reference system can not be created.
      * @throws TransformException if an error occurred while testing a coordinate transformation.
      */
     @Test
-    @org.junit.Ignore
     public void testCRS() throws FactoryException, TransformException {
-        final CoordinateReferenceSystem sourceCRS = CRS.forCode("Proj4:+init=epsg:4326");
-        final CoordinateReferenceSystem targetCRS = CRS.forCode("Proj4:+init=epsg:3395");
+        final CoordinateReferenceSystem sourceCRS = CRS.forCode("Proj4::+init=epsg:4326");
+        final CoordinateReferenceSystem targetCRS = CRS.forCode("Proj4::+init=epsg:3395");
         final CoordinateOperation op = CRS.findOperation(sourceCRS, targetCRS, null);
         assertInstanceOf("Expected Proj.4 wrapper.", Transform.class, op.getMathTransform());
         Proj4FactoryTest.testMercatorProjection(op.getMathTransform());



Mime
View raw message