sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1802036 - in /sis/branches/JDK8: core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ core/sis-utility/src/main/java/org/apache/sis/internal/system/ storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/ storage/sis-...
Date Sat, 15 Jul 2017 22:48:17 GMT
Author: desruisseaux
Date: Sat Jul 15 22:48:17 2017
New Revision: 1802036

URL: http://svn.apache.org/viewvc?rev=1802036&view=rev
Log:
Remove the pseudo-EPSG factory backed by Proj.4. We do not need this factory since Apache
SIS can connect to a real EPSG database.
Instead, make clear that this is a Proj.4 factory with their own definitions.

Added:
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Factory.java
      - copied, changed from r1802035, sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/ReferencingFactory.java
    sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4FactoryTest.java
      - copied, changed from r1802035, sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/EPSGFactoryTest.java
Removed:
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/EPSGFactory.java
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/ReferencingFactory.java
    sis/branches/JDK8/storage/sis-gdal/src/main/resources/org/apache/sis/storage/gdal/axis-orientations.txt
    sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/EPSGFactoryTest.java
Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/OS.java
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJ.java
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4.java
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/ResourcesLoader.java
    sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/test/suite/GDALTestSuite.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java?rev=1802036&r1=1802035&r2=1802036&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticAuthorityFactory.java
[UTF-8] Sat Jul 15 22:48:17 2017
@@ -63,7 +63,7 @@ import org.apache.sis.util.Debug;
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Johann Sorel (Geomatys)
- * @version 0.7
+ * @version 0.8
  * @since   0.7
  * @module
  */
@@ -1237,8 +1237,10 @@ public abstract class GeodeticAuthorityF
      * @param  code  the code to trim.
      * @return the code with the namespace part removed if that part matched one of the values
