sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1802062 - in /sis/branches/JDK8/storage/sis-gdal/src: main/java/org/apache/sis/storage/gdal/ test/java/org/apache/sis/storage/gdal/ test/java/org/apache/sis/test/suite/
Date Sun, 16 Jul 2017 14:37:37 GMT
Author: desruisseaux
Date: Sun Jul 16 14:37:37 2017
New Revision: 1802062

URL: http://svn.apache.org/viewvc?rev=1802062&view=rev
Log:
Defines OperationMethod and parameters for ProjectedCRS.

Added:
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Parser.java
  (with props)
    sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4ParserTest.java
  (with props)
Removed:
    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/Parameter.java
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/ParameterGroup.java
Modified:
    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/Proj4Factory.java
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/ResourcesLoader.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
    sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/test/suite/GDALTestSuite.java

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=1802062&r1=1802061&r2=1802062&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]
Sun Jul 16 14:37:37 2017
@@ -28,10 +28,11 @@ import org.opengis.referencing.datum.Pri
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.referencing.factory.InvalidGeodeticParameterException;
-import org.apache.sis.util.iso.SimpleInternationalString;
-import org.apache.sis.metadata.iso.citation.Citations;
 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;
 
@@ -212,7 +213,13 @@ final class PJ implements Identifier {
     public InternationalString getDescription() {
         String name = getName();
         if (name != null) {
-            name = name.trim();
+            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);
             }

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=1802062&r1=1802061&r2=1802062&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 14:37:37 2017
@@ -25,13 +25,17 @@ import javax.measure.Unit;
 import org.opengis.util.FactoryException;
 import org.opengis.metadata.Identifier;
 import org.opengis.metadata.citation.Citation;
+import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.referencing.cs.*;
 import org.opengis.referencing.crs.*;
 import org.opengis.referencing.datum.*;
 import org.opengis.referencing.IdentifiedObject;
+import org.opengis.referencing.operation.OperationMethod;
 import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.CoordinateOperation;
-import org.apache.sis.referencing.operation.AbstractCoordinateOperation;
+import org.opengis.referencing.operation.CoordinateOperationFactory;
+import org.apache.sis.referencing.operation.DefaultConversion;
+import org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory;
 import org.apache.sis.referencing.factory.GeodeticAuthorityFactory;
 import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.internal.util.Constants;
@@ -39,9 +43,11 @@ import org.apache.sis.metadata.iso.citat
 import org.apache.sis.metadata.iso.ImmutableIdentifier;
 import org.apache.sis.internal.metadata.AxisDirections;
 import org.apache.sis.internal.system.DefaultFactories;
+import org.apache.sis.internal.system.Modules;
 import org.apache.sis.util.collection.WeakValueHashMap;
 import org.apache.sis.util.resources.Vocabulary;
 import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.measure.Units;
@@ -100,6 +106,12 @@ public class Proj4Factory extends Geodet
     private final DatumFactory datumFactory;
 
     /**
+     * The factory for coordinate operation objects.
+     * Currently restricted to Apache SIS implementation because we use a method not yet
available in GeoAPI.
+     */
+    private final DefaultCoordinateOperationFactory opFactory;
+
+    /**
      * Poll of identifiers created by this factory.
      */
     private final Map<String,Identifier> identifiers = new HashMap<>();
@@ -118,6 +130,7 @@ public class Proj4Factory extends Geodet
         crsFactory   = DefaultFactories.forBuildin(CRSFactory.class);
         csFactory    = DefaultFactories.forBuildin(CSFactory.class);
         datumFactory = DefaultFactories.forBuildin(DatumFactory.class);
+        opFactory    = DefaultFactories.forBuildin(CoordinateOperationFactory.class, DefaultCoordinateOperationFactory.class);
     }
 
     /**
@@ -126,17 +139,23 @@ public class Proj4Factory extends Geodet
      * @param crsFactory    the factory to use for creating Coordinate Reference Systems.
      * @param csFactory     the factory to use for creating Coordinate Systems.
      * @param datumFactory  the factory to use for creating Geodetic Datums.
+     * @param opFactory     the factory to use for creating Coordinate Operations.
+     *                      Current implementation requires an instance of {@link DefaultCoordinateOperationFactory},
+     *                      but this may be related in a future Apache SIS version.
      */
     public Proj4Factory(final CRSFactory   crsFactory,
                         final CSFactory    csFactory,
-                        final DatumFactory datumFactory)
+                        final DatumFactory datumFactory,
+                        final CoordinateOperationFactory opFactory)
     {
         ArgumentChecks.ensureNonNull("crsFactory",   crsFactory);
         ArgumentChecks.ensureNonNull("csFactory",    csFactory);
         ArgumentChecks.ensureNonNull("datumFactory", datumFactory);
+        ArgumentChecks.ensureNonNull("opFactory",    opFactory);
         this.crsFactory   = crsFactory;
         this.csFactory    = csFactory;
         this.datumFactory = datumFactory;
+        this.opFactory    = (DefaultCoordinateOperationFactory) opFactory;
     }
 
     /**
@@ -183,7 +202,7 @@ public class Proj4Factory extends Geodet
         final String method;
         if (type.isAssignableFrom(ProjectedCRS.class)) {                // Must be tested
first.
             method = "";
-        } else if (type.isAssignableFrom(GeodeticCRS.class)) {          // Should be tested
before GeocentricCRS.
+        } else if (type.isAssignableFrom(GeographicCRS.class)) {        // Should be tested
before GeocentricCRS.
             method = "latlon";
         } else if (type.isAssignableFrom(GeocentricCRS.class)) {
             method = "geocent";
@@ -377,9 +396,29 @@ public class Proj4Factory extends Geodet
                         csFactory.createCartesianCS(csName, axes[0], axes[1], axes[2]));
             }
             case PROJECTED: {
-                final CoordinateReferenceSystem base = createCRS(unique(new PJ(pj)), withHeight);
-                final Conversion fromBase = null;   // TODO
-                return crsFactory.createProjectedCRS(name, (GeographicCRS) base, fromBase,
withHeight ?
+                final PJ base = unique(new PJ(pj));
+                final CoordinateReferenceSystem baseCRS = createCRS(base, withHeight);
+                final Transform tr = new Transform(pj, withHeight, base, withHeight);
+                /*
+                 * Try to convert the Proj.4 parameters into OGC parameters in order to have
a less opaque structure.
+                 * Failure to perform this conversion will not cause a failure to create
the ProjectedCRS. After all,
+                 * maybe the user invokes this method for using a map projection not yet
supported by Apache SIS.
+                 * Instead, fallback on the more opaque Transform.METHOD description. Apache
SIS will not be able to
+                 * perform analysis on those parameters, but it will not prevent the Proj.4
transformation to work.
+                 */
+                OperationMethod method;
+                ParameterValueGroup parameters;
+                try {
+                    final Proj4Parser parser = new Proj4Parser(pj.getCode());
+                    method = parser.method(opFactory);
+                    parameters = parser.parameters();
+                } catch (IllegalArgumentException | FactoryException e) {
+                    Logging.recoverableException(Logging.getLogger(Modules.GDAL), Proj4Factory.class,
"createProjectedCRS", e);
+                    method = Transform.METHOD;
+                    parameters = null;              // Will let Apache SIS infers the parameters
from the Transform instance.
+                }
+                final Conversion fromBase = new DefaultConversion(name, method, tr, parameters);
+                return crsFactory.createProjectedCRS(name, (GeographicCRS) baseCRS, fromBase,
withHeight ?
                         csFactory.createCartesianCS(csName, axes[0], axes[1], axes[2]) :
                         csFactory.createCartesianCS(csName, axes[0], axes[1]));
             }
