Revision: 5014
          http://sourceforge.net/p/jump-pilot/code/5014
Author:   michaudm
Date:     2016-09-10 14:20:51 +0000 (Sat, 10 Sep 2016)
Log Message:
-----------
Normalize method name in ProjUtils2 and moved test code to jumptest directory.

Modified Paths:
--------------
    core/trunk/src/org/openjump/core/ccordsys/utils/ProjUtils2.java
    core/trunk/src/org/openjump/core/ccordsys/utils/SridLookupTable.java
    core/trunk/src/org/openjump/core/rasterimage/TiffTags.java

Added Paths:
-----------
    core/trunk/src/jumptest/ccordsys/
    core/trunk/src/jumptest/ccordsys/ProjUtilsTest.java

Added: core/trunk/src/jumptest/ccordsys/ProjUtilsTest.java
===================================================================
--- core/trunk/src/jumptest/ccordsys/ProjUtilsTest.java                         
(rev 0)
+++ core/trunk/src/jumptest/ccordsys/ProjUtilsTest.java 2016-09-10 14:20:51 UTC 
(rev 5014)
@@ -0,0 +1,93 @@
+package jumptest.ccordsys;
+
+import junit.framework.TestCase;
+import org.openjump.core.ccordsys.utils.SRSInfo;
+import org.openjump.core.rasterimage.TiffTags;
+
+import java.io.File;
+
+/**
+ * Created by UMichael on 10/09/2016.
+ */
+public class ProjUtilsTest extends TestCase {
+    public static void main(String[] args) throws Exception {
+        /*
+        File src1 = new File("D:\\DATA\\FORMATS\\GeoTIFF\\gdal_eg\\cea.tif");
+        File src2 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\GeogToWGS84GeoKey\\GeogToWGS84GeoKey5.tif");
+        File src3 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\intergraph\\albers27.tif");
+        File src4 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\intergraph\\lamb_conf.tif");
+        File src5 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\intergraph\\utm.tif");
+        File src6 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\made_up\\bogota.tif");
+        File src7 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\made_up\\ilatlon_float.tif");
+        File src8 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\made_up\\lcc-datum.tif");
+        File src9 = new File("D:\\DATA\\FORMATS\\GeoTIFF\\misc\\tjpeg.tif");
+        File src10 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\other\\erdas_spnad83.tif");
+        File src11 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\pci_eg\\oblqmerc.tif");
+        File src12 = new File("D:\\DATA\\FORMATS\\GeoTIFF\\usgs\\ilatlon.tif");
+        File src13 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\usgs\\o41078a1.tif");
+        File src14 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\zi_imaging\\image0.tif");
+        File src15 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\zi_imaging\\tp_image0.tif");
+
+        SRSInfo info1 = TiffTags.readMetadata(src1).getSRSInfo();
+        System.out.printf("%s%n%n", info1);
+
+        System.out.println("");
+        SRSInfo info2 = TiffTags.readMetadata(src2).getSRSInfo();
+        System.out.printf("%s%n%n", info2);
+
+        System.out.println("");
+        SRSInfo info3 = TiffTags.readMetadata(src3).getSRSInfo();
+        System.out.printf("%s%n%n", info3);
+
+        System.out.println("");
+        SRSInfo info4 = TiffTags.readMetadata(src4).getSRSInfo();
+        System.out.printf("%s%n%n", info4);
+
+        System.out.println("");
+        SRSInfo info5 = TiffTags.readMetadata(src5).getSRSInfo();
+        System.out.printf("%s%n%n", info5);
+
+        System.out.println("");
+        SRSInfo info6 = TiffTags.readMetadata(src6).getSRSInfo();
+        System.out.printf("%s%n%n", info6);
+
+        SRSInfo info7 = TiffTags.readMetadata(src7).getSRSInfo();
+        System.out.printf("%s%n%n", info7);
+
+        SRSInfo info8 = TiffTags.readMetadata(src8).getSRSInfo();
+        System.out.printf("%s%n%n", info8);
+
+        SRSInfo info9 = TiffTags.readMetadata(src9).getSRSInfo();
+        System.out.printf("%s%n%n", info9);
+
+        SRSInfo info10 = TiffTags.readMetadata(src10).getSRSInfo();
+        System.out.printf("%s%n%n", info10);
+
+        SRSInfo info11 = TiffTags.readMetadata(src11).getSRSInfo();
+        System.out.printf("%s%n%n", info11);
+
+        SRSInfo info12 = TiffTags.readMetadata(src12).getSRSInfo();
+        System.out.printf("%s%n%n", info12);
+
+        SRSInfo info13 = TiffTags.readMetadata(src13).getSRSInfo();
+        System.out.printf("%s%n%n", info13);
+
+        SRSInfo info14 = TiffTags.readMetadata(src14).getSRSInfo();
+        System.out.printf("%s%n%n", info14);
+
+        SRSInfo info15 = TiffTags.readMetadata(src15).getSRSInfo();
+        System.out.printf("%s%n%n", info15);
+        //System.out.printf("%s%n", md.getEnvelope());
+        */
+
+    }
+
+    public void testGetSRSInfoFromGeoTiff() throws Exception {
+        File src1 = new File("D:\\DATA\\FORMATS\\GeoTIFF\\gdal_eg\\cea.tif");
+        SRSInfo info1 = TiffTags.readMetadata(src1).getSRSInfo();
+        System.out.printf("%s%n%n", info1);
+        assertEquals("cea.tiff contains unnamed NAD27", "unnamed NAD27", 
info1.getDescription());
+    }
+
+
+}