given by
      *         {@link #getCodeSpaces()}.
+     *
+     * @since 0.8
      */
-    final String trimNamespace(final String code) {
+    protected final String trimNamespace(final String code) {
         int s = code.indexOf(DefaultNameSpace.DEFAULT_SEPARATOR);
         if (s >= 0) {
             final int end   = CharSequences.skipTrailingWhitespaces(code, 0, s);

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/OS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/OS.java?rev=1802036&r1=1802035&r2=1802036&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/OS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/OS.java
[UTF-8] Sat Jul 15 22:48:17 2017
@@ -78,12 +78,29 @@ public enum OS {
     }
 
     /**
+     * Returns the name value of {@code "os.name"} property, or {@code null} if the security
manager
+     * does not allow us to access this information.
+     *
+     * <div class="note"><b>Note:</b> {@code uname} is an Unix command
providing the same information.</div>
+     *
+     * @return the operation system name, or {@code null} if this information is not available.
+     */
+    public static String uname() {
+        try {
+            return System.getProperty("os.name");
+        } catch (SecurityException e) {
+            Logging.recoverableException(Logging.getLogger(Loggers.SYSTEM), OS.class, "uname",
e);
+            return null;
+        }
+    }
+
+    /**
      * Returns the operating system SIS is currently on.
      *
      * @return the operation system.
      */
     public static OS current() {
-        final String name = System.getProperty("os.name");
+        final String name = uname();
         if (name != null) {
             if (name.contains("Windows")) return WINDOWS;
             if (name.contains("Mac OS"))  return MAC_OS;
@@ -144,6 +161,6 @@ public enum OS {
                 return tmp.toString();
             }
         }
-        throw new UnsatisfiedLinkError(Errors.format(Errors.Keys.NativeInterfacesNotFound_2,
System.getProperty("os.name"), name));
+        throw new UnsatisfiedLinkError(Errors.format(Errors.Keys.NativeInterfacesNotFound_2,
uname(), name));
     }
 }

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=1802036&r1=1802035&r2=1802036&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]
Sat Jul 15 22:48:17 2017
@@ -25,11 +25,13 @@ import org.opengis.metadata.citation.Cit
 import org.opengis.referencing.datum.Ellipsoid;
 import org.opengis.referencing.datum.GeodeticDatum;
 import org.opengis.referencing.datum.PrimeMeridian;
+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.util.resources.Errors;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.internal.system.OS;
 
@@ -84,7 +86,8 @@ final class PJ implements Identifier {
         Objects.requireNonNull(definition);
         ptr = allocatePJ(definition);
         if (ptr == 0) {
-            throw new InvalidGeodeticParameterException(definition);
+            throw new InvalidGeodeticParameterException(Errors.format(Errors.Keys.UnparsableStringForClass_2,
+                    CoordinateReferenceSystem.class, definition));
         }
     }
 
@@ -194,6 +197,7 @@ final class PJ implements Identifier {
 
     /**
      * 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>
      */
@@ -206,8 +210,14 @@ final class PJ implements Identifier {
      */
     @Override
     public InternationalString getDescription() {
-        final String name = getName();
-        return (name != null) ? new SimpleInternationalString(getName()) : null;
+        String name = getName();
+        if (name != null) {
+            name = name.trim();
+            if (!name.isEmpty()) {
+               return new SimpleInternationalString(name);
+            }
+        }
+        return null;
     }
 
     /**
@@ -342,6 +352,8 @@ final class PJ implements Identifier {
      * Returns a description of the last error that occurred, or {@code null} if none.
      *
      * @return the last error that occurred, or {@code null}.
+     *
+     * @todo this method is not thread-safe. Proj.4 provides a better alternative using a
context parameter.
      */
     native String getLastError();
 

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=1802036&r1=1802035&r2=1802036&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] Sat Jul 15 22:48:17 2017
@@ -36,6 +36,7 @@ import org.opengis.referencing.operation
 import org.apache.sis.referencing.factory.UnavailableFactoryException;
 import org.apache.sis.internal.metadata.AxisDirections;
 import org.apache.sis.internal.system.Modules;
+import org.apache.sis.internal.system.OS;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.ArgumentChecks;
@@ -151,7 +152,7 @@ public final class Proj4 extends Static
          * Appends axis directions. This method always format a vertical direction (up or
down)
          * even if the coordinate system is two-dimensional, because Proj.4 seems to require
it.
          */
-        definition.append(' ').append(EPSGFactory.AXIS_ORDER_PARAM);
+        definition.append(' ').append(Proj4Factory.AXIS_ORDER_PARAM);
         final int dimension = Math.min(cs.getDimension(), 3);
         boolean hasVertical = false;
         for (int i=0; i<dimension; i++) {
@@ -184,10 +185,9 @@ public final class Proj4 extends Static
         ArgumentChecks.ensureNonEmpty(definition, definition);
         ArgumentChecks.ensureBetween("dimension", 2, 3, dimension);
         try {
-            return ReferencingFactory.INSTANCE.createCRS(definition, dimension >= 3);
+            return Proj4Factory.INSTANCE.createCRS(definition, dimension >= 3);
         } catch (UnsatisfiedLinkError | NoClassDefFoundError e) {
-            throw new UnavailableFactoryException(Errors.format(Errors.Keys.NativeInterfacesNotFound_2,
-                    System.getProperty("os.name"), "libproj"), e);
+            throw new UnavailableFactoryException(Errors.format(Errors.Keys.NativeInterfacesNotFound_2,
OS.uname(), "libproj"), e);
         }
     }
 
@@ -206,17 +206,9 @@ public final class Proj4 extends Static
         ArgumentChecks.ensureNonNull("sourceCRS", sourceCRS);
         ArgumentChecks.ensureNonNull("targetCRS", targetCRS);
         try {
-            return ReferencingFactory.INSTANCE.createOperation(sourceCRS, targetCRS);
+            return Proj4Factory.INSTANCE.createOperation(sourceCRS, targetCRS);
         } catch (UnsatisfiedLinkError | NoClassDefFoundError e) {
-            throw new UnavailableFactoryException(Errors.format(Errors.Keys.NativeInterfacesNotFound_2,
-                    System.getProperty("os.name"), "libproj"), e);
+            throw new UnavailableFactoryException(Errors.format(Errors.Keys.NativeInterfacesNotFound_2,
OS.uname(), "libproj"), e);
         }
     }
-
-    /**
-     * Returns the exception to throw when a feature is not yet supported.
-     */
-    static FactoryException unsupportedOperation() {
-        return new FactoryException("Not supported yet.");
-    }
 }

Copied: sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Factory.java
(from r1802035, sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/ReferencingFactory.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Factory.java?p2=sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Factory.java&p1=sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/ReferencingFactory.java&r1=1802035&r2=1802036&rev=1802036&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/ReferencingFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4Factory.java
[UTF-8] Sat Jul 15 22:48:17 2017
@@ -17,11 +17,14 @@
 package org.apache.sis.storage.gdal;
 
 import java.util.Map;
+import java.util.Set;
 import java.util.HashMap;
+import java.util.LinkedHashSet;
 import java.util.Collections;
 import javax.measure.Unit;
 import org.opengis.util.FactoryException;
 import org.opengis.metadata.Identifier;
+import org.opengis.metadata.citation.Citation;
 import org.opengis.referencing.cs.*;
 import org.opengis.referencing.crs.*;
 import org.opengis.referencing.datum.*;
@@ -29,32 +32,57 @@ import org.opengis.referencing.Identifie
 import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.CoordinateOperation;
 import org.apache.sis.referencing.operation.AbstractCoordinateOperation;
-import org.apache.sis.internal.system.DefaultFactories;
-import org.apache.sis.internal.metadata.AxisDirections;
+import org.apache.sis.referencing.factory.GeodeticAuthorityFactory;
+import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.metadata.iso.citation.Citations;
 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.util.collection.WeakValueHashMap;
 import org.apache.sis.util.resources.Vocabulary;
 import org.apache.sis.util.resources.Errors;
-import org.apache.sis.util.iso.AbstractFactory;
-import org.apache.sis.referencing.CommonCRS;
+import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.CharSequences;
 import org.apache.sis.measure.Units;
 
 
 /**
- * Creates Coordinate Reference System instances form {@link PJ} objects.
+ * A factory for Coordinate Reference Systems created from {@literal Proj.4} definitions.
+ * This authority factory recognizes codes in the {@code "Proj4"} name space.
+ * The main methods in this class are:
+ * <ul>
+ *   <li>{@link #getAuthority()}</li>
+ *   <li>{@link #createCoordinateReferenceSystem(String)}</li>
+ * </ul>
+ *
+ * The following methods delegate to {@link #createCoordinateReferenceSystem(String)} and
cast
+ * the result if possible, or throw a {@link FactoryException} otherwise.
+ * <ul>
+ *   <li>{@link #createGeographicCRS(String)}</li>
+ *   <li>{@link #createGeocentricCRS(String)}</li>
+ *   <li>{@link #createProjectedCRS(String)}</li>
+ *   <li>{@link #createObject(String)}</li>
+ * </ul>
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @version 0.8
  * @since   0.8
  * @module
  */
-final class ReferencingFactory extends AbstractFactory {
+public class Proj4Factory extends GeodeticAuthorityFactory implements CRSAuthorityFactory
{
+    /**
+     * The {@literal Proj.4} parameter used for declaration of axis order.  Proj.4 expects
the axis parameter
+     * to be exactly 3 characters long, but Apache SIS accepts 2 characters as well. We relax
the Proj.4 rule
+     * because we use the number of characters for determining the number of dimensions.
+     * This is okay since 1 character = 1 axis.
+     */
+    static final String AXIS_ORDER_PARAM = "+axis=";
+
     /**
      * The default factory instance.
      */
-    static final ReferencingFactory INSTANCE = new ReferencingFactory();
+    static final Proj4Factory INSTANCE = new Proj4Factory();
 
     /**
      * The factory for coordinate reference system objects.
@@ -74,24 +102,167 @@ final class ReferencingFactory extends A
     /**
      * Poll of identifiers created by this factory.
      */
-    private final Map<String,Identifier> identifiers;
+    private final Map<String,Identifier> identifiers = new HashMap<>();
 
     /**
      * Pool of {@literal Proj.4} objects created so far. The keys are the Proj.4 definition
strings.
      * The same {@link PJ} instance may appear more than once if various definition strings
resulted
      * in the same Proj.4 object.
      */
-    private final WeakValueHashMap<String,PJ> pool;
+    private final WeakValueHashMap<String,PJ> pool = new WeakValueHashMap<>(String.class);
 
     /**
-     * Creates a new factory.
+     * Creates a new {@literal Proj.4} factory using the default CRS, CS and datum factories.
      */
-    private ReferencingFactory() {
+    public Proj4Factory() {
         crsFactory   = DefaultFactories.forBuildin(CRSFactory.class);
         csFactory    = DefaultFactories.forBuildin(CSFactory.class);
         datumFactory = DefaultFactories.forBuildin(DatumFactory.class);
-        identifiers  = new HashMap<>();
-        pool         = new WeakValueHashMap<>(String.class);
+    }
+
+    /**
+     * Creates a new {@literal Proj.4} factory using the specified CRS, CS and datum factories.
+     *
+     * @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.
+     */
+    public Proj4Factory(final CRSFactory   crsFactory,
+                        final CSFactory    csFactory,
+                        final DatumFactory datumFactory)
+    {
+        ArgumentChecks.ensureNonNull("crsFactory",   crsFactory);
+        ArgumentChecks.ensureNonNull("csFactory",    csFactory);
+        ArgumentChecks.ensureNonNull("datumFactory", datumFactory);
+        this.crsFactory   = crsFactory;
+        this.csFactory    = csFactory;
+        this.datumFactory = datumFactory;
+    }
+
+    /**
+     * Returns the project that defines the codes recognized by this factory.
+     * The authority determines the {@linkplain #getCodeSpaces() code space}.
+     *
+     * @return {@link Citations#PROJ4}.
+     */
+    @Override
+    public Citation getAuthority() {
+        return Citations.PROJ4;
+    }
+
+    /**
+     * Returns the code space of the authority. The code space is the prefix that may appear
before codes.
+     * It allows to differentiate Proj.4 definitions from EPSG codes or other authorities.
The code space is
+     * removed by {@link #createCoordinateReferenceSystem(String)} before the definition
string is passed to Proj.4
+     *
+     * <div class="note"><b>Example</b>
+     * a complete identifier can be {@code "Proj4:+init=epsg:4326"}.
+     * Note that this is <strong>not</strong> equivalent to the standard {@code
"EPSG:4326"} definition since the
+     * axis order is not the same. The {@code "Proj4:"} prefix specifies that the remaining
part of the string is
+     * a Proj.4 definition; the presence of an {@code "epsg"} word in the definition does
not change that fact.
+     * </div>
+     *
+     * @return {@code "Proj4"}.
+     */
+    @Override
+    public Set<String> getCodeSpaces() {
+        return Collections.singleton(Constants.PROJ4);
+    }
+
+    /**
+     * Returns the set of authority codes for objects of the given type.
+     * Current implementation can not return complete Proj.4 definition strings.
+     * Instead, this method currently returns only fragments (e.g. {@code "+init="}).
+     *
+     * @param  type  the spatial reference objects type.
+     * @return fragments of definition strings for spatial reference objects of the given
type.
+     * @throws FactoryException if access to the underlying database failed.
+     */
+    @Override
+    public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type)
throws FactoryException {
+        final String method;
+        if (type.isAssignableFrom(ProjectedCRS.class)) {                // Must be tested
first.
+            method = "";
+        } else if (type.isAssignableFrom(GeodeticCRS.class)) {          // Should be tested
before GeocentricCRS.
+            method = "latlon";
+        } else if (type.isAssignableFrom(GeocentricCRS.class)) {
+            method = "geocent";
+        } else {
+            return Collections.emptySet();
+        }
+        final Set<String> codes = new LinkedHashSet<>(4);
+        codes.add("+init=");
+        codes.add("+proj=".concat(method));
+        return codes;
+    }
+
+    /**
+     * Creates a new geodetic object from the given {@literal Proj.4} definition.
+     * The default implementation delegates to {@link #createCoordinateReferenceSystem(String)}.
+     *
+     * @param  code  the Proj.4 definition of the geodetic object to create.
+     * @return a geodetic created from the given definition.
+     * @throws FactoryException if the geodetic object can not be created for the given definition.
+     */
+    @Override
+    public IdentifiedObject createObject(String code) throws FactoryException {
+        return createCoordinateReferenceSystem(code);
+    }
+
+    /**
+     * Creates a new CRS from the given {@literal Proj.4} definition.
+     * The {@code "Proj4:"} prefix (ignoring case), if present, is ignored.
+     *
+     * <div class="section">Apache SIS extension</div>
+     * Proj.4 unconditionally requires 3 letters for the {@code "+axis="} parameter — for
example {@code "neu"} for
+     * <cite>North</cite>, <cite>East</cite> and <cite>Up</cite>
respectively — regardless the number of dimensions
+     * in the CRS to create. Apache SIS makes the vertical direction optional:
+     *
+     * <ul>
+     *   <li>If the vertical direction is present (as in {@code "neu"}), a three-dimensional
CRS is created.</li>
+     *   <li>If the vertical direction is absent (as in {@code "ne"}), a two-dimensional
CRS is created.</li>
+     * </ul>
+     *
+     * <div class="note"><b>Examples:</b>
+     * <ul>
+     *   <li>{@code "+init=epsg:4326"} (<strong>not</strong> equivalent
to the standard EPSG::4326 definition)</li>
+     *   <li>{@code "+proj=latlong +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"} (default
to two-dimensional CRS)</li>
+     *   <li>{@code "+proj=latlon +a=6378137.0 +b=6356752.314245179 +pm=0.0 +axis=ne"}
(explicitely two-dimensional)</li>
+     *   <li>{@code "+proj=latlon +a=6378137.0 +b=6356752.314245179 +pm=0.0 +axis=neu"}
(three-dimensional)</li>
+     * </ul>
+     * </div>
+     *
+     * @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.
+     */
+    @Override
+    public CoordinateReferenceSystem createCoordinateReferenceSystem(String code) throws
FactoryException {
+        code = trimNamespace(code);
+        boolean hasHeight = false;
+        /*
+         * Count the number of axes declared in the "+axis" parameter.
+         * If there is only two axes, add a 'u' (up) direction even in the two-dimensional
case.
+         * We make this addition because Proj.4 seems to require the 3-letters code in all
case.
+         */
+        int offset = code.indexOf(AXIS_ORDER_PARAM);
+        if (offset >= 0) {
+            offset += AXIS_ORDER_PARAM.length();
+            final CharSequence orientation = CharSequences.token(code, offset);
+            for (int i=orientation.length(); --i >= 0;) {
+                final char c = orientation.charAt(i);
+                hasHeight = (c == 'u' || c == 'd');
+                if (hasHeight) break;
+            }
+            if (!hasHeight && orientation.length() < 3) {
+                offset = code.indexOf(orientation.toString(), offset);
+                if (offset >= 0) {                          // Should never be -1, but
we are paranoiac.
+                    offset += orientation.length();
+                    code = new StringBuilder(code).insert(offset, 'u').toString();
+                }
+            }
+        }
+        return createCRS(code, hasHeight);
     }
 
     /**
@@ -193,7 +364,7 @@ final class ReferencingFactory extends A
          * attempt to create a new one for a given CRS.
          */
         final Map<String,Identifier> csName = identifier("Unnamed");
-        final Map<String,Identifier> name = new HashMap<>(identifier(pj.getName()));
+        final Map<String,Identifier> name = new HashMap<>(identifier(String.valueOf(pj.getDescription())));
         name.put(CoordinateReferenceSystem.IDENTIFIERS_KEY, pj);
         switch (type) {
             case GEOGRAPHIC: {
@@ -247,11 +418,14 @@ final class ReferencingFactory extends A
 
     /**
      * Creates a coordinate reference system from the given {@literal Proj.4} definition
string.
+     * The {@code Proj4} suffix shall have been removed before to invoke this method.
      *
      * @param  definition  the Proj.4 definition.
      * @param  withHeight  whether to include a height axis.
+     *
+     * @see Proj4#createCRS(String, int)
      */
-    public CoordinateReferenceSystem createCRS(final String definition, final boolean withHeight)
throws FactoryException {
+    final CoordinateReferenceSystem createCRS(final String definition, final boolean withHeight)
throws FactoryException {
         PJ pj = pool.get(definition);
         if (pj == null) {
             pj = unique(new PJ(definition));
@@ -262,6 +436,9 @@ final class ReferencingFactory extends A
 
     /**
      * 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.

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=1802036&r1=1802035&r2=1802036&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] Sat Jul 15 22:48:17 2017
@@ -21,7 +21,6 @@ import java.util.Set;
 import java.util.List;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -52,11 +51,6 @@ import org.apache.sis.referencing.operat
  */
 final class ResourcesLoader {
     /**
-     * The file which contains the axis orientations for each CRS code.
-     */
-    static final String AXIS_FILE = "axis-orientations.txt";
-
-    /**
      * The file which contains parameter aliases.
      */
     static final String PARAMETERS_FILE = "parameter-names.txt";
@@ -67,12 +61,6 @@ final class ResourcesLoader {
     static final String PROJECTIONS_FILE = "projection-names.txt";
 
     /**
-     * The map of axis orientations for each CRS codes.
-     * This map will be loaded from the {@value #AXIS_FILE} file when first needed.
-     */
-    private static Map<String,String> axisOrientations;
-
-    /**
      * The Proj.4 names for OGC, EPSG or GeoTIFF projection names.
      * Will be filled when first needed.
      */
@@ -101,58 +89,6 @@ final class ResourcesLoader {
     }
 
     /**
-     * Returns the axis orientation map. Callers shall not modify the returned map.
-     * The file format is the one created by {@code SupportedCodes.write()} in the
-     * test directory.
-     *
-     * @throws FactoryException if the resource file can not be loaded.
-     */
-    @SuppressWarnings("ReturnOfCollectionOrArrayField")
-    static synchronized Map<String,String> getAxisOrientations() throws FactoryException
{
-        if (axisOrientations != null) {
-            return axisOrientations;
-        }
-        IOException cause = null;
-        final InputStream in = ResourcesLoader.class.getResourceAsStream(AXIS_FILE);
-        if (in != null) try {
-            final Map<String,String> map = new LinkedHashMap<>(5000);
-            try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8")))
{
-                String line;
-                while ((line = reader.readLine()) != null) {
-                    if ((line = line.trim()).isEmpty()) {
-                        continue;                                       // Skip empty lines.
-                    }
-                    switch (line.charAt(0)) {
-                        case '#': {
-                            break;                                      // A line of comment.
Ignore.
-                        }
-                        case '[': {
-                            // The authority. Actually we don't parse yet
-                            // this element. Maybe a future version will do.
-                            break;
-                        }
-                        default: {
-                            int s = line.indexOf(':');
-                            final String orientation = line.substring(0, s).trim();
-                            do {
-                                final int p = s+1;
-                                s = line.indexOf(' ', p);
-                                final String code = (s >= 0) ? line.substring(p,s) : line.substring(p);
-                                map.put(code.trim(), orientation);
-                            } while (s >= 0);
-                            break;
-                        }
-                    }
-                }
-            }
-            return axisOrientations = map;
-        } catch (IOException e) {
-            cause = e;
-        }
-        throw new FactoryException("Can not read the \"" + AXIS_FILE + "\" resource", cause);
-    }
-
-    /**
      * Returns the mapping from projection/parameter names to Proj.4 names.
      *
      * @throws FactoryException if the resource file can not be loaded.

Copied: sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4FactoryTest.java
(from r1802035, sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/EPSGFactoryTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4FactoryTest.java?p2=sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4FactoryTest.java&p1=sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/EPSGFactoryTest.java&r1=1802035&r2=1802036&rev=1802036&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/EPSGFactoryTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/Proj4FactoryTest.java
[UTF-8] Sat Jul 15 22:48:17 2017
@@ -28,7 +28,7 @@ import static org.junit.Assert.*;
 
 
 /**
- * Tests the {@link EPSGFactory} class.
+ * Tests the {@link Proj4Factory} class.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @version 0.8
@@ -36,7 +36,7 @@ import static org.junit.Assert.*;
  * @module
  */
 @DependsOn(PJTest.class)
-public final strictfp class EPSGFactoryTest extends TestCase {
+public final strictfp class Proj4FactoryTest extends TestCase {
     /**
      * Verifies if the {@literal Proj.4} library is available.
      */
@@ -46,21 +46,19 @@ public final strictfp class EPSGFactoryT
     }
 
     /**
-     * Tests the creation of the EPSG:4326 geographic CRS. The interesting part of this test
-     * is the check for axis order. The result will depend on whether the axis orientations
-     * map has been properly created or not.
+     * Tests the creation of the {@code "+init=epsg:4326"} geographic CRS.
      *
      * @throws FactoryException if an error occurred while creating the CRS objects.
      */
     @Test
     public void testEPSG_4326() throws FactoryException {
-        final EPSGFactory factory = new EPSGFactory(true);
-        final GeographicCRS crs = factory.createGeographicCRS("EPSG:4326");
+        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[] {'n', 'e', 'u'}, pj.getAxisDirections());
+        assertArrayEquals(new char[] {'e', 'n', 'u'}, pj.getAxisDirections());
     }
 }

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=1802036&r1=1802035&r2=1802036&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] Sat Jul 15 22:48:17 2017
@@ -32,7 +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.EPSGFactoryTest.class
+    org.apache.sis.storage.gdal.Proj4FactoryTest.class
 })
 public final strictfp class GDALTestSuite extends TestSuite {
     /**



Mime
View raw message