sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1805430 - in /sis/branches/JDK8: core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ storage/sis-gdal/src/main/c/ storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/ storage/sis-gdal/src/main/resource...
Date Fri, 18 Aug 2017 13:49:52 GMT
Author: desruisseaux
Date: Fri Aug 18 13:49:51 2017
New Revision: 1805430

URL: http://svn.apache.org/viewvc?rev=1805430&view=rev
Log:
Better error message if PJ construction failed for a given definition string.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
    sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.c
    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/resources/native/darwin/libproj-binding.so
    sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/TransformTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java?rev=1805430&r1=1805429&r2=1805430&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
[UTF-8] Fri Aug 18 13:49:51 2017
@@ -443,8 +443,8 @@ public abstract class AbstractMathTransf
                     throw failure;
                 }
                 /*
-                 * Otherwise fills the ordinate values to NaN and count the number of exceptions,
-                 * so we known when to give up if there is too much of them. The first exception
+                 * Otherwise set the ordinate values to NaN and count the number of exceptions,
+                 * so we know when to give up if there is too much of them. The first exception
                  * will be propagated at the end of this method.
                  */
                 Arrays.fill(dstPts, dstOff, dstOff + Math.abs(dstInc), Double.NaN);

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.c
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.c?rev=1805430&r1=1805429&r2=1805430&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.c [UTF-8]
(original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.c [UTF-8]
Fri Aug 18 13:49:51 2017
@@ -281,12 +281,14 @@ JNIEXPORT void JNICALL Java_org_apache_s
 JNIEXPORT jstring JNICALL Java_org_apache_sis_storage_gdal_PJ_getLastError
   (JNIEnv *env, jobject object)
 {
-    projPJ pj = getPJ(env, object);
-    if (pj) {
-        int err = *pj_get_errno_ref();
-        if (err) {
-            return (*env)->NewStringUTF(env, pj_strerrno(err));
-        }
+    /*
+     * For now we ignore the object reference, but a future version may use it if
+     * we make this method thread-safe with the use of a Proj.4 context parameter.
+     * Note that this method needs to work even if getPJ(env, object) returns NULL.
+     */
+    int err = *pj_get_errno_ref();
+    if (err) {
+        return (*env)->NewStringUTF(env, pj_strerrno(err));
     }
     return NULL;
 }

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=1805430&r1=1805429&r2=1805430&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]
Fri Aug 18 13:49:51 2017
@@ -27,12 +27,10 @@ import org.opengis.metadata.citation.Cit
 import org.opengis.referencing.datum.Ellipsoid;
 import org.opengis.referencing.datum.GeodeticDatum;
 import org.opengis.referencing.datum.PrimeMeridian;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.referencing.factory.InvalidGeodeticParameterException;
 import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.metadata.iso.citation.Citations;
-import org.apache.sis.util.resources.Errors;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.internal.system.OS;
 
@@ -81,8 +79,8 @@ final class PJ implements Identifier, Se
         Objects.requireNonNull(definition);
         ptr = allocatePJ(definition);
         if (ptr == 0) {
-            throw new InvalidGeodeticParameterException(Errors.format(Errors.Keys.UnparsableStringForClass_2,
-                    CoordinateReferenceSystem.class, definition));
+            // Note: our getLastError() implementation is safe even if pts == 0.
+            throw new InvalidGeodeticParameterException(getLastError());
         }
     }
 
@@ -286,6 +284,7 @@ final class PJ implements Identifier, Se
      * @return the last error that occurred, or {@code null}.
      *
      * @todo this method is not thread-safe. Proj.4 provides a better alternative using a
context parameter.
+     *       Note that this method needs to be safe even if {@link #ptr} is 0.
      */
     native String getLastError();
 

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=1805430&r1=1805429&r2=1805430&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] Fri Aug 18 13:49:51 2017
@@ -166,22 +166,13 @@ public final class Proj4 extends Static
          * Append the map projection parameters. Those parameters may include axis lengths
(a and b),
          * but not necessarily. If axis lengths are specified, then we will ignore the Ellipsoid
instance
          * associated to the CRS.
