sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1802647 [2/2] - in /sis/branches/JDK8: core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/ core/sis-referencing/src/main/java/org/apache/sis/ref...
Date Fri, 21 Jul 2017 22:34:29 GMT
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=1802647&r1=1802646&r2=1802647&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] Fri Jul 21 22:34:29 2017
@@ -17,6 +17,26 @@
 
 /**
  * Referencing services as wrapper around the C/C++ <a href="http://proj.osgeo.org/">{@literal
Proj.4}</a> library.
+ * Unless otherwise specified, this optional module requires the native (C/C++) Proj.4 library
to be installed
+ * on the local machine. This package allows to:
+ * <ul>
+ *   <li>{@linkplain org.apache.sis.storage.gdal.Proj4#createCRS Create a Coordinate
Reference System instance from a Proj.4 definition string}.</li>
+ *   <li>Conversely, {@linkplain org.apache.sis.storage.gdal.Proj4#definition get a
Proj.4 definition string from a Coordinate Reference System}.</li>
+ *   <li>{@linkplain org.apache.sis.storage.gdal.Proj4#createOperation Create a coordinate
operation backed by Proj.4 between two arbitrary CRS}.</li>
+ * </ul>
+ *
+ * Note that Apache SIS provides its own map projection engine in pure Java, so this module
is usually not needed.
+ * This module is useful when a desired map projection is not yet available in Apache SIS,
or when an application
+ * needs to reproduce the exact same numerical results than Proj.4. But some Apache SIS features
like
+ * {@linkplain org.apache.sis.referencing.operation.transform.AbstractMathTransform#derivative
transform derivatives}
+ * are not available through the Proj.4 wrappers.
+ *
+ * <div class="section">Installation</div>
+ * The Proj.4 library needs to be reachable on a platform-dependent library path.
+ * For example the operating system may search in the {@code /opt/local/lib} and other directories.
+ * One of those directories shall contain a {@code libproj.so}, {@code libproj.dylib} or
{@code proj.dll} file,
+ * depending on the platform. An easy way to install the library in appropriate directory
is to use the package
+ * manager provided by the platform.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @version 0.8

Added: sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/MTFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/MTFactory.java?rev=1802647&view=auto
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/MTFactory.java
(added)
+++ sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/MTFactory.java
[UTF-8] Fri Jul 21 22:34:29 2017
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.storage.gdal;
+
+import java.util.Map;
+import java.text.ParseException;
+import org.opengis.util.FactoryException;
+import org.opengis.util.NoSuchIdentifierException;
+import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.parameter.ParameterDescriptorGroup;
+import org.opengis.referencing.cs.CoordinateSystem;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.crs.CRSAuthorityFactory;
+import org.opengis.referencing.operation.Conversion;
+import org.opengis.referencing.operation.CoordinateOperation;
+import org.opengis.referencing.operation.CoordinateOperationFactory;
+import org.opengis.referencing.operation.MathTransformFactory;
+import org.opengis.referencing.operation.OperationMethod;
+import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.Matrix;
+import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.io.wkt.WKTFormat;
+
+
+/**
+ * Adds to {@link Proj4Factory} the missing method for making it a {@link MathTransformFactory}
implementation.
+ * We do not provide those methods in the main source directory yet because we are not sure
about exposing large
+ * amount of methods that are not really supported by Proj.4 wrappers. If experience shows
that it would be useful,
+ * selected methods from this class could be refactored into {@link Proj4Factory} in future
Apache SIS versions.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 0.8
+ * @since   0.8
+ * @module
+ */
+class MTFactory extends Proj4Factory implements CoordinateOperationFactory, MathTransformFactory
{
+    /**
+     * The WKT parser to use, created when first needed.
+     *
+     * @see #createFromWKT(String)
+     */
+    private transient WKTFormat parser;
+
+    /**
+     * Creates a new {@literal Proj.4} factory.
+     *
+     * @param properties  common properties for the objects to create, or {@code null} if
none.
+     */
+    public MTFactory(final Map<String,?> properties) {
+        super(properties);
+    }
+
+    /**
+     * Unsupported by the {@literal Proj.4} wrapper — delegates to the Apache SIS default
factory.
+     */
+    @Override
+    public OperationMethod createOperationMethod(Map<String,?> properties, Integer
sourceDimension,
+            Integer targetDimension, ParameterDescriptorGroup parameters) throws FactoryException
+    {
+        return opFactory().createOperationMethod(properties, sourceDimension, targetDimension,
parameters);
+    }
+
+    /**
+     * Ignores the given {@code method} argument and delegates to
+     * <code>{@linkplain #createOperation(CoordinateReferenceSystem, CoordinateReferenceSystem)
+     * createOperation}(sourceCRS, targetCRS)</code>.
+     *
+     * @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 the given CRS are not instances recognized by this class.
+     */
+    @Override
+    @Deprecated
+    public CoordinateOperation createOperation(final CoordinateReferenceSystem sourceCRS,
+                                               final CoordinateReferenceSystem targetCRS,
+                                               final OperationMethod method)
+            throws FactoryException
+    {
+        return createOperation(sourceCRS, targetCRS);
+    }
+
+    /**
+     * Unsupported by the {@literal Proj.4} wrapper — delegates to the Apache SIS default
factory.
+     */
+    @Override
+    public CoordinateOperation createConcatenatedOperation(Map<String,?> properties,
CoordinateOperation... operations)
+            throws FactoryException
+    {
+        return opFactory().createConcatenatedOperation(properties, operations);
+    }
+
+    /**
+     * Unsupported by the {@literal Proj.4} wrapper — delegates to the Apache SIS default
factory.
+     */
+    @Override
+    public Conversion createDefiningConversion(Map<String,?> properties, OperationMethod
method, ParameterValueGroup parameters)
+            throws FactoryException
+    {
+        return opFactory().createDefiningConversion(properties, method, parameters);
+    }
+
+    /**
+     * Unsupported by the {@literal Proj.4} wrapper.
+     */
+    @Override
+    public MathTransform createBaseToDerived(CoordinateReferenceSystem baseCRS, ParameterValueGroup
parameters, CoordinateSystem derivedCS)
+            throws NoSuchIdentifierException, FactoryException
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Unsupported by the {@literal Proj.4} wrapper.
+     */
+    @Override
+    public MathTransform createAffineTransform(Matrix matrix) throws FactoryException {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Not yet implemented.
+     */
+    @Override
+    public MathTransform createConcatenatedTransform(MathTransform transform1, MathTransform
transform2) throws FactoryException {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Unsupported by the {@literal Proj.4} wrapper.
+     */
+    @Override
+    public MathTransform createPassThroughTransform(int firstAffectedOrdinate, MathTransform
subTransform, int numTrailingOrdinates)
+            throws FactoryException
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Unconditionally returns the operation method that describes the {@literal Proj.4}
{@link Transform} wrapper
+     * since it is the only kind of operation created by this class.
+     */
+    @Override
+    public OperationMethod getLastMethodUsed() {
+        return Transform.METHOD;
+    }
+
+    /**
+     * Parses the given Well Known Text (version 1) into a math transform.
+     */
+    @Override
+    public synchronized MathTransform createFromWKT(final String wkt) throws FactoryException
{
+        ArgumentChecks.ensureNonEmpty("wkt", wkt);
+        if (parser == null) {
+            parser = new WKTFormat(null, null);
+            parser.setFactory(CRSAuthorityFactory.class, this);
+            parser.setFactory(MathTransformFactory.class, this);
+            parser.setFactory(CoordinateOperationFactory.class, this);
+        }
+        try {
+            return (MathTransform) parser.parseObject(wkt);
+        } catch (ParseException | ClassCastException e) {
+            throw new FactoryException(e);
+        }
+    }
+
+    /**
+     * No XML format is defined for math transform.
+     */
+    @Override
+    @Deprecated
+    public MathTransform createFromXML(String xml) throws FactoryException {
+        throw new UnsupportedOperationException();
+    }
+}

Propchange: sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/MTFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/MTFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-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=1802647&r1=1802646&r2=1802647&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] Fri Jul 21 22:34:29 2017
@@ -23,8 +23,8 @@ import org.apache.sis.test.TestCase;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import static org.junit.Assert.*;
 import static org.junit.Assume.*;
+import static org.apache.sis.test.Assert.*;
 
 
 /**
@@ -177,4 +177,16 @@ public final strictfp class PJTest exten
     private static void assertNaN(final double value) {
         assertEquals(Double.doubleToRawLongBits(Double.NaN), Double.doubleToRawLongBits(value));
     }
+
+    /**
+     * Tests serialization. Since we can not serialize native resources, {@link PJ} is expected
+     * to serialize the Proj.4 definition string instead.
+     *
+     * @throws FactoryException if the Proj.4 definition string used in this test is invalid.
+     */
+    @Test
+    public void testSerialization() throws FactoryException {
+        final PJ pj = new PJ("+proj=latlong +datum=WGS84");
+        assertNotSame(pj, assertSerializedEquals(pj));
+    }
 }

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=1802647&r1=1802646&r2=1802647&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] Fri Jul 21 22:34:29 2017
@@ -26,6 +26,7 @@ import org.opengis.referencing.operation
 import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.TransformException;