@@ -461,10 +500,7 @@ public class Proj4Factory extends Geodet
         }
         final Transform tr = new Transform(unwrapOrCreate(sourceCRS), is3D("sourceCRS", sourceCRS),
                                            unwrapOrCreate(targetCRS), is3D("targetCRS", targetCRS));
-        /*
-         * TODO: should create a more specific coordinate operation.
-         */
-        return new AbstractCoordinateOperation(identifier(name), sourceCRS, targetCRS, null,
tr);
+        return opFactory.createSingleOperation(identifier(name), sourceCRS, targetCRS, null,
Transform.METHOD, tr);
     }
 
     /**

Added: 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=1802062&view=auto
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Parser.java
(added)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Parser.java
[UTF-8] Sun Jul 16 14:37:37 2017
@@ -0,0 +1,121 @@
+/*
+ * 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.Map;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Locale;
+import org.opengis.util.FactoryException;
+import org.opengis.parameter.ParameterValue;
+import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.referencing.operation.OperationMethod;
+import org.apache.sis.util.CharSequences;
+import org.apache.sis.util.resources.Errors;
+import org.apache.sis.referencing.factory.InvalidGeodeticParameterException;
+import org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory;
+
+
+/**
+ * Creates a parameter value group from a {@literal Proj.4} definition string.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 0.8
+ * @since   0.8
+ * @module
+ */
+final class Proj4Parser {
+    /**
+     * {@literal Proj.4} parameters to ignore when building the parameter value group of
a map projection.
+     * 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);
+    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("towgs84");        // Datum shift
+        EXCLUDES.add("axis");           // Axis order
+    }
+
+    /**
+     * The values extracted from the {@literal Proj.4} definition strings.
+     * Keys are Proj.4 keywords like {@code "a"} or {@code "ts"}.
+     */
+    private final Map<String,String> parameters = new LinkedHashMap<>();
+
+    /**
+     * The map projection method inferred from the {@code "+proj="}, or {@code null} if not
yet fetched.
+     */
+    private OperationMethod method;
+
+    /**
+     * Creates a parser for the given {@literal Proj.4} definition string.
+     */
+    Proj4Parser(final String definition) throws InvalidGeodeticParameterException {
+        final int length = definition.length();
+        int start = definition.indexOf('+');
+        while (start >= 0) {
+            final int end  = definition.indexOf('=', ++start);
+            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));
+                    }
+                }
+            }
+            start = next;
+        }
+    }
+
+    /**
+     * Returns the operation method inferred from the {@code "proj"} parameter value.
+     * This method must be invoked at least once before {@link #parameters()}.
+     */
+    final OperationMethod method(final DefaultCoordinateOperationFactory opFactory) throws
FactoryException {
+        if (method == null) {
+            final String name = parameters.remove("proj");
+            if (name == null) {
+                throw new InvalidGeodeticParameterException(Errors.format(Errors.Keys.ElementNotFound_1,
"proj"));
+            }
+            method = opFactory.getOperationMethod(name);
+        }
+        return method;
+    }
+
+    /**
+     * Returns the parameter value group filled from the {@literal Proj.4} parameters.
+     *
+     * @throws IllegalArgumentException if a Proj.4 parameter can not be converted to the
expected type.
+     */
+    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()));
+        }
+        return pg;
+    }
+}

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

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

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/ResourcesLoader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/ResourcesLoader.java?rev=1802062&r1=1802061&r2=1802062&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/ResourcesLoader.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/ResourcesLoader.java
[UTF-8] Sun Jul 16 14:37:37 2017
@@ -17,13 +17,7 @@
 package org.apache.sis.storage.gdal;
 
 import java.util.Map;
