sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmarec...@apache.org
Subject svn commit: r1770411 - in /sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff: GeoKeys.java GeoKeysRange.java TiffCRSBuilder.java
Date Fri, 18 Nov 2016 16:53:56 GMT
Author: rmarechal
Date: Fri Nov 18 16:53:55 2016
New Revision: 1770411

URL: http://svn.apache.org/viewvc?rev=1770411&view=rev
Log:
Complete creation of CRS from Geotiff tags.

Removed:
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoKeysRange.java
Modified:
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoKeys.java
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/TiffCRSBuilder.java

Modified: sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoKeys.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoKeys.java?rev=1770411&r1=1770410&r2=1770411&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoKeys.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoKeys.java
[UTF-8] Fri Nov 18 16:53:55 2016
@@ -74,16 +74,17 @@ final class GeoKeys {
         static final String GTUserDefinedGeoKey_String = "32767";
 
         /**
-         * Return tag Name from {@link GeoTiffConstants} class.
+         * Returns key Name from {@link Configuration} class if exist.
+         * If key name doesn't exist return {@code null}.
          *
-         * @param tag
-         * @return tag Name from {@link GeoTiffConstants} class.
+         * @param key
+         * @return tag Name from {@link Configuration} class.
          */
-        static String getName(final int tag) {
+        static String getName(final int key) {
             try {
-                for (final Field field : CRS.class.getDeclaredFields()) {
+                for (final Field field : Configuration.class.getDeclaredFields()) {
                     if (field.getType() == Integer.TYPE) {
-                        if (field.getInt(null) == tag) {
+                        if (field.getInt(null) == key) {
                             return field.getName();
                         }
                     }
@@ -91,12 +92,19 @@ final class GeoKeys {
             } catch (ReflectiveOperationException ex) {
                 throw new AssertionError(ex); // Should never happen.
             }
-            return Integer.toHexString(tag);
+            return Integer.toHexString(key);
         }
 
+        /**
+         * Returns {@code true} if {@link Configuration} class contain given key
+         * else return {@code false}.
+         *
+         * @param key
+         * @return {@code true} if {@link configuration} contain key else {@code false}.
+         */
         static boolean contain(int key) {
             try {
-                for (final Field field : CRS.class.getDeclaredFields()) {
+                for (final Field field : Configuration.class.getDeclaredFields()) {
                     if (field.getType() == Integer.TYPE) {
                         if (field.getInt(null) == key) {
                             return true;
@@ -159,14 +167,15 @@ final class GeoKeys {
         static final int CT_SouthOrientedGaussConformal =    CT_TransvMercator_SouthOriented;
 
         /**
-         * Return tag Name from {@link GeoTiffConstants} class.
+         * Returns key Name from {@link Operation_Method} class if exist.
+         * If key name doesn't exist return {@code null}.
          *
-         * @param tag
-         * @return tag Name from {@link GeoTiffConstants} class.
+         * @param key
+         * @return tag Name from {@link Operation_Method} class.
          */
         static String getName(final int tag) {
             try {
-                for (final Field field : CRS.class.getDeclaredFields()) {
+                for (final Field field : Operation_Method.class.getDeclaredFields()) {
                     if (field.getType() == Integer.TYPE) {
                         if (field.getInt(null) == tag) {
                             return field.getName();
@@ -179,9 +188,16 @@ final class GeoKeys {
             return Integer.toHexString(tag);
         }
 
+        /**
+         * Returns {@code true} if {@link Configuration} class contain given key
+         * else return {@code false}.
+         *
+         * @param key
+         * @return {@code true} if {@link configuration} contain key else {@code false}.
+         */
         static boolean contain(int key) {
             try {
-                for (final Field field : CRS.class.getDeclaredFields()) {
+                for (final Field field : Operation_Method.class.getDeclaredFields()) {
                     if (field.getType() == Integer.TYPE) {
                         if (field.getInt(null) == key) {
                             return true;
@@ -240,14 +256,15 @@ final class GeoKeys {
         static final int Angular_DMS_Hemisphere = 9108;
 
         /**
-         * Return tag Name from {@link GeoTiffConstants} class.
+         * Returns key Name from {@link Units} class if exist.
+         * If key name doesn't exist return {@code null}.
          *
-         * @param tag
-         * @return tag Name from {@link GeoTiffConstants} class.
+         * @param key
+         * @return tag Name from {@link Units} class.
          */
         static String getName(final int tag) {
             try {
-                for (final Field field : CRS.class.getDeclaredFields()) {
+                for (final Field field : Units.class.getDeclaredFields()) {
                     if (field.getType() == Integer.TYPE) {
                         if (field.getInt(null) == tag) {
                             return field.getName();
@@ -260,9 +277,16 @@ final class GeoKeys {
             return Integer.toHexString(tag);
         }
 
+        /**
+         * Returns {@code true} if {@link Units} class contain given key
+         * else return {@code false}.
+         *
+         * @param key
+         * @return {@code true} if {@link Units} contain key else {@code false}.
+         */
         static boolean contain(int key) {
             try {
-                for (final Field field : CRS.class.getDeclaredFields()) {
+                for (final Field field : Units.class.getDeclaredFields()) {
                     if (field.getType() == Integer.TYPE) {
                         if (field.getInt(null) == key) {
                             return true;
@@ -333,10 +357,11 @@ final class GeoKeys {
         static final int VerticalUnitsGeoKey     = 4099;   /* Section 6.3.1.3 codes */
 
         /**
-         * Return tag Name from {@link GeoTiffConstants} class.
+         * Returns key Name from {@link CRS} class if exist.
+         * If key name doesn't exist return {@code null}.
          *
-         * @param tag
-         * @return tag Name from {@link GeoTiffConstants} class.
+         * @param key
+         * @return tag Name from {@link CRS} class.
          */
         static String getName(final int tag) {
             try {
@@ -353,6 +378,13 @@ final class GeoKeys {
             return Integer.toHexString(tag);
         }
 
+        /**
+         * Returns {@code true} if {@link CRS} class contain given key
+         * else return {@code false}.
+         *
+         * @param key
+         * @return {@code true} if {@link CRS} contain key else {@code false}.
+         */
         static boolean contain(int key) {
             try {
                 for (final Field field : CRS.class.getDeclaredFields()) {
@@ -373,4 +405,43 @@ final class GeoKeys {
 
     }
 
+
+    //--------------------------- To String ------------------------------------
+    /**
+     * Returns key Name from one of {@link Configuration}, {@link Operation_Method},
+     * {@link Units} or {@link CRS} class if exist. If key name doesn't
+     * exist return {@code null}.
+     *
+     * @param key
+     * @return tag Name from one of internal sub-class if exist.
+     */
+    static String getName(final int tag) {
+        if (Configuration.contain(tag))
+            return Configuration.getName(tag);
+
+        if (Operation_Method.contain(tag))
+            return Operation_Method.getName(tag);
+
+        if (Units.contain(tag))
+            return Units.getName(tag);
+
+        if (CRS.contain(tag))
+            return CRS.getName(tag);
+
+        return null;
+    }
+
+    /**
+     * Returns {@code true} if given key is within one of {@link Configuration}, {@link Operation_Method},
+     * {@link Units} or {@link CRS} internal sub class else return {@code false}.
+     *
+     * @param key
+     * @return {@code true} if one of internal sub class contain key else {@code false}.
+     */
+    static boolean contain(int key) {
+        return Configuration.contain(key)
+            || Operation_Method.contain(key)
+            || Units.contain(key)
+            || CRS.contain(key);
+    }
 }

Modified: sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/TiffCRSBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/TiffCRSBuilder.java?rev=1770411&r1=1770410&r2=1770411&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/TiffCRSBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/TiffCRSBuilder.java
[UTF-8] Fri Nov 18 16:53:55 2016
@@ -611,22 +611,23 @@ public class TiffCRSBuilder {
         int axisNumber = 0;
         if (axis0.getDirection().equals(AxisDirection.EAST)
          || axis0.getDirection().equals(AxisDirection.WEST)) {
-            axisNumber = 4;
-            if (axis0.getDirection().equals(AxisDirection.EAST))  axisNumber |= 2;
-            if (axis1.getDirection().equals(AxisDirection.NORTH)) axisNumber |= 1;
+            axisNumber = 0b0100;
+            if (axis0.getDirection().equals(AxisDirection.EAST))  axisNumber |= 0b0010;
+            if (axis1.getDirection().equals(AxisDirection.NORTH)) axisNumber |= 0b0001;
         } else if (axis0.getDirection().equals(AxisDirection.NORTH)
                 || axis0.getDirection().equals(AxisDirection.SOUTH)) {
-            if (axis0.getDirection().equals(AxisDirection.EAST))  axisNumber |= 2;
-            if (axis1.getDirection().equals(AxisDirection.NORTH)) axisNumber |= 1;
+            if (axis0.getDirection().equals(AxisDirection.EAST))  axisNumber |= 0b0010;
+            if (axis1.getDirection().equals(AxisDirection.NORTH)) axisNumber |= 0b0001;
         } else {
             return (CartesianCS) CoordinateSystems.replaceLinearUnit(baseCS, fallBackUnit);
         }
 
         //-- get the Unit epsg code if exist
-        String unitCode = geoKeys.getAsString(unitKey).trim();
+        String unitCode = geoKeys.getAsString(unitKey);
         if (unitCode == null
          || unitCode.equalsIgnoreCase(GeoKeys.Configuration.GTUserDefinedGeoKey_String))
             return (CartesianCS) CoordinateSystems.replaceLinearUnit(baseCS, fallBackUnit);
+        unitCode = unitCode.trim();
 
         if (unitCode.startsWith("epsg:") || unitCode.startsWith("EPSG:"))
             unitCode = unitCode.substring(5, unitCode.length());
@@ -637,35 +638,35 @@ public class TiffCRSBuilder {
             // Linear_Meter = 9001
             case 9001 : {
                 switch (axisNumber) {
-                    case 7 : { //-- 111 [E,N]
+                    case 0b0111 : { //-- [E,N]
                         epsgCSCode = "4400";
                         break;
                     }
-                    case 6 : { //-- 110 [E,S]
-                        //-- no found into epsg base
+                    case 0b0110 : { //-- [E,S]
+                        //-- no relative CS found into epsg base
                         break;
                     }
-                    case 5 : { //-- 101 [W,N]
+                    case 0b0101 : { //-- [W,N]
                         epsgCSCode = "4491";
                         break;
                     }
-                    case 4 : { //-- 100 [W,S]
+                    case 0b0100 : { //-- [W,S]
                         epsgCSCode = "6503";
                         break;
                     }
-                    case 3 : { //-- 011 [N,E]
+                    case 0b0011 : { //-- [N,E]
                         epsgCSCode = "4500";
                         break;
                     }
-                    case 2 : { //-- 010 [N,W]
+                    case 0b0010 : { //-- [N,W]
                         epsgCSCode = "4501";//-- or 6507
                         break;
                     }
-                    case 1 : { //-- 001 [S,E]
-                        //-- not found into epsg base
+                    case 0b0001 : { //-- [S,E]
+                        //-- no relative CS found into epsg base
                         break;
                     }
-                    case 0 : { //-- 000 [S,W]
+                    case 0b0000 : { //-- [S,W]
                         epsgCSCode = "6501";
                         break;
                     }
@@ -675,11 +676,11 @@ public class TiffCRSBuilder {
             // Linear_Foot = 9002
             case 9002 : {
                 switch (axisNumber) {
-                    case 6 : { //-- 111 [E,N]
+                    case 0b0111 : { //-- [E,N]
                         epsgCSCode = "1039";
                         break;
                     }
-                    case 3 : { //-- 011 [N,E]
+                    case 0b0011 : { //-- [N,E]
                         epsgCSCode = "1029";
                         break;
                     }
@@ -690,7 +691,7 @@ public class TiffCRSBuilder {
             // Linear_Foot_US_Survey = 9003
             case 9003 : {
                 switch (axisNumber) {
-                    case 6 : { //-- 111 [E,N]
+                    case 0b0111 : { //-- [E,N]
                         epsgCSCode = "4497";
                         break;
                     }
@@ -705,11 +706,11 @@ public class TiffCRSBuilder {
             // Linear_Foot_Clarke = 9005
             case 9005 : {
                 switch (axisNumber) {
-                    case 6 : { //-- 111 [E,N]
+                    case 0b0111 : { //-- [E,N]
                         epsgCSCode = "4403";
                         break;
                     }
-                    case 3 : { //-- 011 [N,E]
+                    case 0b0011 : { //-- [N,E]
                         epsgCSCode = "4502";
                         break;
                     }
@@ -750,6 +751,143 @@ public class TiffCRSBuilder {
         return epsgFactory().createCartesianCS(epsgCSCode);
     }
 
+    /**
+     * Returns a {@link EllipsoidalCS} which is a combination of given base CS and tiff unit
key if exist.<br>
+     * The returned CS is searched and retrieved from epsg base if exist.<br>
+     * If don't exist, we call {@link CoordinateSystems#replaceAngularUnit(org.opengis.referencing.cs.CoordinateSystem,
javax.measure.Unit) }
+     * to build expected CS.<br>
+     * The retrieved Angular CS are :<br>
+     *
+     * <ul>
+     * <li> epsg : 6428 [Ellipsoidal 2D CS. Axes: latitude, longitude. Orientations:
north, east. UoM: rad] </li>
+     * <li> epsg : 6429 [Ellipsoidal 2D CS. Axes: longitude, latitude. Orientations:
east, north. UoM: rad] </li>
+     * <li> epsg : 6422 [Ellipsoidal 2D CS. Axes: latitude, longitude. Orientations:
north, east. UoM: degree] </li>
+     * <li> epsg : 6424 [Ellipsoidal 2D CS. Axes: longitude, latitude. Orientations:
east, north. UoM: degree] </li>
+     * <li> epsg : 6403 [Ellipsoidal 2D CS. Axes: latitude, longitude. Orientations:
north, east. UoM: grads.] </li>
+     * <li> epsg : 6425 [Ellipsoidal 2D CS. Axes: longitude, latitude. Orientations:
east, north. UoM: grads.] </li>
+     * </ul>
+     *
+     * @param baseCS
+     * @param fallBackUnit
+     * @return
+     */
+    private EllipsoidalCS retrieveEllipsoidalCS(final int unitKey, final EllipsoidalCS baseCS,
final Unit fallBackUnit)
+            throws FactoryException {
+        assert baseCS.getDimension() == 2;
+        CoordinateSystemAxis axis0 = baseCS.getAxis(0);
+        CoordinateSystemAxis axis1 = baseCS.getAxis(1);
+
+        //-------- Axis Number ----------------------
+        // axisnumber integer reference couple axis direction on 3 bits.
+        // higher's of the 3 bits, define axis combinaisons 1 for [E,N] or [W,S]
+        // and 0 for [N,E] or [S,W].
+        // secondly higher bit position define sens for first axis
+        // third and last bit position define sens for second axis.
+        // examples :
+        // [E,N] : axisNumber = 111
+        // [E,S] : axisNumber = 110
+        // [N,W] : axisNumber = 010
+        // [S,W] : axisNumber = 000 etc
+        //
+        //-------------------------------------------
+        int axisNumber = 0;
+        if (axis0.getDirection().equals(AxisDirection.EAST)
+         || axis0.getDirection().equals(AxisDirection.WEST)) {
+            axisNumber = 0b0100;
+            if (axis0.getDirection().equals(AxisDirection.EAST))  axisNumber |= 0b0010;
+            if (axis1.getDirection().equals(AxisDirection.NORTH)) axisNumber |= 0b0001;
+        } else if (axis0.getDirection().equals(AxisDirection.NORTH)
+                || axis0.getDirection().equals(AxisDirection.SOUTH)) {
+            if (axis0.getDirection().equals(AxisDirection.EAST))  axisNumber |= 0b0010;
+            if (axis1.getDirection().equals(AxisDirection.NORTH)) axisNumber |= 0b0001;
+        } else {
+            return (EllipsoidalCS) CoordinateSystems.replaceAngularUnit(baseCS, fallBackUnit);
+        }
+
+        //-- get the Unit epsg code if exist
+        String unitCode = geoKeys.getAsString(unitKey);
+        if (unitCode == null
+         || unitCode.equalsIgnoreCase(GeoKeys.Configuration.GTUserDefinedGeoKey_String))
+            return (EllipsoidalCS) CoordinateSystems.replaceAngularUnit(baseCS, fallBackUnit);
+        unitCode = unitCode.trim();
+
+        if (unitCode.startsWith("epsg:") || unitCode.startsWith("EPSG:"))
+            unitCode = unitCode.substring(5, unitCode.length());
+
+        int intCode = Integer.parseInt(unitCode);
+        String epsgCSCode = null;
+        switch (intCode) {
+            // Angular_Radian = 9101
+            case 9101 : {
+                switch (axisNumber) {
+                    case 0b0111 : { //-- [E,N]
+                        epsgCSCode = "6429";
+                        break;
+                    }
+                    case 0b0011 : { //-- [N,E]
+                        epsgCSCode = "6428";
+                        break;
+                    }
+                    default :
+                }
+                break;
+            }
+            //-- Angular_Degree = 9102
+            //-- into epsg base, 9102 angular degree was replaced by 9122
+            //-- following returned CS will be built with internal 9122 CS.
+            case 9102 : {
+                switch (axisNumber) {
+                    case 0b0111 : { //-- [E,N]
+                        epsgCSCode = "6424";
+                        break;
+                    }
+                    case 0b0011 : { //-- [N,E]
+                        epsgCSCode = "6422";
+                        break;
+                    }
+                    default :
+                }
+                break;
+            }
+            // Angular_Arc_Minute = 9103
+            case 9103 :
+            // Angular_Arc_Second = 9104
+            case 9104 : {
+                break;
+            }
+            // Angular_Grad = 9105
+            case 9105 : {
+                switch (axisNumber) {
+                    case 0b0111 : { //-- [E,N]
+                        epsgCSCode = "6425";
+                        break;
+                    }
+                    case 0b0011 : { //-- [N,E]
+                        epsgCSCode = "6403";
+                        break;
+                    }
+                    default :
+                }
+                break;
+            }
+            // Angular_Gon = 9106
+            case 9106 :
+            // Angular_DMS = 9107
+            case 9107 :
+            //-- Angular_DMS_Hemisphere = 9108
+            case 9108 :
+            default :
+        }
+
+        if (epsgCSCode == null)
+            //-- epsg CS + Unit not found
+            return (EllipsoidalCS) CoordinateSystems.replaceAngularUnit(baseCS, fallBackUnit);
+
+        epsgCSCode = "EPSG:".concat(epsgCSCode);
+
+        return epsgFactory().createEllipsoidalCS(epsgCSCode);
+    }
+
 
     ////////////////////////////////////////////////////////////////////////////
     //-------------------------- PROJECTED CRS -------------------------------//
@@ -913,8 +1051,11 @@ public class TiffCRSBuilder {
             //-- make the user defined GCS from all the components...
             return objectFactory().createGeographicCRS(name(name),
                                                        datum,
-                                       (EllipsoidalCS) CoordinateSystems.replaceAngularUnit(CommonCRS.defaultGeographic().getCoordinateSystem(),
-                                                                                        
              angularUnit));
+                                                       retrieveEllipsoidalCS(GeoKeys.CRS.GeogAngularUnitsGeoKey,
+                                                               CommonCRS.defaultGeographic().getCoordinateSystem(),
+                                                               angularUnit));
+//                                       (EllipsoidalCS) CoordinateSystems.replaceAngularUnit(CommonCRS.defaultGeographic().getCoordinateSystem(),
+//                                                                                      
                angularUnit));
         }
 
         //---------------------------------------------------------------------//
@@ -933,7 +1074,6 @@ public class TiffCRSBuilder {
             throw new IllegalArgumentException("Impossible to define CRS from none Geodetic
base. found : "+geoCRS.toWKT());
 
         if (!(geoCRS instanceof GeographicCRS)) {
-            //-- TODO log warning : is not instance of Geodetic try to re-build it
             warning(reader, Level.WARNING, Resources.Keys.UnexpectedGeoCRS_1, reader.input.filename);
             geoCRS = objectFactory().createGeographicCRS(name(IdentifiedObjects.getName(geoCRS,
new DefaultCitation("EPSG"))),
                                                         ((GeodeticCRS)geoCRS).getDatum(),
@@ -943,8 +1083,11 @@ public class TiffCRSBuilder {
         if (angularUnit != null
         && !angularUnit.equals(geoCRS.getCoordinateSystem().getAxis(0).getUnit()))
{
             geoCRS = objectFactory().createGeographicCRS(name(IdentifiedObjects.getName(geoCRS,
new DefaultCitation("EPSG"))),
-                    (GeodeticDatum) ((GeographicCRS)geoCRS).getDatum(),
-                    (EllipsoidalCS) CoordinateSystems.replaceAngularUnit(CommonCRS.defaultGeographic().getCoordinateSystem(),
angularUnit));
+                                                        (GeodeticDatum) ((GeographicCRS)geoCRS).getDatum(),
+                                                        retrieveEllipsoidalCS(GeoKeys.CRS.GeogAngularUnitsGeoKey,
+                                                                CommonCRS.defaultGeographic().getCoordinateSystem(),
+                                                                angularUnit));
+//                    (EllipsoidalCS) CoordinateSystems.replaceAngularUnit(CommonCRS.defaultGeographic().getCoordinateSystem(),
angularUnit));
         }
         return (GeographicCRS) geoCRS;
     }
@@ -1133,7 +1276,11 @@ public class TiffCRSBuilder {
             strBuild.append("\n");
 
             for (int key : keySet()) {
-                strBuild.append(GeoKeys.CRS.getName(key)+" ("+key+") = "+getAsString(key));
+                if (GeoKeys.contain(key)) {
+                    strBuild.append(GeoKeys.getName(key)+" ("+key+") = "+getAsString(key));
+                } else {
+                    strBuild.append("key : "+key+", is not recognized.");
+                }
                 strBuild.append("\n");
             }
             strBuild.append("/*****************************************************************************************/");



Mime
View raw message