Modified: core/trunk/src/org/openjump/core/ccordsys/utils/ProjUtils2.java
===================================================================
--- core/trunk/src/org/openjump/core/ccordsys/utils/ProjUtils2.java     
2016-09-10 11:29:03 UTC (rev 5013)
+++ core/trunk/src/org/openjump/core/ccordsys/utils/ProjUtils2.java     
2016-09-10 14:20:51 UTC (rev 5014)
@@ -43,78 +43,7 @@
     private static final String NOT_RECOGNIZED = I18N
             
.get("org.openjump.core.ui.plugin.layer.LayerPropertiesPlugIn.Not_recognized");
 
-    public static void main(String[] args) throws Exception {
-        File src1 = new File("D:\\DATA\\FORMATS\\GeoTIFF\\gdal_eg\\cea.tif");
-        File src2 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\GeogToWGS84GeoKey\\GeogToWGS84GeoKey5.tif");
-        File src3 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\intergraph\\albers27.tif");
-        File src4 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\intergraph\\lamb_conf.tif");
-        File src5 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\intergraph\\utm.tif");
-        File src6 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\made_up\\bogota.tif");
-        File src7 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\made_up\\ilatlon_float.tif");
-        File src8 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\made_up\\lcc-datum.tif");
-        File src9 = new File("D:\\DATA\\FORMATS\\GeoTIFF\\misc\\tjpeg.tif");
-        File src10 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\other\\erdas_spnad83.tif");
-        File src11 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\pci_eg\\oblqmerc.tif");
-        File src12 = new File("D:\\DATA\\FORMATS\\GeoTIFF\\usgs\\ilatlon.tif");
-        File src13 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\usgs\\o41078a1.tif");
-        File src14 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\zi_imaging\\image0.tif");
-        File src15 = new 
File("D:\\DATA\\FORMATS\\GeoTIFF\\zi_imaging\\tp_image0.tif");
 
-        SRSInfo info1 = TiffTags.readMetadata(src1).getSRSInfo();
-        System.out.printf("%s%n%n", info1);
-
-        System.out.println("");
-        SRSInfo info2 = TiffTags.readMetadata(src2).getSRSInfo();
-        System.out.printf("%s%n%n", info2);
-
-        System.out.println("");
-        SRSInfo info3 = TiffTags.readMetadata(src3).getSRSInfo();
-        System.out.printf("%s%n%n", info3);
-
-        System.out.println("");
-        SRSInfo info4 = TiffTags.readMetadata(src4).getSRSInfo();
-        System.out.printf("%s%n%n", info4);
-
-        System.out.println("");
-        SRSInfo info5 = TiffTags.readMetadata(src5).getSRSInfo();
-        System.out.printf("%s%n%n", info5);
-
-        System.out.println("");
-        SRSInfo info6 = TiffTags.readMetadata(src6).getSRSInfo();
-        System.out.printf("%s%n%n", info6);
-
-        SRSInfo info7 = TiffTags.readMetadata(src7).getSRSInfo();
-        System.out.printf("%s%n%n", info7);
-
-        SRSInfo info8 = TiffTags.readMetadata(src8).getSRSInfo();
-        System.out.printf("%s%n%n", info8);
-
-        SRSInfo info9 = TiffTags.readMetadata(src9).getSRSInfo();
-        System.out.printf("%s%n%n", info9);
-
-        SRSInfo info10 = TiffTags.readMetadata(src10).getSRSInfo();
-        System.out.printf("%s%n%n", info10);
-
-        SRSInfo info11 = TiffTags.readMetadata(src11).getSRSInfo();
-        System.out.printf("%s%n%n", info11);
-
-        SRSInfo info12 = TiffTags.readMetadata(src12).getSRSInfo();
-        System.out.printf("%s%n%n", info12);
-
-        SRSInfo info13 = TiffTags.readMetadata(src13).getSRSInfo();
-        System.out.printf("%s%n%n", info13);
-
-        SRSInfo info14 = TiffTags.readMetadata(src14).getSRSInfo();
-        System.out.printf("%s%n%n", info14);
-
-        SRSInfo info15 = TiffTags.readMetadata(src15).getSRSInfo();
-        System.out.printf("%s%n%n", info15);
-        //System.out.printf("%s%n", md.getEnvelope());
-
-    }
-
-
-
     /**
      * - Read SRS from GeoTIFF tag - This method gets projection srid code and
      * projection info from a geotiff file. It first scans GeoKeyDirectoryTag 
to
@@ -130,7 +59,7 @@
      * @throws URISyntaxException
      */
     @SuppressWarnings("static-access")
