sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1802070 - in /sis/branches/JDK8: core/sis-referencing/src/main/java/org/apache/sis/parameter/ ide-project/NetBeans/ storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/ storage/sis-gdal/src/main/resources/org/ storage/sis-gdal/src/t...
Date Sun, 16 Jul 2017 15:31:09 GMT
Author: desruisseaux
Date: Sun Jul 16 15:31:08 2017
New Revision: 1802070

URL: http://svn.apache.org/viewvc?rev=1802070&view=rev
Log:
Add test case for pj_transform.

Removed:
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/ResourcesLoader.java
    sis/branches/JDK8/storage/sis-gdal/src/main/resources/org/
Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterFormat.java
    sis/branches/JDK8/ide-project/NetBeans/build.xml
    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/Transform.java
    sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4FactoryTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterFormat.java?rev=1802070&r1=1802069&r2=1802070&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterFormat.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterFormat.java
[UTF-8] Sun Jul 16 15:31:08 2017
@@ -687,7 +687,8 @@ public class ParameterFormat extends Tab
                 /*
                  * Writes the values, each on its own line, together with their unit of measurement.
                  */
-                table.setCellAlignment(TableAppender.ALIGN_RIGHT);
+                final byte alignment = Number.class.isAssignableFrom(valueClass) ? TableAppender.ALIGN_RIGHT
: TableAppender.ALIGN_LEFT;
+                table.setCellAlignment(alignment);
                 final int length = row.values.size();
                 for (int i=0; i<length; i++) {
                     Object value = row.values.get(i);
@@ -705,7 +706,7 @@ public class ParameterFormat extends Tab
                                 table.append(ditto);
                                 nextColumn(table);
                             }
-                            table.setCellAlignment(TableAppender.ALIGN_RIGHT);
+                            table.setCellAlignment(alignment);
                         }
                         /*
                          * Format the value followed by the unit of measure, or followed
by spaces if there is no unit

Modified: sis/branches/JDK8/ide-project/NetBeans/build.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/ide-project/NetBeans/build.xml?rev=1802070&r1=1802069&r2=1802070&view=diff
==============================================================================
--- sis/branches/JDK8/ide-project/NetBeans/build.xml (original)
+++ sis/branches/JDK8/ide-project/NetBeans/build.xml Sun Jul 16 15:31:08 2017
@@ -74,7 +74,6 @@
         <include name="**/*.properties"/>
       </fileset>
       <fileset dir="${project.root}/storage/sis-gdal/src/main/resources">
-        <include name="**/*.txt"/>
         <include name="**/*.dll"/>
         <include name="**/*.so"/>
       </fileset>

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=1802070&r1=1802069&r2=1802070&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] Sun Jul 16 15:31:08 2017
@@ -22,6 +22,7 @@ import org.opengis.util.FactoryException
 import org.opengis.parameter.ParameterValue;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.parameter.GeneralParameterValue;
+import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.crs.GeodeticCRS;
 import org.opengis.referencing.crs.ProjectedCRS;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
@@ -34,6 +35,8 @@ import org.opengis.referencing.datum.Geo
 import org.opengis.referencing.datum.PrimeMeridian;
 import org.opengis.referencing.operation.CoordinateOperation;
 import org.apache.sis.referencing.factory.UnavailableFactoryException;
+import org.apache.sis.referencing.IdentifiedObjects;
+import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.internal.metadata.AxisDirections;
 import org.apache.sis.internal.system.Modules;
 import org.apache.sis.internal.system.OS;
@@ -42,6 +45,7 @@ import org.apache.sis.util.resources.Err
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.Static;
 import org.apache.sis.measure.Units;
+import org.opengis.referencing.operation.Projection;
 
 
 /**
@@ -105,9 +109,10 @@ public final class Proj4 extends Static
             datum      = ((GeodeticCRS) crs).getDatum();
             parameters = null;
         } else if (crs instanceof ProjectedCRS) {
-            datum      = ((ProjectedCRS) crs).getDatum();
-            parameters = ((ProjectedCRS) crs).getConversionFromBase().getParameterValues();
-            method     = ResourcesLoader.getProjName(parameters, false).substring(1);
+            Projection c = ((ProjectedCRS) crs).getConversionFromBase();
+            datum        = ((ProjectedCRS) crs).getDatum();
+            method       = name(c.getMethod());
+            parameters   = c.getParameterValues();
         } else {
             throw new FactoryException(Errors.format(Errors.Keys.UnsupportedType_1, crs.getClass()));
         }
@@ -125,7 +130,7 @@ public final class Proj4 extends Static
                 if (parameter instanceof ParameterValue) {
                     final Object value = ((ParameterValue) parameter).getValue();
                     if (value != null) {
-                        final String pn = ResourcesLoader.getProjName(parameter, true);
+                        final String pn = name(parameter.getDescriptor());
                         if (pn.equals("+a")) hasSemiMajor = true;
                         if (pn.equals("+b")) hasSemiMinor = true;
                         definition.append(' ').append(pn).append('=').append(value);
@@ -172,6 +177,18 @@ public final class Proj4 extends Static
     }
 
     /**
+     * Returns the {@literal Proj.4} name for the given parameter,
+     * or throws an exception if the {@literal Proj.4} name is unknown.
+     */
+    private static String name(final IdentifiedObject object) throws FactoryException {
+        final String name = IdentifiedObjects.getName(object, Citations.PROJ4);
+        if (name == null) {
+            throw new FactoryException(Errors.format(Errors.Keys.CanNotSetParameterValue_1,
object.getName()));
+        }
+        return name;
+    }
+
+    /**
      * Creates a new CRS from the given {@literal Proj.4} definition string.
      *
      * @param  definition  the Proj.4 definition string.
@@ -179,6 +196,8 @@ public final class Proj4 extends Static
      * @return a CRS created from the given definition string and number of dimensions.
      * @throws NullPointerException if the definition string is {@code null}.
      * @throws FactoryException if one of the given argument has an invalid value.
+     *
+     * @see Proj4Factory#createCoordinateReferenceSystem(String)
      */
     public static CoordinateReferenceSystem createCRS(String definition, final int dimension)