+import org.opengis.parameter.ParameterValueGroup;
 import org.apache.sis.geometry.DirectPosition2D;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
@@ -114,11 +115,31 @@ public final strictfp class Proj4Factory
         final ProjectedCRS  targetCRS = factory.createProjectedCRS("+init=epsg:3395");
         final CoordinateOperation op  = factory.createOperation(sourceCRS, targetCRS);
         assertInstanceOf("createOperation", Conversion.class, op);
+        testMercatorProjection(op.getMathTransform());
+    }
 
-        final MathTransform mt = op.getMathTransform();
+    /**
+     * Tests EPSG:3395 on a point.
+     */
+    private static void testMercatorProjection(final MathTransform mt) throws TransformException
{
         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);
     }
+
+    /**
+     * Tests {@link Proj4Factory#createParameterizedTransform(ParameterValueGroup)}.
+     *
+     * @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 testParameterizedTransform() throws FactoryException, TransformException
{
+        final Proj4Factory factory   = Proj4Factory.INSTANCE;
+        final ParameterValueGroup pg = factory.getDefaultParameters("merc");
+        pg.parameter("a").setValue(6378137.0);
+        pg.parameter("b").setValue(6356752.314245179);
+        testMercatorProjection(factory.createParameterizedTransform(pg));
+    }
 }

Added: 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=1802647&view=auto
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/TransformTest.java
(added)
+++ sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/TransformTest.java
[UTF-8] Fri Jul 21 22:34:29 2017
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.storage.gdal;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Arrays;
+import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.util.NoSuchIdentifierException;
+import org.opengis.test.referencing.ParameterizedTransformTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+import org.junit.AfterClass;
+
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests various map projections using {@literal Proj.4} wrappers.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 0.8
+ * @since   0.8
+ * @module
+ */
+@RunWith(JUnit4.class)
+public class TransformTest extends ParameterizedTransformTest {
+    /**
+     * The operation methods that we failed to instantiate.
+     * We use this set for verifying that there is no more failures than the expected ones.
+     */
+    private static final Set<String> FAILURES = new HashSet<>();
+
+    /**
+     * Creates a new test suite.
+     */
+    public TransformTest() {
+        super(new MTFactory(null) {
+            @Override
+            public ParameterValueGroup getDefaultParameters(final String method) throws NoSuchIdentifierException
{
+                try {
+                    return super.getDefaultParameters(method);
+                } catch (NoSuchIdentifierException e) {
+                    FAILURES.add(method);
+                    throw e;
+                }
+            }
+        });
+        isDerivativeSupported = false;
+    }
+
+    /**
+     * Invoked after all the tests have been run for comparing the list of failures with
the expected list.
+     * This method checks for the exact same content, so this method detects both unexpected
failures and
+     * "unexpected" successes. Note that a failure is not necessarily because Proj.4 does
not support the
+     * map projection; it may also be because Apache SIS does not yet declare the corresponding
operation
+     * method.
+     */
+    @AfterClass
+    public static void verifyFailureList() {
+        assertSetEquals(Arrays.asList(
+                "Abridged Molodensky",
+                "Cassini-Soldner",                          // No OperationMethod in SIS
yet.
+                "Hotine Oblique Mercator (variant B)",
+                "Krovak",                                   // No OperationMethod in SIS
yet.
+                "Lambert Azimuthal Equal Area",             // No OperationMethod in SIS
yet.
+                "Lambert Conic Conformal (1SP)",
+                "Lambert Conic Conformal (2SP Belgium)",
+                "Lambert Conic Conformal (2SP Michigan)",
+                "Mercator (Spherical)",
+                "Mercator (variant C)",
+                "Polar Stereographic (variant B)",
+                "Polar Stereographic (variant C)",
+                "Popular Visualisation Pseudo Mercator",
+                "Polyconic",                                // No OperationMethod in SIS
yet.
+                "Transverse Mercator (South Orientated)"), FAILURES);
+        FAILURES.clear();
+    }
+}

Propchange: sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/TransformTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/TransformTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/test/suite/GDALTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/test/suite/GDALTestSuite.java?rev=1802647&r1=1802646&r2=1802647&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/test/suite/GDALTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/test/suite/GDALTestSuite.java
[UTF-8] Fri Jul 21 22:34:29 2017
@@ -33,7 +33,8 @@ import org.junit.runners.Suite;
     org.apache.sis.storage.gdal.PJTest.class,
     org.apache.sis.storage.gdal.Proj4Test.class,
     org.apache.sis.storage.gdal.Proj4ParserTest.class,
-    org.apache.sis.storage.gdal.Proj4FactoryTest.class
+    org.apache.sis.storage.gdal.Proj4FactoryTest.class,
+    org.apache.sis.storage.gdal.TransformTest.class
 })
 public final strictfp class GDALTestSuite extends TestSuite {
     /**



Mime
View raw message