-    public static SRSInfo readSRSFromGeoTiffFile(String fileSourcePath)
+    public static SRSInfo getSRSInfoFromGeoTiff(String fileSourcePath)
             throws IOException, URISyntaxException, 
TiffTags.TiffReadingException, ImageReadException {
         return TiffTags.readMetadata(new File(fileSourcePath)).getSRSInfo();
     }
@@ -152,7 +81,7 @@
      * @throws IOException
      */
 
-    public static SRSInfo readSRSFromAuxiliaryFile(String fileSourcePath)
+    public static SRSInfo getSRSInfoFromAuxiliaryFile(String fileSourcePath)
             throws URISyntaxException, IOException {
 
         // --- it reads an auxiliary file and decode a possible proj
@@ -303,7 +232,7 @@
      * @return SRID
      * @throws Exception
      */
-    public static SRSInfo SRSInfoFromStyleOrFile(Layer layer) throws Exception 
{
+    public static SRSInfo getSRSInfoFromLayerStyleOrSource(Layer layer) throws 
Exception {
         SRSInfo srsInfo = new SRSInfo();
 
         // First we check if a SRID != 0 has already been recorded for this 
Layer
@@ -315,7 +244,7 @@
             // If no SRID has been identified, search for a SRID in geotiff 
tagg
             // or into an auxiliary file
         } else {
-            srsInfo = SRSInfoFromFile(layer);
+            srsInfo = getSRSInfoFromLayerSource(layer);
         }
 
         return srsInfo;
@@ -331,7 +260,7 @@
      * @return SRID
      * @throws Exception
      */
-    public static SRSInfo SRSInfoFromFile(Layer layer) throws Exception {
+    public static SRSInfo getSRSInfoFromLayerSource(Layer layer) throws 
Exception {
         String fileSourcePath = "";
         SRSInfo srsInfo = new SRSInfo();
         // Raster layer case
@@ -359,10 +288,10 @@
                     // If the TIF file is not a GeoTIFF it looks
                     // for a proj code into aux files
                 } else {
-                    srsInfo = readSRSFromAuxiliaryFile(fileSourcePath);
+                    srsInfo = getSRSInfoFromAuxiliaryFile(fileSourcePath);
                 }
             } else {
-                srsInfo = readSRSFromAuxiliaryFile(fileSourcePath);
+                srsInfo = getSRSInfoFromAuxiliaryFile(fileSourcePath);
             }
         }
         // Vector layer case
@@ -371,7 +300,7 @@
                 DataSourceQuery dsq = layer.getDataSourceQuery();
                 Object fnameObj = 
dsq.getDataSource().getProperties().get("File");
                 fileSourcePath = fnameObj.toString();
-                srsInfo = readSRSFromAuxiliaryFile(fileSourcePath);
+                srsInfo = getSRSInfoFromAuxiliaryFile(fileSourcePath);
             }
         }
         return srsInfo;