throws FactoryException {
         definition = definition.trim();
@@ -193,11 +212,16 @@ public final class Proj4 extends Static
 
     /**
      * Creates an operation for conversion or transformation between two coordinate reference
systems.
+     * This implementation always uses Proj.4 for performing the coordinate operations, regardless
if
+     * the given CRS were created from a Proj.4 definition string or not. This method fails
if it can
+     * not map the given CRS to Proj.4 structures.
      *
      * @param  sourceCRS   the source coordinate reference system.
      * @param  targetCRS   the target coordinate reference system.
      * @return a coordinate operation for transforming coordinates from the given source
CRS to the given target CRS.
      * @throws FactoryException if an error occurred while creating the coordinate operation.
+     *
+     * @see Proj4Factory#createOperation(CoordinateReferenceSystem, CoordinateReferenceSystem)
      */
     public static CoordinateOperation createOperation(final CoordinateReferenceSystem sourceCRS,
                                                       final CoordinateReferenceSystem targetCRS)

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=1802070&r1=1802069&r2=1802070&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] Sun Jul 16 15:31:08 2017
@@ -254,6 +254,8 @@ public class Proj4Factory extends Geodet
      * @param  code  the Proj.4 definition of the CRS object to create.
      * @return a CRS created from the given definition.
      * @throws FactoryException if the CRS object can not be created for the given definition.
+     *
+     * @see Proj4#createCRS(String, int)
      */
     @Override
     public CoordinateReferenceSystem createCoordinateReferenceSystem(String code) throws
FactoryException {
@@ -463,6 +465,7 @@ public class Proj4Factory extends Geodet
      * @param  withHeight  whether to include a height axis.
      *
      * @see Proj4#createCRS(String, int)
+     * @see #createCoordinateReferenceSystem(String)
      */
     final CoordinateReferenceSystem createCRS(final String definition, final boolean withHeight)
throws FactoryException {
         PJ pj = pool.get(definition);
@@ -483,6 +486,8 @@ public class Proj4Factory extends Geodet
      * @param  targetCRS  the target coordinate reference system.
      * @return a coordinate operation for transforming coordinates from the given source
CRS to the given target CRS.
      * @throws FactoryException if the given CRS are not instances recognized by this class.
+     *
+     * @see Proj4#createOperation(CoordinateReferenceSystem, CoordinateReferenceSystem)
      */
     public CoordinateOperation createOperation(final CoordinateReferenceSystem sourceCRS,
                                                final CoordinateReferenceSystem targetCRS)

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Transform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Transform.java?rev=1802070&r1=1802069&r2=1802070&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Transform.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Transform.java
[UTF-8] Sun Jul 16 15:31:08 2017
@@ -95,8 +95,8 @@ final class Transform extends AbstractMa
     @Override
     public ParameterValueGroup getParameterValues() {
         final ParameterValueGroup pg = getParameterDescriptors().createValue();
-        pg.parameter("srcdefn").setValue(source.getCode());
-        pg.parameter("dstdefn").setValue(target.getCode());
+        pg.parameter("srcdefn").setValue(source.getCode().trim());
+        pg.parameter("dstdefn").setValue(target.getCode().trim());
         return pg;
     }
 

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=1802070&r1=1802069&r2=1802070&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] Sun Jul 16 15:31:08 2017
@@ -18,16 +18,22 @@ package org.apache.sis.storage.gdal;
 
 import java.util.Arrays;
 import org.opengis.util.FactoryException;
+import org.opengis.geometry.DirectPosition;
 import org.opengis.referencing.crs.ProjectedCRS;
 import org.opengis.referencing.crs.GeographicCRS;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.operation.CoordinateOperation;
+import org.opengis.referencing.operation.Conversion;
+import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.TransformException;
+import org.apache.sis.geometry.DirectPosition2D;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.apache.sis.test.TestUtilities;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import static org.junit.Assert.*;
+import static org.opengis.test.Assert.*;
 
 
 /**
@@ -94,4 +100,25 @@ public final strictfp class Proj4Factory
         assertEquals(PJ.Type.PROJECTED, pj.getType());
         assertArrayEquals(new char[] {'e', 'n', 'u'}, pj.getAxisDirections());
     }
+
+    /**
+     * Tests the transformation from {@code "+init=epsg:4326"} to {@code "+init=epsg:3395"}.
+     *
+     * @throws FactoryException if an error occurred while creating the CRS objects.
+     * @throws TransformException if an error occurred while projecting a test point.
+     */
+    @Test
+    public void testTransform() throws FactoryException, TransformException {
+        final Proj4Factory  factory   = Proj4Factory.INSTANCE;
+        final GeographicCRS sourceCRS = factory.createGeographicCRS("+init=epsg:4326");
+        final ProjectedCRS  targetCRS = factory.createProjectedCRS("+init=epsg:3395");
+        final CoordinateOperation op  = factory.createOperation(sourceCRS, targetCRS);
+        assertInstanceOf("createOperation", Conversion.class, op);
+
+        final MathTransform mt = op.getMathTransform();
+        DirectPosition pt = new DirectPosition2D(20, 40);
+        pt = mt.transform(pt, pt);
+        assertEquals("Easting",  2226389.816, pt.getOrdinate(0), 0.01);
+        assertEquals("Northing", 4838471.398, pt.getOrdinate(1), 0.01);
+    }
 }



Mime
View raw message