sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1801784 - in /sis/branches/JDK8/storage/sis-gdal/src: main/c/ main/java/org/apache/sis/storage/gdal/ test/java/org/apache/sis/storage/gdal/
Date Wed, 12 Jul 2017 22:27:38 GMT
Author: desruisseaux
Date: Wed Jul 12 22:27:38 2017
New Revision: 1801784

URL: http://svn.apache.org/viewvc?rev=1801784&view=rev
Log:
Merge PJDatum into PJ class.

Removed:
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJDatum.java
Modified:
    sis/branches/JDK8/storage/sis-gdal/src/main/c/Makefile
    sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.c
    sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.h
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/CRS.java
    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/PJObject.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/package-info.java
    sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/PJTest.java

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/c/Makefile
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/c/Makefile?rev=1801784&r1=1801783&r2=1801784&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/c/Makefile (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/c/Makefile Wed Jul 12 22:27:38 2017
@@ -33,7 +33,7 @@
 #
 # GCC options reminder:
 #    -shared		Produce a shared object which can then be linked with other objects to form
an executable.
-#    -shared-libgcc	Use the shared version of libgcc.
+#    -shared-libgcc	Use the shared version of libgcc. Recommended for JNI when exceptions
may be thrown from gcc.
 #    -fpic		Generate position-independent code suitable for use in a shared library.
 #    -O2		Performs nearly all supported optimizations that do not involve a space-speed tradeoff.
 #

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=1801784&r1=1801783&r2=1801784&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]
Wed Jul 12 22:27:38 2017
@@ -107,7 +107,7 @@ JNIEXPORT jstring JNICALL Java_org_apach
         const char *desc = pj_get_def(pj, 0);
         if (desc) {
             jstring str = (*env)->NewStringUTF(env, desc);
-            pj_dalloc(desc);
+            pj_dalloc((char*) desc);
             return str;
         }
     }

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.h
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.h?rev=1801784&r1=1801783&r2=1801784&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.h [UTF-8]
(original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.h [UTF-8]
Wed Jul 12 22:27:38 2017
@@ -51,6 +51,14 @@ JNIEXPORT jobject JNICALL Java_org_apach
 
 /*
  * Class:     org_apache_sis_storage_gdal_PJ
+ * Method:    getEccentricitySquared
+ * Signature: ()D
+ */
+JNIEXPORT jdouble JNICALL Java_org_apache_sis_storage_gdal_PJ_getEccentricitySquared
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     org_apache_sis_storage_gdal_PJ
  * Method:    getSemiMajorAxis
  * Signature: ()D
  */
@@ -67,10 +75,10 @@ JNIEXPORT jdouble JNICALL Java_org_apach
 
 /*
  * Class:     org_apache_sis_storage_gdal_PJ
- * Method:    getEccentricitySquared
+ * Method:    getGreenwichLongitude
  * Signature: ()D
  */
-JNIEXPORT jdouble JNICALL Java_org_apache_sis_storage_gdal_PJ_getEccentricitySquared
+JNIEXPORT jdouble JNICALL Java_org_apache_sis_storage_gdal_PJ_getGreenwichLongitude
   (JNIEnv *, jobject);
 
 /*
@@ -82,14 +90,6 @@ JNIEXPORT jcharArray JNICALL Java_org_ap
   (JNIEnv *, jobject);
 
 /*
- * Class:     org_apache_sis_storage_gdal_PJ
- * Method:    getGreenwichLongitude
- * Signature: ()D
- */
-JNIEXPORT jdouble JNICALL Java_org_apache_sis_storage_gdal_PJ_getGreenwichLongitude
-  (JNIEnv *, jobject);
-
-/*
  * Class:     org_apache_sis_storage_gdal_PJ
  * Method:    getLinearUnitToMetre
  * Signature: (Z)D

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/CRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/CRS.java?rev=1801784&r1=1801783&r2=1801784&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/CRS.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/CRS.java
[UTF-8] Wed Jul 12 22:27:38 2017
@@ -30,6 +30,7 @@ import org.opengis.referencing.datum.Geo
 import org.opengis.referencing.operation.Projection;
 
 import org.apache.sis.measure.Units;
+import org.apache.sis.referencing.factory.InvalidGeodeticParameterException;
 
 
 /**
@@ -45,7 +46,7 @@ class CRS extends PJObject implements Co
     /**
      * The geodetic datum, which is also the object to use for performing call to Proj4 functions.
      */
-    final PJDatum pj;
+    final PJ pj;
 
     /**
      * The coordinate system axes. The length of this array is the dimension,
@@ -61,7 +62,7 @@ class CRS extends PJObject implements Co
      * @param dimension   the number of dimensions of the new CRS. Must be at least 2.
      * @param unit        the horizontal axes unit.
      */
-    CRS(final Identifier identifier, final PJDatum datum, final int dimension, final Unit<?>
unit) {
+    CRS(final Identifier identifier, final PJ datum, final int dimension, final Unit<?>
unit) {
         super(identifier);
         pj = datum;
         axes = new CoordinateSystemAxis[dimension];
@@ -116,7 +117,7 @@ class CRS extends PJObject implements Co
      * The geocentric specialization of {@link CRS}.
      */
     static final class Geocentric extends CRS implements GeocentricCRS {
-        Geocentric(final Identifier identifier, final PJDatum datum, final int dimension)
{
+        Geocentric(final Identifier identifier, final PJ datum, final int dimension) {
             super(identifier, datum, dimension, Units.DEGREE);
         }
     }
@@ -125,7 +126,7 @@ class CRS extends PJObject implements Co
      * The geographic specialization of {@link CRS}.
      */
     static final class Geographic extends CRS implements GeographicCRS, EllipsoidalCS {
-        Geographic(final Identifier identifier, final PJDatum datum, final int dimension)
{
+        Geographic(final Identifier identifier, final PJ datum, final int dimension) {
             super(identifier, datum, dimension, Units.DEGREE);
         }
 
@@ -162,7 +163,7 @@ class CRS extends PJObject implements Co
         /**
          * Creates a new projected CRS.
          */
-        Projected(final Identifier identifier, final PJDatum datum, final int dimension,
+        Projected(final Identifier identifier, final PJ datum, final int dimension,
                 final String axisOrientations)
         {
             super(identifier, datum, dimension, datum.getLinearUnit(false));
@@ -213,7 +214,7 @@ class CRS extends PJObject implements Co
         public synchronized Geographic getBaseCRS() {
             if (baseCRS == null) {
                 int dimension = axes.length;
-                PJDatum base = new PJDatum(pj);
+                PJ base = new PJ(pj);
                 if (axisOrientations != null) {
                     final int s = axisOrientations.indexOf(Proj4.AXIS_ORDER_SEPARATOR);
                     if (s >= 0) {
@@ -229,7 +230,11 @@ class CRS extends PJObject implements Co
                             }
                             ap += Proj4.AXIS_ORDER_PARAM.length();
                             definition.replace(ap, findWordEnd(definition, ap), orientation);
-                            base = new PJDatum(base.getName(), definition.toString());
+                            try {
+                                base = new PJ(base.getName(), definition.toString());
+                            } catch (InvalidGeodeticParameterException e) {
+                                throw new IllegalStateException(e);
+                            }
                         }
                     }
                 }

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=1801784&r1=1801783&r2=1801784&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]
Wed Jul 12 22:27:38 2017
@@ -16,20 +16,31 @@
  */
 package org.apache.sis.storage.gdal;
 
+import java.util.Date;
 import java.util.Objects;
 import java.lang.annotation.Native;
+import javax.measure.Unit;
+import javax.measure.quantity.Angle;
+import javax.measure.quantity.Length;
+import org.opengis.metadata.Identifier;
+import org.opengis.metadata.extent.Extent;
+import org.opengis.util.InternationalString;
+import org.opengis.referencing.datum.Ellipsoid;
+import org.opengis.referencing.datum.GeodeticDatum;
+import org.opengis.referencing.datum.PrimeMeridian;
 import org.opengis.referencing.operation.TransformException;
+import org.apache.sis.referencing.factory.InvalidGeodeticParameterException;
 import org.apache.sis.internal.system.OS;
+import org.apache.sis.measure.Units;
 
 
 /**
  * Wraps the <a href="http://proj.osgeo.org/">Proj4</a> {@code PJ} native data
structure.
- * Almost every methods defined in this class are native methods delegating the work to the
Proj4 library.
- * This class is the only place where such native methods are defined.
+ * Many methods defined in this class are native methods delegating their work to the Proj4
library.
+ * This class is the only place where such native methods are defined for Proj4 support.
  *
  * <p>In the Proj4 library, the {@code PJ} structure aggregates in a single place information
usually
- * splitted in many different ISO 19111 interfaces: {@link org.opengis.referencing.datum.Ellipsoid},
- * {@link org.opengis.referencing.datum.Datum}, {@link org.opengis.referencing.datum.PrimeMeridian},
+ * splitted in many different ISO 19111 interfaces: {@link Ellipsoid}, {@link GeodeticDatum},
{@link PrimeMeridian},
  * {@link org.opengis.referencing.cs.CoordinateSystem}, {@link org.opengis.referencing.crs.CoordinateReferenceSystem}
  * and their sub-interfaces. The relationship with the GeoAPI methods is indicated in the
"See" tags when appropriate.</p>
  *
@@ -38,7 +49,7 @@ import org.apache.sis.internal.system.OS
  * @since   0.8
  * @module
  */
-class PJ {
+final class PJ extends PJObject implements GeodeticDatum, PrimeMeridian, Ellipsoid {
     /**
      * The maximal number of dimension accepted by the {@link #transform(PJ, int, double[],
int, int)} method.
      * This upper limit is actually somewhat arbitrary. This limit exists mostly as a safety
against potential misuse.
@@ -66,14 +77,16 @@ class PJ {
     /**
      * Creates a new {@code PJ} structure from the given Proj4 definition string.
      *
+     * @param  name        the datum identifier, or {@code null} for inferring it from the
definition.
      * @param  definition  the Proj4 definition string.
-     * @throws IllegalArgumentException if the PJ structure can not be created from the given
string.
+     * @throws InvalidGeodeticParameterException if the PJ structure can not be created from
the given string.
      */
-    public PJ(final String definition) throws IllegalArgumentException {
+    public PJ(Identifier name, final String definition) throws InvalidGeodeticParameterException
{
+        super(name != null ? name : identifier(definition, "+datum="));
         Objects.requireNonNull(definition);
         ptr = allocatePJ(definition);
         if (ptr == 0) {
-            throw new IllegalArgumentException(definition);
+            throw new InvalidGeodeticParameterException(definition);
         }
     }
 
@@ -87,7 +100,7 @@ class PJ {
      * @throws IllegalArgumentException if the PJ structure can not be created.
      */
     public PJ(final PJ crs) throws IllegalArgumentException {
-        Objects.requireNonNull(crs);
+        super(identifier(crs.getDefinition(), "+datum="));
         ptr = allocateGeoPJ(crs);
         if (ptr == 0) {
             throw new IllegalArgumentException(crs.getLastError());
@@ -95,10 +108,9 @@ class PJ {
     }
 
     /**
-     * Allocates a PJ native data structure and returns the pointer to it. This method should
be
-     * invoked by the constructor only, and the return value <strong>must</strong>
be assigned
-     * to the {@link #ptr} field. The allocated structure is released by the {@link #finalize()}
-     * method.
+     * Allocates a PJ native data structure and returns the pointer to it. This method should
be invoked by
+     * the constructor only, and the return value <strong>must</strong> be assigned
to the {@link #ptr} field.
+     * The allocated structure is released by the {@link #finalize()} method.
      *
      * @param  definition  the Proj4 definition string.
      * @return a pointer to the PJ native data structure, or 0 if the operation failed.
@@ -106,10 +118,9 @@ class PJ {
     private static native long allocatePJ(String definition);
 
     /**
-     * Allocates a PJ native data structure for the base geographic CRS of the given CRS,
and
-     * returns the pointer to it. This method should be invoked by the constructor only,
and
-     * the return value <strong>must</strong> be assigned to the {@link #ptr}
field.
-     * The allocated structure is released by the {@link #finalize()} method.
+     * Allocates a PJ native data structure for the base geographic CRS of the given CRS,
and returns the pointer to it.
+     * This method should be invoked by the constructor only, and the return value <strong>must</strong>
be assigned to
+     * the {@link #ptr} field. The allocated structure is released by the {@link #finalize()}
method.
      *
      * @param  projected  the CRS from which to derive the base geographic CRS.
      * @return a pointer to the PJ native data structure, or 0 if the operation failed.
@@ -169,34 +180,129 @@ class PJ {
     }
 
     /**
+     * Returns the ellipsoid associated with this geodetic datum.
+     * In Proj4 implementation, the datum and its ellipsoid are represented by the same {@code
PJ} object.
+     */
+    @Override
+    public Ellipsoid getEllipsoid() {
+        return this;
+    }
+
+    /**
+     * Returns {@code true} if the ellipsoid is a sphere.
+     */
+    @Override
+    public boolean isSphere() {
+        return getEccentricitySquared() == 0;
+    }
+
+    /**
+     * Returns {@code true} unconditionally since the inverse eccentricity squared in definitive
+     * in the Proj4 library, and the eccentricity is directly related to the flattening.
+     */
+    @Override
+    public boolean isIvfDefinitive() {
+        return true;
+    }
+
+    /**
+     * Returns the inverse flattening, computed from the eccentricity.
+     */
+    @Override
+    public double getInverseFlattening() {
+        return 1 / (1 - Math.sqrt(1 - getEccentricitySquared()));
+    }
+
+    /**
+     * Returns the square of the ellipsoid eccentricity (ε²). The eccentricity is related
to axis length
+     * by ε=√(1-(<var>b</var>/<var>a</var>)²). The eccentricity
of a sphere is zero.
+     *
+     * @return the eccentricity.
+     *
+     * @see #isSphere()
+     * @see #getInverseFlattening()
+     */
+    public native double getEccentricitySquared();
+
+    /**
      * Returns the value stored in the {@code a_orig} PJ field.
      *
      * @return the axis length stored in {@code a_orig}.
-     *
-     * @see org.opengis.referencing.datum.Ellipsoid#getSemiMajorAxis()
      */
+    @Override
     public native double getSemiMajorAxis();
 
     /**
      * Returns the value computed from PJ fields by {@code √((a_orig)² × (1 - es_orig))}.
      *
      * @return the axis length computed by {@code √((a_orig)² × (1 - es_orig))}.
-     *
-     * @see org.opengis.referencing.datum.Ellipsoid#getSemiMinorAxis()
      */
+    @Override
     public native double getSemiMinorAxis();
 
     /**
-     * Returns the square of the ellipsoid eccentricity (ε²). The eccentricity
-     * is related to axis length by ε=√(1-(<var>b</var>/<var>a</var>)²).
The
-     * eccentricity of a sphere is zero.
+     * Returns the ellipsoid axis unit, which is assumed metres in the case of the Proj4
library.
+     * Not to be confused with the {@linkplain #getLinearUnit(boolean) coordinate system
axis unit}.
+     */
+    @Override
+    public Unit<Length> getAxisUnit() {
+        return Units.METRE;
+    }
+
+    /**
+     * Returns the prime meridian associated with this geodetic datum.
+     * In Proj4 implementation, the datum and its prime meridian are represented by the same
{@code PJ} object.
+     */
+    @Override
+    public PrimeMeridian getPrimeMeridian() {
+        return this;
+    }
+
+    /**
+     * Returns the units of the prime meridian.
+     * All angular units are converted from radians to degrees in the JNI code.
      *
-     * @return the eccentricity.
+     * @see #getLinearUnit(boolean)
+     */
+    @Override
+    public Unit<Angle> getAngularUnit() {
+        return Units.DEGREE;
+    }
+
+    /**
+     * Longitude of the prime meridian measured from the Greenwich meridian, positive eastward.
      *
-     * @see org.opengis.referencing.datum.Ellipsoid#isSphere()
-     * @see org.opengis.referencing.datum.Ellipsoid#getInverseFlattening()
+     * @return the prime meridian longitude, in degrees.
      */
-    public native double getEccentricitySquared();
+    @Override
+    public native double getGreenwichLongitude();
+
+    /**
+     * Returns a description of the relationship used to anchor the coordinate system to
the Earth.
+     * Current implementation returns {@code null}.
+     */
+    @Override
+    public InternationalString getAnchorPoint() {
+        return null;
+    }
+
+    /**
+     * Returns the time after which this datum definition is valid.
+     * Current implementation returns {@code null}.
+     */
+    @Override
+    public Date getRealizationEpoch() {
+        return null;
+    }
+
+    /**
+     * Returns the area or region or timeframe in which this datum is valid.
+     * Current implementation returns {@code null}.
+     */
+    @Override
+    public Extent getDomainOfValidity() {
+        return null;
+    }
 
     /**
      * Returns an array of character indicating the direction of each axis. Directions are
@@ -209,13 +315,14 @@ class PJ {
     public native char[] getAxisDirections();
 
     /**
-     * Longitude of the prime meridian measured from the Greenwich meridian, positive eastward.
+     * Returns the linear unit for the horizontal or the vertical coordinate system axes.
+     * Not to be confused with the {@linkplain #getAxisUnit() ellipsoid axis unit}.
      *
-     * @return the prime meridian longitude, in degrees.
-     *
-     * @see org.opengis.referencing.datum.PrimeMeridian#getGreenwichLongitude()
+     * @see #getAngularUnit()
      */
-    public native double getGreenwichLongitude();
+    public Unit<Length> getLinearUnit(final boolean vertical) {
+        return Units.METRE.divide(getLinearUnitToMetre(vertical));
+    }
 
     /**
      * Returns the conversion factor from the linear units to metres.
@@ -224,7 +331,7 @@ class PJ {
      *         or {@code true} for the conversion factor of the vertical axis.
      * @return the conversion factor to metres for the given axis.
      */
-    public native double getLinearUnitToMetre(boolean vertical);
+    native double getLinearUnitToMetre(boolean vertical);
 
     /**
      * Transforms in-place the coordinates in the given array. The coordinates array shall
contain
@@ -257,7 +364,7 @@ class PJ {
      *
      * @return the last error that occurred, or {@code null}.
      */
-    public native String getLastError();
+    native String getLastError();
 
     /**
      * Returns the string representation of the PJ structure.
@@ -270,7 +377,6 @@ class PJ {
     /**
      * Deallocates the native PJ data structure. This method can be invoked only by the garbage
      * collector, and must be invoked exactly once (no more, no less).
-     * <strong>NEVER INVOKE THIS METHOD EXPLICITELY, NEVER OVERRIDE</strong>.
      */
     @Override
     @SuppressWarnings("FinalizeDeclaration")

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJObject.java?rev=1801784&r1=1801783&r2=1801784&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJObject.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJObject.java
[UTF-8] Wed Jul 12 22:27:38 2017
@@ -24,6 +24,7 @@ import org.opengis.util.InternationalStr
 import org.opengis.metadata.Identifier;
 import org.opengis.metadata.extent.Extent;
 import org.opengis.referencing.IdentifiedObject;
+import org.apache.sis.internal.simple.SimpleIdentifier;
 
 
 /**
@@ -74,6 +75,29 @@ class PJObject implements IdentifiedObje
     }
 
     /**
+     * Returns the value of the given parameter as an identifier, or {@code null} if none.
+     * The given parameter key shall include the {@code '+'} prefix and {@code '='} suffix,
+     * for example {@code "+proj="}. This is a helper method for providing the {@code name}
+     * argument in constructors.
+     *
+     * @param  definition  the Proj.4 definition string to parse.
+     * @param  key         the parameter name.
+     * @return the parameter value as an identifier.
+     */
+    static Identifier identifier(final String definition, final String key) {
+        int i = definition.indexOf(key);
+        if (i >= 0) {
+            i += key.length();
+            final int stop = definition.indexOf(' ', i);
+            String value = (stop >= 0) ? definition.substring(i, stop) : definition.substring(i);
+            if (!(value = value.trim()).isEmpty()) {
+                return new SimpleIdentifier(null, value, false);
+            }
+        }
+        return null;
+    }
+
+    /**
      * Returns the name of this referencing object, or {@code null} if none.
      * Note that this attribute is mandatory according ISO 19111, but this
      * simple Proj.4 wrapper is lenient about that.

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=1801784&r1=1801783&r2=1801784&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] Wed Jul 12 22:27:38 2017
@@ -88,11 +88,11 @@ public final class Proj4 extends Static
      * @param  dimension   the number of dimension of the CRS to create.
      * @return a CRS created from the given definition string and number of dimension.
      * @throws NullPointerException if the definition string is {@code null}.
-     * @throws IllegalArgumentException if one of the given argument has an invalid value.
+     * @throws FactoryException if one of the given argument has an invalid value.
      */
     public static CoordinateReferenceSystem createCRS(final Identifier crsId,
             final Identifier datumId, String definition, final int dimension)
-            throws IllegalArgumentException
+            throws FactoryException
     {
         if ((definition = definition.trim()).isEmpty()) {
             throw new IllegalArgumentException("The definition must be non-empty.");
@@ -129,7 +129,7 @@ public final class Proj4 extends Static
         /*
          * Create the Proj.4 wrapper.
          */
-        final PJDatum datum = new PJDatum(datumId, definition);
+        final PJ datum = new PJ(datumId, definition);
         final PJ.Type type = datum.getType();
         final CoordinateReferenceSystem crs;
         switch (type) {

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=1801784&r1=1801783&r2=1801784&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] Wed Jul 12 22:27:38 2017
@@ -16,7 +16,7 @@
  */
 
 /**
- * GeoAPI implementation as wrapper around the C/C++ <a href="http://proj.osgeo.org/">Proj4</a>
library.
+ * Referencing services as wrapper around the C/C++ <a href="http://proj.osgeo.org/">Proj4</a>
library.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @version 0.8

Modified: sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/PJTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/PJTest.java?rev=1801784&r1=1801783&r2=1801784&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/PJTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/PJTest.java
[UTF-8] Wed Jul 12 22:27:38 2017
@@ -17,6 +17,8 @@
 package org.apache.sis.storage.gdal;
 
 import org.opengis.referencing.operation.TransformException;
+import org.apache.sis.referencing.factory.InvalidGeodeticParameterException;
+import org.apache.sis.measure.Units;
 import org.apache.sis.test.TestCase;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -61,43 +63,66 @@ public final strictfp class PJTest exten
         assertEquals("+proj=latlong +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0", pj.getDefinition().trim());
         assertEquals("Lat/long (Geodetic alias)", pj.toString().trim());
         assertEquals(PJ.Type.GEOGRAPHIC, pj.getType());
+        assertEquals("WGS84",            pj.getName().getCode());
         assertEquals(6378137.0,          pj.getSemiMajorAxis(),         1E-9);
         assertEquals(6356752.314245179,  pj.getSemiMinorAxis(),         1E-9);
-        assertEquals(0.0,                pj.getGreenwichLongitude(),    0.0);
-        assertEquals(1.0,                pj.getLinearUnitToMetre(true), 0.0);
+        assertEquals(298.257223563,      pj.getInverseFlattening(),     1E-9);
+        assertEquals(0.0,                pj.getGreenwichLongitude(),    STRICT);
+        assertEquals(1.0,                pj.getLinearUnitToMetre(true), STRICT);
+        assertSame  (Units.METRE,        pj.getAxisUnit());
+        assertFalse(pj.isSphere());
         assertArrayEquals(new char[] {'e', 'n', 'u'}, pj.getAxisDirections());
     }
 
     /**
      * Tests the creation of a simple WGS84 object.
+     *
+     * @throws InvalidGeodeticParameterException if the Proj4 definition string used in this
test is invalid.
      */
     @Test
-    public void testWGS84() {
-        final PJ pj = new PJ("+proj=latlong +datum=WGS84");
+    public void testWGS84() throws InvalidGeodeticParameterException {
+        final PJ pj = new PJ(null, "+proj=latlong +datum=WGS84");
         assertIsWGS84(pj);
     }
 
     /**
-     * Tests the creation of the EPSG:3395 projected CRS
+     * Tests the creation of the EPSG:3395 projected CRS.
+     *
+     * @throws InvalidGeodeticParameterException if the Proj4 definition string used in this
test is invalid.
      */
     @Test
-    public void testEPSG3395() {
-        final PJ pj = new PJ("+init=epsg:3395");
+    public void testEPSG3395() throws InvalidGeodeticParameterException {
+        final PJ pj = new PJ(null, "+init=epsg:3395");
         assertEquals(PJ.Type.PROJECTED, pj.getType());
         assertArrayEquals(new char[] {'e', 'n', 'u'}, pj.getAxisDirections());
-        assertEquals(1.0, pj.getLinearUnitToMetre(true), 0.0);
+        assertEquals(1.0, pj.getLinearUnitToMetre(true), STRICT);
         assertIsWGS84(new PJ(pj));
     }
 
     /**
+     * Tests the {@link PJ#getLinearUnit(boolean)} method.
+     *
+     * @throws InvalidGeodeticParameterException if the Proj4 definition string used in this
test is invalid.
+     */
+    @Test
+    public void testGetLinearUnit() throws InvalidGeodeticParameterException {
+        PJ pj;
+        pj = new PJ(null, "+proj=merc +to_meter=1");
+        assertSame(Units.METRE, pj.getLinearUnit(false));
+        pj = new PJ(null, "+proj=merc +to_meter=0.001");
+        assertSame(Units.KILOMETRE, pj.getLinearUnit(false));
+    }
+
+    /**
      * Ensures that the native code correctly detects the case of null pointers.
      * This is important in order to ensure that we don't have a JVM crash.
      *
+     * @throws InvalidGeodeticParameterException if the Proj4 definition string used in this
test is invalid.
      * @throws TransformException should never happen.
      */
     @Test
-    public void testNullPointerException() throws TransformException {
-        final PJ pj = new PJ("+proj=latlong +datum=WGS84");
+    public void testNullPointerException() throws InvalidGeodeticParameterException, TransformException
{
+        final PJ pj = new PJ(null, "+proj=latlong +datum=WGS84");
         try {
             pj.transform(null, 2, null, 0, 1);
             fail("Expected an exception to be thrown.");
@@ -110,11 +135,12 @@ public final strictfp class PJTest exten
      * Ensures that the native code correctly detects the case of index out of bounds.
      * This is important in order to ensure that we don't have a JVM crash.
      *
+     * @throws InvalidGeodeticParameterException if the Proj4 definition string used in this
test is invalid.
      * @throws TransformException should never happen.
      */
     @Test
-    public void testIndexOutOfBoundsException() throws TransformException {
-        final PJ pj = new PJ("+proj=latlong +datum=WGS84");
+    public void testIndexOutOfBoundsException() throws InvalidGeodeticParameterException,
TransformException {
+        final PJ pj = new PJ(null, "+proj=latlong +datum=WGS84");
         try {
             pj.transform(pj, 2, new double[5], 2, 2);
             fail("Expected an exception to be thrown.");
@@ -127,11 +153,13 @@ public final strictfp class PJTest exten
      * Tests a method that returns NaN. The native code is expected to returns the
      * {@link java.lang.Double#NaN} constant, because not all C/C++ compiler define
      * a {@code NAN} constant.
+     *
+     * @throws InvalidGeodeticParameterException if the Proj4 definition string used in this
test is invalid.
      */
     @Test
     @SuppressWarnings("FinalizeCalledExplicitly")
-    public void testNaN() {
-        final PJ pj = new PJ("+proj=latlong +datum=WGS84");
+    public void testNaN() throws InvalidGeodeticParameterException {
+        final PJ pj = new PJ(null, "+proj=latlong +datum=WGS84");
         pj.finalize();              // This cause the disposal of the internal PJ structure.
         assertNull(pj.getType());
         assertNaN(pj.getSemiMajorAxis());



Mime
View raw message