Modified: core/trunk/src/org/openjump/core/ccordsys/utils/SridLookupTable.java
===================================================================
--- core/trunk/src/org/openjump/core/ccordsys/utils/SridLookupTable.java        
2016-09-10 11:29:03 UTC (rev 5013)
+++ core/trunk/src/org/openjump/core/ccordsys/utils/SridLookupTable.java        
2016-09-10 14:20:51 UTC (rev 5014)
@@ -57,7 +57,9 @@
                 Matcher m = pattern.matcher(line);
                 if (m.matches()) {
                     if (m.group(1).equals(code)) {
-                        
srsInfo.setCode(m.group(1)).setDescription(m.group(2)).setUnit(m.group(3));
+                        srsInfo .setCode(m.group(1))
+                                .setDescription(m.group(2))
+                                .setUnit(getUnitFromString(m.group(3)));
                     }
                 }
             }
@@ -76,7 +78,9 @@
                 Matcher m = pattern.matcher(line);
                 if (m.matches()) {
                     if (normalize(m.group(2)).equals(normalize(name))) {
-                        
srsInfo.setCode(m.group(1)).setDescription(m.group(2)).setUnit(m.group(3));
+                        srsInfo .setCode(m.group(1))
+                                .setDescription(m.group(2))
+                                .setUnit(getUnitFromString(m.group(3)));
                     }
                 }
             }
@@ -96,7 +100,9 @@
                 if (m.matches()) {
                     if (m.group(1).equals(codeOrName) ||
                             
normalize(m.group(2)).equals(normalize(codeOrName))) {
-                        
srsInfo.setCode(m.group(1)).setDescription(m.group(2)).setUnit(m.group(3));
+                        srsInfo .setCode(m.group(1))
+                                .setDescription(m.group(2))
+                                .setUnit(getUnitFromString(m.group(3)));
                     }
                 }
             }
@@ -125,6 +131,10 @@
         return srsInfo == null ? null : srsInfo.getUnit();
     }
 
+    private static Unit getUnitFromString(String u){
+        return Unit.valueOf(u.toUpperCase().replaceAll("METRE","METER"));
+    }
+
     /**
      * Use this function to normalize srs name and get a chance to match it
      * with the one in srid.txt

Modified: core/trunk/src/org/openjump/core/rasterimage/TiffTags.java
===================================================================
--- core/trunk/src/org/openjump/core/rasterimage/TiffTags.java  2016-09-10 
11:29:03 UTC (rev 5013)
+++ core/trunk/src/org/openjump/core/rasterimage/TiffTags.java  2016-09-10 
14:20:51 UTC (rev 5014)
@@ -75,7 +75,7 @@
                     break;
                 case GeoTiffConstants.GeoAsciiParamsTag:
                     geoAsciiParams = tiffField.getStringValue();
-                    geoAsciiParams = geoAsciiParams.replaceAll("[\\s\\|_;]+", 
" ");
+                    geoAsciiParams = geoAsciiParams.replaceAll("[\\s\\|_;]+", 
" ").trim();
                     srsInfo.setDescription(geoAsciiParams);
                     System.out.println(geoAsciiParams);
             }


------------------------------------------------------------------------------
_______________________________________________
Jump-pilot-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to