You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2017/07/25 10:46:32 UTC
svn commit: r1802916 - in /sis/branches/JDK8:
core/sis-utility/src/main/java/org/apache/sis/util/resources/
storage/sis-gdal/src/main/c/
storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/
storage/sis-gdal/src/main/resources/native/darwin/ stor...
Author: desruisseaux
Date: Tue Jul 25 10:46:31 2017
New Revision: 1802916
URL: http://svn.apache.org/viewvc?rev=1802916&view=rev
Log:
Use only public API for avoiding compatibility problems.
Modified:
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/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/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/Proj4Parser.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/PJTest.java
sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4FactoryTest.java
sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4ParserTest.java
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=1802916&r1=1802915&r2=1802916&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] Tue Jul 25 10:46:31 2017
@@ -126,6 +126,11 @@ public final class Errors extends Indexe
public static final short CanNotParseFile_2 = 10;
/**
+ * Can not parse “{0}”.
+ */
+ public static final short CanNotParse_1 = 180;
+
+ /**
* Can not read property “{1}” in file “{0}”.
*/
public static final short CanNotReadPropertyInFile_2 = 11;
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=1802916&r1=1802915&r2=1802916&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] Tue Jul 25 10:46:31 2017
@@ -35,6 +35,7 @@ CanNotConvertValue_2 = Can
CanNotCompute_1 = Can not compute \u201c{0}\u201d.
CanNotCopy_1 = Can not copy \u201c{0}\u201d.
CanNotOpen_1 = Can not open \u201c{0}\u201d.
+CanNotParse_1 = Can not parse \u201c{0}\u201d.
CanNotParseFile_2 = Can not parse \u201c{1}\u201d as a file in the {0} format.
CanNotRead_1 = Can not read \u201c{0}\u201d.
CanNotReadPropertyInFile_2 = Can not read property \u201c{1}\u201d in file \u201c{0}\u201d.
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=1802916&r1=1802915&r2=1802916&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] Tue Jul 25 10:46:31 2017
@@ -32,6 +32,7 @@ CanNotConvertValue_2 = La v
CanNotCompute_1 = Ne peut pas calculer \u00ab\u202f{0}\u202f\u00bb.
CanNotCopy_1 = Ne peut pas copier \u00ab\u202f{0}\u202f\u00bb.
CanNotOpen_1 = Ne peut pas ouvrir \u00ab\u202f{0}\u202f\u00bb.
+CanNotParse_1 = Ne peut pas interpr\u00e9ter \u00ab\u202f{0}\u202f\u00bb.
CanNotParseFile_2 = Ne peut pas lire \u00ab\u202f{1}\u202f\u00bb comme un fichier au format {0}.
CanNotRead_1 = Ne peut pas lire \u00ab\u202f{0}\u202f\u00bb.
CanNotReadPropertyInFile_2 = Ne peut pas lire la propri\u00e9t\u00e9 \u00ab\u202f{1}\u202f\u00bb dans le fichier \u00ab\u202f{0}\u202f\u00bb.
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=1802916&r1=1802915&r2=1802916&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] Tue Jul 25 10:46:31 2017
@@ -16,7 +16,7 @@
*/
#include <math.h>
#include <string.h>
-#include <projects.h>
+#include <proj_api.h>
#include "org_apache_sis_storage_gdal_PJ.h"
@@ -35,10 +35,10 @@
* \return The address of the PJ structure, or NULL if the operation fails (for example
* because the "ptr" field was not found).
*/
-PJ *getPJ(JNIEnv *env, jobject object)
+projPJ getPJ(JNIEnv *env, jobject object)
{
jfieldID id = (*env)->GetFieldID(env, (*env)->GetObjectClass(env, object), PJ_FIELD_NAME, PJ_FIELD_TYPE);
- return (id) ? (PJ*) (*env)->GetLongField(env, object, id) : NULL;
+ return (id) ? (projPJ) (*env)->GetLongField(env, object, id) : NULL;
}
/*!
@@ -70,7 +70,7 @@ JNIEXPORT jlong JNICALL Java_org_apache_
{
const char *def_utf = (*env)->GetStringUTFChars(env, definition, NULL);
if (!def_utf) return 0; // OutOfMemoryError already thrown.
- PJ *pj = pj_init_plus(def_utf);
+ projPJ pj = pj_init_plus(def_utf);
(*env)->ReleaseStringUTFChars(env, definition, def_utf);
return (jlong) pj;
}
@@ -87,7 +87,7 @@ JNIEXPORT jlong JNICALL Java_org_apache_
JNIEXPORT jlong JNICALL Java_org_apache_sis_storage_gdal_PJ_allocateGeoPJ
(JNIEnv *env, jclass class, jobject projected)
{
- PJ *pj = getPJ(env, projected);
+ projPJ pj = getPJ(env, projected);
return (pj) ? (jlong) pj_latlong_from_proj(pj) : 0;
}
@@ -102,7 +102,7 @@ JNIEXPORT jlong JNICALL Java_org_apache_
JNIEXPORT jstring JNICALL Java_org_apache_sis_storage_gdal_PJ_getCode
(JNIEnv *env, jobject object)
{
- PJ *pj = getPJ(env, object);
+ projPJ pj = getPJ(env, object);
if (pj) {
const char *desc = pj_get_def(pj, 0);
if (desc) {
@@ -116,27 +116,6 @@ JNIEXPORT jstring JNICALL Java_org_apach
/*!
* \brief
- * Returns the description associated to the PJ structure.
- *
- * \param env - The JNI environment.
- * \param object - The Java object wrapping the PJ structure (not allowed to be NULL).
- * \return The description associated to the PJ structure.
- */
-JNIEXPORT jstring JNICALL Java_org_apache_sis_storage_gdal_PJ_getName
- (JNIEnv *env, jobject object)
-{
- PJ *pj = getPJ(env, object);
- if (pj) {
- const char *desc = pj->descr;
- if (desc) {
- return (*env)->NewStringUTF(env, desc);
- }
- }
- return NULL;
-}
-
-/*!
- * \brief
* Returns the CRS type as one of the PJ.Type enum: GEOGRAPHIC, GEOCENTRIC or PROJECTED.
* This function should never return NULL, unless class or fields have been renamed in
* such a way that we can not find anymore the expected enum values.
@@ -148,7 +127,7 @@ JNIEXPORT jstring JNICALL Java_org_apach
JNIEXPORT jobject JNICALL Java_org_apache_sis_storage_gdal_PJ_getType
(JNIEnv *env, jobject object)
{
- PJ *pj = getPJ(env, object);
+ projPJ pj = getPJ(env, object);
if (pj) {
const char *type;
if (pj_is_latlong(pj)) {
@@ -171,76 +150,27 @@ JNIEXPORT jobject JNICALL Java_org_apach
/*!
* \brief
- * Returns the semi-major axis length.
- *
- * \param env - The JNI environment.
- * \param object - The Java object wrapping the PJ structure (not allowed to be NULL).
- * \return The semi-major axis length.
- */
-JNIEXPORT jdouble JNICALL Java_org_apache_sis_storage_gdal_PJ_getSemiMajorAxis
- (JNIEnv *env, jobject object)
-{
- PJ *pj = getPJ(env, object);
- return pj ? pj->a_orig : NAN;
-}
-
-/*!
- * \brief
- * Computes the semi-minor axis length from the semi-major axis length and the eccentricity
- * squared.
- *
- * \param env - The JNI environment.
- * \param object - The Java object wrapping the PJ structure (not allowed to be NULL).
- * \return The semi-minor axis length.
- */
-JNIEXPORT jdouble JNICALL Java_org_apache_sis_storage_gdal_PJ_getSemiMinorAxis
- (JNIEnv *env, jobject object)
-{
- PJ *pj = getPJ(env, object);
- if (!pj) return NAN;
- double a = pj->a_orig;
- return sqrt(a*a * (1.0 - pj->es_orig));
-}
-
-/*!
- * \brief
- * Returns the eccentricity squared.
- *
- * \param env - The JNI environment.
- * \param object - The Java object wrapping the PJ structure (not allowed to be NULL).
- * \return The eccentricity.
- */
-JNIEXPORT jdouble JNICALL Java_org_apache_sis_storage_gdal_PJ_getEccentricitySquared
- (JNIEnv *env, jobject object)
-{
- PJ *pj = getPJ(env, object);
- return pj ? pj->es_orig : NAN;
-}
-
-/*!
- * \brief
- * Returns an array of character indicating the direction of each axis.
+ * Returns the semi-major axis length and eccentricity squared in an array of length 2.
*
* \param env - The JNI environment.
* \param object - The Java object wrapping the PJ structure (not allowed to be NULL).
- * \return The axis directions.
+ * \return The semi-major axis length and eccentricity squared in an array of length 2.
*/
-JNIEXPORT jcharArray JNICALL Java_org_apache_sis_storage_gdal_PJ_getAxisDirections
+JNIEXPORT jdoubleArray JNICALL Java_org_apache_sis_storage_gdal_PJ_getEllipsoidDefinition
(JNIEnv *env, jobject object)
{
- PJ *pj = getPJ(env, object);
+ projPJ pj = getPJ(env, object);
if (pj) {
- int length = strlen(pj->axis);
- jcharArray array = (*env)->NewCharArray(env, length);
+ double major_axis;
+ double eccentricity_squared;
+ pj_get_spheroid_defn(pj, &major_axis, &eccentricity_squared);
+ jdoubleArray array = (*env)->NewDoubleArray(env, 2);
if (array) {
- jchar* axis = (*env)->GetCharArrayElements(env, array, NULL);
- if (axis) {
- // Don't use memcp because the type may not be the same.
- int i;
- for (i=0; i<length; i++) {
- axis[i] = pj->axis[i];
- }
- (*env)->ReleaseCharArrayElements(env, array, axis, 0);
+ jdouble* def = (*env)->GetDoubleArrayElements(env, array, NULL);
+ if (def) {
+ def[0] = major_axis;
+ def[1] = eccentricity_squared;
+ (*env)->ReleaseDoubleArrayElements(env, array, def, 0);
}
return array;
}
@@ -250,40 +180,6 @@ JNIEXPORT jcharArray JNICALL Java_org_ap
/*!
* \brief
- * Longitude of the prime meridian measured from the Greenwich meridian, positive eastward.
- *
- * \param env - The JNI environment.
- * \param object - The Java object wrapping the PJ structure (not allowed to be NULL).
- * \return The prime meridian longitude, in degrees.
- */
-JNIEXPORT jdouble JNICALL Java_org_apache_sis_storage_gdal_PJ_getGreenwichLongitude
- (JNIEnv *env, jobject object)
-{
- PJ *pj = getPJ(env, object);
- return (pj) ? (pj->from_greenwich)*(180/M_PI) : NAN;
-}
-
-/*!
- * \brief
- * Returns the conversion factor from linear units to metres.
- *
- * \param env - The JNI environment.
- * \param object - The Java object wrapping the PJ structure (not allowed to be NULL).
- * \param vertical - JNI_FALSE for horizontal axes, or JNI_TRUE for the vertical axis.
- * \return The conversion factor to metres.
- */
-JNIEXPORT jdouble JNICALL Java_org_apache_sis_storage_gdal_PJ_getLinearUnitToMetre
- (JNIEnv *env, jobject object, jboolean vertical)
-{
- PJ *pj = getPJ(env, object);
- if (pj) {
- return (vertical) ? pj->vto_meter : pj->to_meter;
- }
- return NAN;
-}
-
-/*!
- * \brief
* Converts input values from degrees to radians before coordinate operation, or the output
* values from radians to degrees after the coordinate operation.
*
@@ -293,7 +189,7 @@ JNIEXPORT jdouble JNICALL Java_org_apach
* \param dimension - Dimension of points in the coordinate array.
* \param factor - The scale factor to apply: M_PI/180 for inputs or 180/M_PI for outputs.
*/
-void convertAngularOrdinates(PJ *pj, double* data, jint numPts, int dimension, double factor) {
+void convertAngularOrdinates(projPJ pj, double* data, jint numPts, int dimension, double factor) {
int dimToSkip;
if (pj_is_latlong(pj)) {
// Convert only the 2 first ordinates and skip all the other dimensions.
@@ -349,8 +245,8 @@ JNIEXPORT void JNICALL Java_org_apache_s
if (c) (*env)->ThrowNew(env, c, "Illegal offset or illegal number of points.");
return;
}
- PJ *src_pj = getPJ(env, object);
- PJ *dst_pj = getPJ(env, target);
+ projPJ src_pj = getPJ(env, object);
+ projPJ dst_pj = getPJ(env, target);
if (src_pj && dst_pj) {
// Using GetPrimitiveArrayCritical/ReleasePrimitiveArrayCritical rather than
// GetDoubleArrayElements/ReleaseDoubleArrayElements increase the chances that
@@ -385,9 +281,9 @@ JNIEXPORT void JNICALL Java_org_apache_s
JNIEXPORT jstring JNICALL Java_org_apache_sis_storage_gdal_PJ_getLastError
(JNIEnv *env, jobject object)
{
- PJ *pj = getPJ(env, object);
+ projPJ pj = getPJ(env, object);
if (pj) {
- int err = pj_ctx_get_errno(pj->ctx);
+ int err = *pj_get_errno_ref();
if (err) {
return (*env)->NewStringUTF(env, pj_strerrno(err));
}
@@ -412,7 +308,7 @@ JNIEXPORT void JNICALL Java_org_apache_s
{
jfieldID id = (*env)->GetFieldID(env, (*env)->GetObjectClass(env, object), PJ_FIELD_NAME, PJ_FIELD_TYPE);
if (id) {
- PJ *pj = (PJ*) (*env)->GetLongField(env, object, id);
+ projPJ pj = (projPJ) (*env)->GetLongField(env, object, id);
if (pj) {
(*env)->SetLongField(env, object, id, (jlong) 0);
pj_free(pj);
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=1802916&r1=1802915&r2=1802916&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] Tue Jul 25 10:46:31 2017
@@ -41,14 +41,6 @@ JNIEXPORT jstring JNICALL Java_org_apach
/*
* Class: org_apache_sis_storage_gdal_PJ
- * Method: getName
- * Signature: ()Ljava/lang/String;
- */
-JNIEXPORT jstring JNICALL Java_org_apache_sis_storage_gdal_PJ_getName
- (JNIEnv *, jobject);
-
-/*
- * Class: org_apache_sis_storage_gdal_PJ
* Method: getType
* Signature: ()Lorg/apache/sis/storage/gdal/PJ/Type;
*/
@@ -57,54 +49,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
- */
-JNIEXPORT jdouble JNICALL Java_org_apache_sis_storage_gdal_PJ_getSemiMajorAxis
- (JNIEnv *, jobject);
-
-/*
- * Class: org_apache_sis_storage_gdal_PJ
- * Method: getSemiMinorAxis
- * Signature: ()D
+ * Method: getEllipsoidDefinition
+ * Signature: ()[D
*/
-JNIEXPORT jdouble JNICALL Java_org_apache_sis_storage_gdal_PJ_getSemiMinorAxis
+JNIEXPORT jdoubleArray JNICALL Java_org_apache_sis_storage_gdal_PJ_getEllipsoidDefinition
(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: getAxisDirections
- * Signature: ()[C
- */
-JNIEXPORT jcharArray JNICALL Java_org_apache_sis_storage_gdal_PJ_getAxisDirections
- (JNIEnv *, jobject);
-
-/*
- * Class: org_apache_sis_storage_gdal_PJ
- * Method: getLinearUnitToMetre
- * Signature: (Z)D
- */
-JNIEXPORT jdouble JNICALL Java_org_apache_sis_storage_gdal_PJ_getLinearUnitToMetre
- (JNIEnv *, jobject, jboolean);
-
-/*
- * Class: org_apache_sis_storage_gdal_PJ
* Method: transform
* Signature: (Lorg/apache/sis/storage/gdal/PJ;I[DII)V
*/
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=1802916&r1=1802915&r2=1802916&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] Tue Jul 25 10:46:31 2017
@@ -32,9 +32,7 @@ import org.opengis.referencing.operation
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.iso.SimpleInternationalString;
import org.apache.sis.util.resources.Errors;
-import org.apache.sis.util.CharSequences;
import org.apache.sis.internal.util.Constants;
import org.apache.sis.internal.system.OS;
@@ -194,32 +192,11 @@ final class PJ implements Identifier, Se
/**
* Returns the string representation of the PJ structure.
- * Note that the string returned by Proj.4 contains <cite>End Of Line</cite> characters.
- *
- * <div class="note"><b>Example:</b> "Lat/long (Geodetic alias)"</div>
- */
- native String getName();
-
- /**
- * Returns the string representation of the PJ structure.
*
* @return the string representation, or {@code null} if none.
*/
@Override
public InternationalString getDescription() {
- String name = getName();
- if (name != null) {
- final StringBuilder buffer = new StringBuilder(name.length());
- for (CharSequence line : CharSequences.splitOnEOL(getName())) {
- line = CharSequences.trimWhitespaces(line);
- if (buffer.length() != 0) buffer.append(' ');
- buffer.append(line);
- }
- name = buffer.toString();
- if (!name.isEmpty()) {
- return new SimpleInternationalString(name);
- }
- }
return null;
}
@@ -261,69 +238,21 @@ final class PJ implements Identifier, Se
}
/**
- * 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 semi-major axis length and 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. Other related quantities are:
+ *
+ * <ul>
+ * <li>semi-minor axis length: b = a × √(1 - ε²)</li>
+ * <li>inverse flattening: invf = 1 / (1 - √(1 - ε²))</li>
+ * </ul>
*
- * @return the eccentricity.
+ * @return the semi-major axis length and the eccentricity squared in an array of length 2.
*
* @see Ellipsoid#isSphere()
* @see Ellipsoid#getInverseFlattening()
*/
- public native double getEccentricitySquared();
-
- /**
- * Returns the inverse flattening, computed from the eccentricity.
- * The inverse flattening factor of a sphere is infinity.
- */
- public double getInverseFlattening() {
- return 1 / (1 - Math.sqrt(1 - getEccentricitySquared()));
- }
-
- /**
- * Returns the value stored in the {@code a_orig} PJ field.
- *
- * @return the axis length stored in {@code a_orig}.
- *
- * @see Ellipsoid#getSemiMajorAxis()
- */
- 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 Ellipsoid#getSemiMinorAxis()
- */
- public native double getSemiMinorAxis();
-
- /**
- * Longitude of the prime meridian measured from the Greenwich meridian, positive eastward.
- *
- * @return the prime meridian longitude, in degrees.
- *
- * @see PrimeMeridian#getGreenwichLongitude()
- */
- public native double getGreenwichLongitude();
-
- /**
- * Returns an array of character indicating the direction of each axis. Directions are
- * characters like {@code 'e'} for East, {@code 'n'} for North and {@code 'u'} for Up.
- *
- * @return the axis directions.
- *
- * @see org.opengis.referencing.cs.CoordinateSystemAxis#getDirection()
- */
- public native char[] getAxisDirections();
-
- /**
- * Returns the conversion factor from the linear units to metres.
- *
- * @param vertical {@code false} for the conversion factor of horizontal axes,
- * 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);
+ public native double[] getEllipsoidDefinition();
/**
* Transforms in-place the coordinates in the given array.
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=1802916&r1=1802915&r2=1802916&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] Tue Jul 25 10:46:31 2017
@@ -18,6 +18,7 @@ package org.apache.sis.storage.gdal;
import javax.measure.Unit;
import javax.measure.quantity.Angle;
+import javax.measure.format.ParserException;
import org.opengis.metadata.Identifier;
import org.opengis.util.FactoryException;
import org.opengis.parameter.ParameterValue;
@@ -40,6 +41,7 @@ import org.opengis.referencing.operation
import org.opengis.referencing.operation.CoordinateOperation;
import org.apache.sis.referencing.operation.AbstractCoordinateOperation;
import org.apache.sis.referencing.factory.UnavailableFactoryException;
+import org.apache.sis.referencing.factory.InvalidGeodeticParameterException;
import org.apache.sis.referencing.IdentifiedObjects;
import org.apache.sis.referencing.CRS;
import org.apache.sis.metadata.iso.citation.Citations;
@@ -311,6 +313,8 @@ public final class Proj4 extends Static
definition = definition.trim();
try {
return Proj4Factory.INSTANCE.createCRS(definition, dimension >= 3);
+ } catch (IllegalArgumentException | ParserException e) {
+ throw new InvalidGeodeticParameterException(canNotParse(definition), e);
} catch (UnsatisfiedLinkError | NoClassDefFoundError e) {
throw new UnavailableFactoryException(unavailable(e), e);
}
@@ -376,4 +380,11 @@ public final class Proj4 extends Static
}
return message;
}
+
+ /**
+ * Returns the error message for a {@literal Proj.4} string that can not be parsed.
+ */
+ static String canNotParse(final String code) {
+ return Errors.format(Errors.Keys.CanNotParse_1, code);
+ }
}
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=1802916&r1=1802915&r2=1802916&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 10:46:31 2017
@@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Collections;
import javax.measure.Unit;
+import javax.measure.format.ParserException;
import org.opengis.util.FactoryException;
import org.opengis.util.NoSuchIdentifierException;
import org.opengis.metadata.Identifier;
@@ -509,39 +510,14 @@ public class Proj4Factory extends Geodet
}
try {
return createCRS(code, hasHeight);
+ } catch (IllegalArgumentException | ParserException e) {
+ throw new InvalidGeodeticParameterException(Proj4.canNotParse(code), e);
} catch (UnsatisfiedLinkError | NoClassDefFoundError e) {
throw new UnavailableFactoryException(Proj4.unavailable(e), e);
}
}
/**
- * 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}
- * property value in constructors.
- *
- * @param definition the Proj.4 definition string to parse.
- * @param keyword the parameter name.
- * @return the parameter value as an identifier.
- */
- private Map<String,Object> identifier(final String definition, final String keyword) {
- String value = "";
- if (keyword != null) {
- int i = definition.indexOf(keyword);
- if (i >= 0) {
- i += keyword.length();
- final int stop = definition.indexOf(' ', i);
- value = (stop >= 0) ? definition.substring(i, stop) : definition.substring(i);
- value = value.trim();
- }
- }
- if (value.isEmpty()) {
- value = "Unnamed";
- }
- return identifier(value);
- }
-
- /**
* Returns the identifier for the given code in {@literal Proj.4} namespace.
*/
private Map<String,Object> identifier(final String code) {
@@ -560,20 +536,24 @@ public class Proj4Factory extends Geodet
/**
* Creates a geodetic datum from the given {@literal Proj.4} wrapper.
*
- * @param pj the Proj.4 object to wrap.
+ * @param pj the Proj.4 object to wrap.
+ * @param parser the parameter values of the Proj.4 object to wrap.
+ * @throws NumberFormatException if a Proj.4 parameter value can not be parsed.
*/
- private GeodeticDatum createDatum(final PJ pj) throws FactoryException {
+ private GeodeticDatum createDatum(final PJ pj, final Proj4Parser parser) throws FactoryException {
final PrimeMeridian pm;
- final double greenwichLongitude = pj.getGreenwichLongitude();
+ final double greenwichLongitude = Double.parseDouble(parser.value("pm", "0"));
if (greenwichLongitude == 0) {
pm = CommonCRS.WGS84.datum().getPrimeMeridian();
} else {
pm = datumFactory.createPrimeMeridian(identifier("Unnamed"), greenwichLongitude, Units.DEGREE);
}
- final String definition = pj.getCode();
- return datumFactory.createGeodeticDatum(identifier(definition, "+datum="),
- datumFactory.createEllipsoid (identifier(definition, "+ellps="),
- pj.getSemiMajorAxis(), pj.getSemiMinorAxis(), Units.METRE), pm);
+ final double[] def = pj.getEllipsoidDefinition();
+ 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);
}
/**
@@ -582,14 +562,17 @@ public class Proj4Factory extends Geodet
*
* @param pj the Proj.4 object to wrap.
* @param withHeight whether to include a height axis.
+ * @throws IllegalArgumentException if a Proj.4 parameter value can not be parsed or assigned.
+ * @throws ParserException if a unit symbol can not be parsed.
*/
private CoordinateReferenceSystem createCRS(final PJ pj, final boolean withHeight) throws FactoryException {
final PJ.Type type = pj.getType();
final boolean geographic = PJ.Type.GEOGRAPHIC.equals(type);
- final char[] dir = pj.getAxisDirections();
- final CoordinateSystemAxis[] axes = new CoordinateSystemAxis[withHeight ? dir.length : 2];
+ final Proj4Parser parser = new Proj4Parser(pj.getCode());
+ final String dir = parser.value("axis", "enu");
+ final CoordinateSystemAxis[] axes = new CoordinateSystemAxis[withHeight ? dir.length() : 2];
for (int i=0; i<axes.length; i++) {
- final char d = Character.toLowerCase(dir[i]);
+ final char d = Character.toLowerCase(dir.charAt(i));
char abbreviation = Character.toUpperCase(d);
boolean vertical = false;
final AxisDirection c;
@@ -606,7 +589,7 @@ public class Proj4Factory extends Geodet
if (geographic && AxisDirections.isCardinal(c)) {
abbreviation = (d == 'e' || d == 'w') ? 'λ' : 'φ';
}
- final Unit<?> unit = (vertical || !geographic) ? Units.METRE.divide(pj.getLinearUnitToMetre(vertical)) : Units.DEGREE;
+ final Unit<?> unit = (vertical || !geographic) ? parser.unit(vertical) : Units.DEGREE;
axes[i] = csFactory.createCoordinateSystemAxis(identifier(name), String.valueOf(abbreviation).intern(), c, unit);
}
/*
@@ -619,12 +602,12 @@ public class Proj4Factory extends Geodet
name.put(CoordinateReferenceSystem.IDENTIFIERS_KEY, pj);
switch (type) {
case GEOGRAPHIC: {
- return crsFactory.createGeographicCRS(name, createDatum(pj), withHeight ?
+ return crsFactory.createGeographicCRS(name, createDatum(pj, parser), withHeight ?
csFactory.createEllipsoidalCS(csName, axes[0], axes[1], axes[2]) :
csFactory.createEllipsoidalCS(csName, axes[0], axes[1]));
}
case GEOCENTRIC: {
- return crsFactory.createGeocentricCRS(name, createDatum(pj),
+ return crsFactory.createGeocentricCRS(name, createDatum(pj, parser),
csFactory.createCartesianCS(csName, axes[0], axes[1], axes[2]));
}
case PROJECTED: {
@@ -641,7 +624,6 @@ public class Proj4Factory extends Geodet
OperationMethod method;
ParameterValueGroup parameters;
try {
- final Proj4Parser parser = new Proj4Parser(pj.getCode());
method = parser.method(opFactory());
parameters = parser.parameters();
} catch (IllegalArgumentException | FactoryException e) {
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=1802916&r1=1802915&r2=1802916&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 10:46:31 2017
@@ -21,6 +21,9 @@ import java.util.Map;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Locale;
+import javax.measure.Unit;
+import javax.measure.format.ParserException;
+import org.apache.sis.measure.Units;
import org.opengis.util.FactoryException;
import org.opengis.parameter.ParameterValue;
import org.opengis.parameter.ParameterValueGroup;
@@ -45,13 +48,16 @@ final class Proj4Parser {
* We ignore those parameters because they define for example the datum, prime meridian, <i>etc</i>.
* Those information will be fetched by other classes than this {@code Proj4Parser}.
*/
- private static final Set<String> EXCLUDES = new HashSet<>(12);
+ private static final Set<String> EXCLUDES = new HashSet<>(16);
static {
EXCLUDES.add("init"); // Authority code
EXCLUDES.add("datum"); // Geodetic datum name
EXCLUDES.add("ellps"); // Ellipsoid name
EXCLUDES.add("pm"); // Prime meridian
EXCLUDES.add("units"); // Axis units
+ EXCLUDES.add("vunits"); // Vertical axis units
+ EXCLUDES.add("to_meter"); // Axis units conversion factor
+ EXCLUDES.add("vto_meter"); // Vertical axis units conversion factor
EXCLUDES.add("towgs84"); // Datum shift
EXCLUDES.add("axis"); // Axis order
}
@@ -83,12 +89,10 @@ final class Proj4Parser {
final int next = definition.indexOf('+', start);
if (end >= 0 && (next < 0 || end < next)) {
final String keyword = CharSequences.trimWhitespaces(definition, start, end).toString().toLowerCase(Locale.US);
- if (!EXCLUDES.contains(keyword)) {
- 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));
- }
+ 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));
}
}
start = next;
@@ -96,6 +100,15 @@ final class Proj4Parser {
}
/**
+ * 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;
+ }
+
+ /**
* Returns the operation method inferred from the {@code "proj"} parameter value.
* This method must be invoked at least once before {@link #parameters()}.
*/
@@ -118,9 +131,36 @@ final class Proj4Parser {
final ParameterValueGroup parameters() throws IllegalArgumentException {
final ParameterValueGroup pg = method.getParameters().createValue();
for (final Map.Entry<String,String> entry : parameters.entrySet()) {
- final ParameterValue<?> value = pg.parameter(entry.getKey());
- value.setValue(Double.parseDouble(entry.getValue()));
+ 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));
+ }
+ }
}
return pg;
}
+
+ /**
+ * Returns the vertical or horizontal axis unit.
+ * This unit applies only to linear axes, not angular axes neither parameters.
+ *
+ * @param vertical {@code true} for querying the vertical unit, or {@code false} for the horizontal one.
+ * @return the vertical or horizontal axis unit of measurement, or {@code Units.METRE} if unspecified.
+ * @throws NumberFormatException if the unit conversion factor can not be parsed.
+ * @throws ParserException if the unit symbol can not be parsed.
+ */
+ final Unit<?> unit(final boolean vertical) throws ParserException {
+ String v = parameters.remove(vertical ? "vto_meter" : "to_meter");
+ if (v != null && !v.isEmpty()) {
+ return Units.METRE.divide(Double.parseDouble(v));
+ }
+ v = parameters.remove(vertical ? "vunits" : "units");
+ if (v != null && !v.isEmpty()) {
+ return Units.valueOf(v);
+ }
+ return Units.METRE;
+ }
}
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=1802916&r1=1802915&r2=1802916&view=diff
==============================================================================
Binary files - no diff available.
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=1802916&r1=1802915&r2=1802916&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] Tue Jul 25 10:46:31 2017
@@ -60,18 +60,15 @@ public final strictfp class PJTest exten
* Ensures that the given object is the WGS84 definition.
*/
private static void assertIsWGS84(final PJ pj) {
- assertEquals("Lat/long (Geodetic alias)", pj.getName().trim());
assertEquals("+proj=latlong +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0", pj.getCode().trim());
assertEquals("Proj4", pj.getCodeSpace());
assertSame (Citations.PROJ4, pj.getAuthority());
assertTrue (Character.isDigit( pj.getVersion().codePointAt(0)));
assertEquals(PJ.Type.GEOGRAPHIC, pj.getType());
- assertEquals(6378137.0, pj.getSemiMajorAxis(), 1E-9);
- assertEquals(6356752.314245179, pj.getSemiMinorAxis(), 1E-9);
- assertEquals(298.257223563, pj.getInverseFlattening(), 1E-9);
- assertEquals(0.0, pj.getGreenwichLongitude(), STRICT);
- assertEquals(1.0, pj.getLinearUnitToMetre(true), STRICT);
- assertArrayEquals(new char[] {'e', 'n', 'u'}, pj.getAxisDirections());
+ final double[] ellps = pj.getEllipsoidDefinition();
+ assertEquals(2, ellps.length);
+ ellps[1] = 1 / (1 - StrictMath.sqrt(1 - ellps[1])); // Replace eccentricity squared by inverse flattening.
+ assertArrayEquals(new double[] {6378137.0, 298.257223563}, ellps, 1E-9);
}
/**
@@ -94,13 +91,15 @@ public final strictfp class PJTest exten
public void testEPSG3395() throws FactoryException {
final PJ pj = new PJ("+init=epsg:3395");
assertEquals(PJ.Type.PROJECTED, pj.getType());
- assertArrayEquals(new char[] {'e', 'n', 'u'}, pj.getAxisDirections());
- assertEquals(1.0, pj.getLinearUnitToMetre(true), STRICT);
+ final String definition = pj.getCode();
+ assertTrue(definition, definition.contains("+proj=merc"));
+ assertTrue(definition, definition.contains("+datum=WGS84"));
+ assertTrue(definition, definition.contains("+units=m"));
assertIsWGS84(new PJ(pj));
}
/**
- * Tests the {@link PJ#getLinearUnitToMetre(boolean)} method.
+ * Tests the units of measurement.
*
* @throws FactoryException if the Proj.4 definition string used in this test is invalid.
*/
@@ -108,9 +107,11 @@ public final strictfp class PJTest exten
public void testGetLinearUnit() throws FactoryException {
PJ pj;
pj = new PJ("+proj=merc +to_meter=1");
- assertEquals(1, pj.getLinearUnitToMetre(false), STRICT);
+ String definition = pj.getCode();
+ assertTrue(definition, definition.contains("+to_meter=1"));
pj = new PJ("+proj=merc +to_meter=0.001");
- assertEquals(0.001, pj.getLinearUnitToMetre(false), STRICT);
+ definition = pj.getCode();
+ assertTrue(definition, definition.contains("+to_meter=0.001"));
}
/**
@@ -161,21 +162,9 @@ public final strictfp class PJTest exten
public void testNaN() throws FactoryException {
final PJ pj = new PJ("+proj=latlong +datum=WGS84");
pj.finalize(); // This cause the disposal of the internal PJ structure.
+ assertNull(pj.getCode());
assertNull(pj.getType());
- assertNaN(pj.getSemiMajorAxis());
- assertNaN(pj.getSemiMinorAxis());
- assertNaN(pj.getEccentricitySquared());
- assertNaN(pj.getGreenwichLongitude());
- assertNaN(pj.getLinearUnitToMetre(false));
- assertNaN(pj.getLinearUnitToMetre(true));
- }
-
- /**
- * Asserts that the bits pattern of the given value is strictly identical to the bits
- * pattern of the {@link java.lang.Double#NaN} constant.
- */
- private static void assertNaN(final double value) {
- assertEquals(Double.doubleToRawLongBits(Double.NaN), Double.doubleToRawLongBits(value));
+ assertNull(pj.getEllipsoidDefinition());
}
/**
Modified: sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4FactoryTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4FactoryTest.java?rev=1802916&r1=1802915&r2=1802916&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4FactoryTest.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4FactoryTest.java [UTF-8] Tue Jul 25 10:46:31 2017
@@ -19,6 +19,7 @@ package org.apache.sis.storage.gdal;
import java.util.Arrays;
import org.opengis.util.FactoryException;
import org.opengis.geometry.DirectPosition;
+import org.opengis.referencing.cs.AxisDirection;
import org.opengis.referencing.crs.ProjectedCRS;
import org.opengis.referencing.crs.GeographicCRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
@@ -77,12 +78,12 @@ public final strictfp class Proj4Factory
public void test4326() throws FactoryException {
final Proj4Factory factory = Proj4Factory.INSTANCE;
final GeographicCRS crs = factory.createGeographicCRS("+init=epsg:4326");
- /*
- * Use Proj.4 specific API to check axis order.
- */
final PJ pj = (PJ) TestUtilities.getSingleton(crs.getIdentifiers());
assertEquals(PJ.Type.GEOGRAPHIC, pj.getType());
- assertArrayEquals(new char[] {'e', 'n', 'u'}, pj.getAxisDirections());
+ final String definition = pj.getCode();
+ assertTrue(definition, definition.contains("+proj=longlat"));
+ assertTrue(definition, definition.contains("+datum=WGS84"));
+ assertAxisDirectionsEqual(definition, crs.getCoordinateSystem(), AxisDirection.EAST, AxisDirection.NORTH);
}
/**
@@ -94,12 +95,12 @@ public final strictfp class Proj4Factory
public void test3395() throws FactoryException {
final Proj4Factory factory = Proj4Factory.INSTANCE;
final ProjectedCRS crs = factory.createProjectedCRS("+init=epsg:3395");
- /*
- * Use Proj.4 specific API to check axis order.
- */
final PJ pj = (PJ) TestUtilities.getSingleton(crs.getIdentifiers());
assertEquals(PJ.Type.PROJECTED, pj.getType());
- assertArrayEquals(new char[] {'e', 'n', 'u'}, pj.getAxisDirections());
+ final String definition = pj.getCode();
+ assertTrue(definition, definition.contains("+proj=merc"));
+ assertTrue(definition, definition.contains("+datum=WGS84"));
+ assertAxisDirectionsEqual(definition, crs.getCoordinateSystem(), AxisDirection.EAST, AxisDirection.NORTH);
}
/**
Modified: sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4ParserTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4ParserTest.java?rev=1802916&r1=1802915&r2=1802916&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4ParserTest.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4ParserTest.java [UTF-8] Tue Jul 25 10:46:31 2017
@@ -21,6 +21,7 @@ import org.opengis.referencing.operation
import org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory;
import org.apache.sis.internal.referencing.provider.Mercator1SP;
import org.apache.sis.internal.system.DefaultFactories;
+import org.apache.sis.measure.Units;
import org.apache.sis.test.TestCase;
import org.junit.Test;
import org.opengis.parameter.ParameterValueGroup;
@@ -62,5 +63,21 @@ public final strictfp class Proj4ParserT
assertInstanceOf("method", Mercator1SP.class, parser.method(opFactory));
final ParameterValueGroup pg = parser.parameters();
assertEquals("scale_factor", pg.parameter("scale_factor").getValue(), 1.0);
+ assertEquals(Units.METRE, parser.unit(false));
+ }
+
+ /**
+ * Tests parsing a definition string with axes in kilometres.
+ *
+ * @throws FactoryException if the parsing failed.
+ */
+ @Test
+ public void testKilometres() throws FactoryException {
+ final Proj4Parser parser = new Proj4Parser("+proj=merc +to_meter=0.001");
+
+ assertInstanceOf("method", Mercator1SP.class, parser.method(opFactory));
+ final ParameterValueGroup pg = parser.parameters();
+ assertEquals("scale_factor", pg.parameter("scale_factor").getValue(), 1.0);
+ assertEquals(Units.KILOMETRE, parser.unit(false));
}
}