-import java.util.Set;
-import java.util.List;
 import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.ArrayList;
-import java.util.Collections;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -34,11 +28,7 @@ import org.opengis.util.FactoryException
 import org.opengis.util.NoSuchIdentifierException;
 import org.opengis.parameter.GeneralParameterValue;
 import org.opengis.referencing.IdentifiedObject;
-import org.opengis.referencing.operation.OperationMethod;
 
-import org.apache.sis.metadata.iso.citation.Citations;
-import org.apache.sis.referencing.NamedIdentifier;
-import org.apache.sis.referencing.operation.DefaultOperationMethod;
 
 
 /**
@@ -53,12 +43,12 @@ final class ResourcesLoader {
     /**
      * The file which contains parameter aliases.
      */
-    static final String PARAMETERS_FILE = "parameter-names.txt";
+    private static final String PARAMETERS_FILE = "parameter-names.txt";
 
     /**
      * The file which contains projection aliases.
      */
-    static final String PROJECTIONS_FILE = "projection-names.txt";
+    private static final String PROJECTIONS_FILE = "projection-names.txt";
 
     /**
      * The Proj.4 names for OGC, EPSG or GeoTIFF projection names.
@@ -73,16 +63,6 @@ final class ResourcesLoader {
     private static final Map<String,String> parameterNames = new HashMap<>();
 
     /**
-     * Pool of identifiers, filled when first needed.
-     */
-    private static final Map<String, List<GenericName>> aliases = new HashMap<>();
-
-    /**
-     * The set of all operation methods, filled when first needed.
-     */
-    private static final Set<OperationMethod> methods = new LinkedHashSet<>();
-
-    /**
      * Do not allows instantiation of this class.
      */
     private ResourcesLoader() {
@@ -162,62 +142,4 @@ final class ResourcesLoader {
         }
         return proj;
     }