-         *
-         * The "+over" option is for disabling the default wrapping of output longitudes
in the -180 to 180 range.
-         * We do that for having the same behavior between Proj.4 and Apache SIS. No wrapping
reduce discontinuity
-         * problems with geometries that cross the anti-meridian.
-         *
-         * The "+no_defs" option is for ensuring that no defaults are read from "/usr/share/proj/proj_def.dat"
file.
-         * That file contains default values for various map projections, for example "+lat_1=29.5"
and "+lat_2=45.5"
-         * for the "aea" projection. Those defaults are assuming that users want Conterminous
U.S. map.
-         * This may cause surprising behavior for users outside USA.
          */
         final StringBuilder definition = new StringBuilder(100);
         definition.append(Proj4Factory.PROJ_PARAM).append(method);
         boolean hasSemiMajor = false;
         boolean hasSemiMinor = false;
         if (parameters != null) {
-            definition.append(" +over +no_defs");                                       //
See above comment
+            definition.append(Proj4Factory.STANDARD_OPTIONS);
             for (final GeneralParameterValue parameter : parameters.values()) {
                 if (parameter instanceof ParameterValue<?>) {
                     final ParameterValue<?> pv = (ParameterValue<?>) parameter;

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=1805430&r1=1805429&r2=1805430&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] Fri Aug 18 13:49:51 2017
@@ -96,6 +96,20 @@ public class Proj4Factory extends Geodet
     static final String PROJ_PARAM = '+' + Proj4Parser.PROJ + '=';
 
     /**
+     * Options to be added in any {@literal Proj.4} definition strings.
+     * <ul>
+     *   <li>The {@code "+over"} option is for disabling the default wrapping of output
longitudes in the -180 to 180 range.
+     *     We do that for having the same behavior between Proj.4 and Apache SIS. No wrapping
reduce discontinuity problems
+     *     with geometries that cross the anti-meridian.</li>
+     *   <li>The {@code "+no_defs"} option is for ensuring that no defaults are read
from {@code "/usr/share/proj/proj_def.dat"} file.
+     *     That file contains default values for various map projections, for example {@code
"+lat_1=29.5"} and {@code "+lat_2=45.5"}
+     *     for the {@code "aea"} projection. Those defaults are assuming that users want
Conterminous U.S. map.
+     *     This may cause surprising behavior for users outside USA.</li>
+     * </ul>
+     */
+    static String STANDARD_OPTIONS = " +over +no_defs";
+
+    /**
      * The {@literal Proj.4} parameter used for declaration of axis order.  Proj.4 expects
the axis parameter
      * to be exactly 3 characters long, but Apache SIS accepts 2 characters as well. We relax
the Proj.4 rule
      * because we use the number of characters for determining the number of dimensions.
@@ -424,7 +438,7 @@ public class Proj4Factory extends Geodet
      */
     public MathTransform createParameterizedTransform(final ParameterValueGroup parameters)
throws FactoryException {
         final String proj = name(parameters.getDescriptor(), Errors.Keys.UnsupportedOperation_1);
-        final StringBuilder buffer = new StringBuilder(100).append(PROJ_PARAM).append(proj);
+        final StringBuilder buffer = new StringBuilder(100).append(PROJ_PARAM).append(proj).append(STANDARD_OPTIONS);
         for (final GeneralParameterValue p : parameters.values()) {
             /*
              * Unconditionally ask the parameter name in order to throw an exception

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/resources/native/darwin/libproj-binding.so
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/resources/native/darwin/libproj-binding.so?rev=1805430&r1=1805429&r2=1805430&view=diff
==============================================================================
Binary files - no diff available.

Modified: sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/TransformTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/TransformTest.java?rev=1805430&r1=1805429&r2=1805430&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/TransformTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/TransformTest.java
[UTF-8] Fri Aug 18 13:49:51 2017
@@ -57,7 +57,7 @@ public class TransformTest extends Param
                     return super.getDefaultParameters(method);
                 } catch (NoSuchIdentifierException e) {
                     FAILURES.add(method);
-                    throw e;
+                    throw e;                            // Instructs ParameterizedTransformTest
to skip the test.
                 }
             }
         });
@@ -82,7 +82,7 @@ public class TransformTest extends Param
     @AfterClass
     public static void verifyFailureList() {
         /*
-         * The list of failires is empty if verifyNativeLibraryAvailability() failed,
+         * The list of failures is empty if verifyNativeLibraryAvailability() failed,
          * in which case no test have been run.
          */
         if (!FAILURES.isEmpty()) {



Mime
View raw message