-
-    /**
-     * Returns the list of aliases for the given name, or an empty list if none.
-     */
-    static List<GenericName> getAliases(String name, final boolean isParam) throws
FactoryException {
-        // Replace the name by the Proj.4 name, if we find it.
-        final Map<String, String> map = getAliases(isParam);
-        final String projName = map.get(name);
-        if (projName != null) {
-            name = projName;
-        }
-        return getAliases(name, map);
-    }
-
-    /**
-     * Returns the list of aliases for the given Proj.4 name, or an empty list if none.
-     */
-    private static List<GenericName> getAliases(final String name, final Map<String,String>
map) {
-        List<GenericName> list;
-        synchronized (aliases) {
-            list = aliases.get(name);
-            if (list == null) {
-                list = new ArrayList<>();
-                for (final Map.Entry<String,String> entry : map.entrySet()) {
-                    if (name.equalsIgnoreCase(entry.getValue())) {
-                        list.add(new NamedIdentifier(null, entry.getKey()));
-                    }
-                }
-                if (list.isEmpty()) {
-                    list = Collections.emptyList();
-                } else {
-                    ((ArrayList<?>) list).trimToSize();
-                    list = Collections.unmodifiableList(list);
-                }
-            }
-        }
-        return list;
-    }
-
-    /**
-     * Returns the set of all operation methods.
-     */
-    static Set<OperationMethod> getMethods() throws FactoryException {
-        synchronized (methods) {
-            if (methods.isEmpty()) {
-                final Map<String,String> map = getAliases(false);
-                final Map<String,Object> properties = new HashMap<>(4);
-                for (final String name : new HashSet<>(map.values())) {
-                    final NamedIdentifier id = new NamedIdentifier(Citations.PROJ4, name);
-                    final List<GenericName> aliases = getAliases(name, map);
-                    properties.put(DefaultOperationMethod.NAME_KEY, id);
-                    properties.put(DefaultOperationMethod.ALIAS_KEY, aliases);
-                    methods.add(new DefaultOperationMethod(properties, 2, 2, new ParameterGroup(id,
aliases)));
-                }
-            }
-        }
-        return Collections.unmodifiableSet(methods);
-    }
 }

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=1802062&r1=1802061&r2=1802062&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 14:37:37 2017
@@ -16,9 +16,18 @@
  */
 package org.apache.sis.storage.gdal;
 
+import java.util.Collections;
+import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.parameter.ParameterDescriptor;
+import org.opengis.parameter.ParameterDescriptorGroup;
+import org.opengis.referencing.operation.OperationMethod;
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.TransformException;
+import org.apache.sis.internal.util.Constants;
+import org.apache.sis.metadata.iso.citation.Citations;
+import org.apache.sis.parameter.ParameterBuilder;
+import org.apache.sis.referencing.operation.DefaultOperationMethod;
 import org.apache.sis.referencing.operation.transform.AbstractMathTransform;
 
 
@@ -32,6 +41,22 @@ import org.apache.sis.referencing.operat
  */
 final class Transform extends AbstractMathTransform {
     /**
+     * The operation method for a transformation between two {@link PJ} instances.
+     * The parameter names are taken from
+     * <a href="http://proj4.org/development/api.html#pj-transform">Proj.4 API</a>.
+     */
+    static final OperationMethod METHOD;
+    static {
+        final ParameterBuilder builder = new ParameterBuilder().setCodeSpace(Citations.PROJ4,
Constants.PROJ4);
+        final ParameterDescriptor<?>[] p = {
+            builder.addName("srcdefn").setDescription("Source (input) coordinate system.").create(String.class,
null),
+            builder.addName("dstdefn").setDescription("Destination (output) coordinate system.").create(String.class,
null)
+        };
+        final ParameterDescriptorGroup params = builder.addName("pj_transform").createGroup(1,
1, p);
+        METHOD = new DefaultOperationMethod(Collections.singletonMap(OperationMethod.NAME_KEY,
params.getName()), null, null, params);
+    }
+
+    /**
      * The source and target CRS.
      */
     private final PJ source, target;
@@ -57,6 +82,25 @@ final class Transform extends AbstractMa
     }
 
     /**
+     * Returns the parameter descriptors for this math transform.
+     */
+    @Override
+    public ParameterDescriptorGroup getParameterDescriptors() {
+        return METHOD.getParameters();
+    }
+
+    /**
+     * Returns a copy of the parameter values for this parameterized object.
+     */
+    @Override
+    public ParameterValueGroup getParameterValues() {
+        final ParameterValueGroup pg = getParameterDescriptors().createValue();
+        pg.parameter("srcdefn").setValue(source.getCode());
+        pg.parameter("dstdefn").setValue(target.getCode());
+        return pg;
+    }
+
+    /**
      * Returns the number of source dimensions.
      */
     @Override

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=1802062&r1=1802061&r2=1802062&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 14:37:37 2017
@@ -16,8 +16,11 @@
  */
 package org.apache.sis.storage.gdal;
 
+import java.util.Arrays;
 import org.opengis.util.FactoryException;
+import org.opengis.referencing.crs.ProjectedCRS;
 import org.opengis.referencing.crs.GeographicCRS;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.apache.sis.test.TestUtilities;
@@ -35,7 +38,7 @@ import static org.junit.Assert.*;
  * @since   0.8
  * @module
  */
-@DependsOn(PJTest.class)
+@DependsOn({PJTest.class, Proj4ParserTest.class})
 public final strictfp class Proj4FactoryTest extends TestCase {
     /**
      * Verifies if the {@literal Proj.4} library is available.
@@ -46,12 +49,25 @@ public final strictfp class Proj4Factory
     }
 
     /**
+     * Tests {@link Proj4Factory#getAuthorityCodes(Class)}.
+     *
+     * @throws FactoryException if an error occurred while querying the factory.
+     */
+    @Test
+    public void testGetAuthorityCodes() throws FactoryException {
+        final Proj4Factory factory = Proj4Factory.INSTANCE;
+        assertTrue(factory.getAuthorityCodes(GeographicCRS.class).containsAll(Arrays.asList("+init=",
"+proj=latlon")));
+        assertTrue(factory.getAuthorityCodes(CoordinateReferenceSystem.class).containsAll(Arrays.asList("+init=",
"+proj=")));
+    }
+
+    /**
      * Tests the creation of the {@code "+init=epsg:4326"} geographic CRS.
+     * Note that the axis order is not the same than standard EPSG:4326.
      *
      * @throws FactoryException if an error occurred while creating the CRS objects.
      */
     @Test
-    public void testEPSG_4326() throws FactoryException {
+    public void test4326() throws FactoryException {
         final Proj4Factory factory = Proj4Factory.INSTANCE;
         final GeographicCRS crs = factory.createGeographicCRS("+init=epsg:4326");
         /*
@@ -61,4 +77,21 @@ public final strictfp class Proj4Factory
         assertEquals(PJ.Type.GEOGRAPHIC, pj.getType());
         assertArrayEquals(new char[] {'e', 'n', 'u'}, pj.getAxisDirections());
     }
+
+    /**
+     * Tests the creation of the {@code "+init=epsg:3395"} projected CRS.
+     *
+     * @throws FactoryException if an error occurred while creating the CRS objects.
+     */
+    @Test
+    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());
+    }
 }

Added: 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=1802062&view=auto
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4ParserTest.java
(added)
+++ sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4ParserTest.java
[UTF-8] Sun Jul 16 14:37:37 2017
@@ -0,0 +1,66 @@
+/*
+ * 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 org.opengis.util.FactoryException;
+import org.opengis.referencing.operation.CoordinateOperationFactory;
+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.test.TestCase;
+import org.junit.Test;
+import org.opengis.parameter.ParameterValueGroup;
+
+import static org.opengis.test.Assert.*;
+
+
+/**
+ * Tests {@link Proj4Parser}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 0.8
+ * @since   0.8
+ * @module
+ */
+public final strictfp class Proj4ParserTest extends TestCase {
+    /**
+     * The factory needed for calls to {@code Proj4Parser.method(…)}.
+     */
+    private final DefaultCoordinateOperationFactory opFactory;
+
+    /**
+     * Creates a new test.
+     */
+    public Proj4ParserTest() {
+        opFactory = DefaultFactories.forBuildin(CoordinateOperationFactory.class, DefaultCoordinateOperationFactory.class);
+    }
+
+    /**
+     * Tests parsing of a Mercator projection definition string.
+     *
+     * @throws FactoryException if the parsing failed.
+     */
+    @Test
+    public void testMercator() throws FactoryException {
+        final Proj4Parser parser = new Proj4Parser("+init=epsg:3395 +proj=merc +lon_0=0 +k=1
+x_0=0 +y_0=0"
+                      + " +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0");
+
+        assertInstanceOf("method", Mercator1SP.class, parser.method(opFactory));
+        final ParameterValueGroup pg = parser.parameters();
+        assertEquals("scale_factor", pg.parameter("scale_factor").getValue(), 1.0);
+    }
+}

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

Propchange: sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4ParserTest.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=1802062&r1=1802061&r2=1802062&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] Sun Jul 16 14:37:37 2017
@@ -32,6 +32,7 @@ import org.junit.runners.Suite;
 @Suite.SuiteClasses({
     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
 })
 public final strictfp class GDALTestSuite extends TestSuite {



Mime
View raw message