From 94ae08701bbd7585a0b7e5a92d1975965a503c03 Mon Sep 17 00:00:00 2001
From: Dennis Kao <ulysseskao@gmail.com>
Date: Wed, 15 Jan 2014 11:28:52 +0800
Subject: [PATCH] Merge branch 'origin/2.1.x'

---
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TPCLIDConverter.java |  282 +++++++++++++++++++------------------------------------
 1 files changed, 98 insertions(+), 184 deletions(-)

diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TPCLIDConverter.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TPCLIDConverter.java
index 2a45c96..907cc5c 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TPCLIDConverter.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TPCLIDConverter.java
@@ -3,43 +3,38 @@
 import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Envelope;
 
-public abstract class TPCLIDConverter
-{
+public abstract class TPCLIDConverter {
     public final static int SX1200 = 800;
     public final static int SY1200 = 500;
     public final static int SX600 = 400;
     public final static int SY600 = 250;
 
-    public static String CoordinateToTpclId(Coordinate dp)
-    {
+    public static String CoordinateToTpclId(Coordinate dp) {
         long orgX, orgY;
         int mapX, mapY;
         int shiftX, shiftY;
         int dx1, dy1;
         int dx2, dy2;
 
-        if (dp == null)
-        {
+        if (dp == null) {
             return null;
         }
 
         double X = dp.x;
         double Y = dp.y;
 
-        String CoordToTPCLID = "";
+        String coordToTPCLID = "";
 
         char mapID = coordinateToSingleMapID(dp);
 
-        if (mapID == 'w')
-        {
+        if (mapID == 'w') {
             return "";
         }
 
         /* get the origin point of mapID */
         Coordinate Point = getOriginPoint("" + mapID, Integer.MAX_VALUE);
 
-        if (Point == null)
-        {
+        if (Point == null) {
             return null;
         }
 
@@ -48,8 +43,7 @@
 
         mapX = intDivision((X - orgX), SX1200);
 
-        if (mapID == 'Z' && mapX >= 100)
-        {
+        if (mapID == 'Z' && mapX >= 100) {
             mapX = mapX - 100;
         }
         mapY = intDivision((Y - orgY), SY1200);
@@ -61,18 +55,17 @@
         dy2 = (shiftY % 100) % 10;
 
 
-        CoordToTPCLID = "" + mapID;
-        CoordToTPCLID = CoordToTPCLID + dataFormat(mapX);
-        CoordToTPCLID = CoordToTPCLID + dataFormat(mapY);
-        CoordToTPCLID = CoordToTPCLID + intToAscii(shiftX / 100 + asciiToInt("A"));
-        CoordToTPCLID = CoordToTPCLID + intToAscii(shiftY / 100 + asciiToInt("A"));
-        CoordToTPCLID = CoordToTPCLID + dx1 + dy1 + dx2 + dy2;
+        coordToTPCLID = "" + mapID;
+        coordToTPCLID = coordToTPCLID + dataFormat(mapX);
+        coordToTPCLID = coordToTPCLID + dataFormat(mapY);
+        coordToTPCLID = coordToTPCLID + intToAscii(shiftX / 100 + asciiToInt("A"));
+        coordToTPCLID = coordToTPCLID + intToAscii(shiftY / 100 + asciiToInt("A"));
+        coordToTPCLID = coordToTPCLID + dx1 + dy1 + dx2 + dy2;
 
-        return CoordToTPCLID;
+        return coordToTPCLID;
     }
 
-    public static char coordinateToSingleMapID(Coordinate dp)
-    {
+    public static char coordinateToSingleMapID(Coordinate dp) {
         char mapID = 'w';
 
         String[] strY = StringUtils.splitToArray(Double.toString(dp.y), ".");
@@ -81,209 +74,164 @@
         int intY = Integer.parseInt(strY[0]);
         int intX = Integer.parseInt(strX[0]);
 
-        if (intY > 2944000)
-        {
+        if (intY > 2944000) {
             return mapID;
         }
-        if (intY >= 2894000 && intY <= 2944000 && intX >= 10000 && intX <= 90000)
-        {
+        if (intY >= 2894000 && intY <= 2944000 && intX >= 10000 && intX <= 90000) {
             mapID = 'S';
             return mapID;
         }
-        if (intY >= 2614000 && intY <= 2664000 && intX >= 10000 && intX <= 66000)
-        {
+        if (intY >= 2614000 && intY <= 2664000 && intX >= 10000 && intX <= 66000) {
             mapID = 'X';
             return mapID;
         }
-        if (intY >= 2564000 && intY <= 2614000 && intX >= 10000 && intX <= 66000)
-        {
+        if (intY >= 2564000 && intY <= 2614000 && intX >= 10000 && intX <= 66000) {
             mapID = 'Y';
             return mapID;
         }
-        if (intY >= 2675800 && intY <= 2725800 && intX >= 10000 && intX <= 170000)
-        {
+        if (intY >= 2675800 && intY <= 2725800 && intX >= 10000 && intX <= 170000) {
             mapID = 'Z';
             return mapID;
         }
-        if (intY > 2800000)
-        {
+        if (intY > 2800000) {
             return mapID;
         }
-        if (intY >= 2750000)
-        {
-            if (intX < 170000)
-            {
+        if (intY >= 2750000) {
+            if (intX < 170000) {
                 return mapID;
             }
-            if (intX < 250000)
-            {
+            if (intX < 250000) {
                 mapID = 'A';
                 return mapID;
             }
-            if (intX < 330000)
-            {
+            if (intX < 330000) {
                 mapID = 'B';
                 return mapID;
             }
-            if (intX < 410000)
-            {
+            if (intX < 410000) {
                 mapID = 'C';
                 return mapID;
             }
             return mapID;
         }
-        if (intY >= 2700000)
-        {
-            if (intX < 170000)
-            {
+        if (intY >= 2700000) {
+            if (intX < 170000) {
                 return mapID;
             }
-            if (intX < 250000)
-            {
+            if (intX < 250000) {
                 mapID = 'D';
                 return mapID;
             }
-            if (intX < 330000)
-            {
+            if (intX < 330000) {
                 mapID = 'E';
                 return mapID;
             }
-            if (intX < 410000)
-            {
+            if (intX < 410000) {
                 mapID = 'F';
                 return mapID;
             }
             return mapID;
         }
-        if (intY >= 2650000)
-        {
-            if (intX < 170000)
-            {
+        if (intY >= 2650000) {
+            if (intX < 170000) {
                 return mapID;
             }
-            if (intX < 250000)
-            {
+            if (intX < 250000) {
                 mapID = 'G';
                 return mapID;
             }
-            if (intX < 330000)
-            {
+            if (intX < 330000) {
                 mapID = 'H';
                 return mapID;
             }
-            if (intX < 410000)
-            {
+            if (intX < 410000) {
                 mapID = 'I';
                 return mapID;
             }
             return mapID;
         }
-        if (intY >= 2600000)
-        {
-            if (intX < 90000)
-            {
+        if (intY >= 2600000) {
+            if (intX < 90000) {
                 return mapID;
             }
-            if (intX < 170000)
-            {
+            if (intX < 170000) {
                 mapID = 'J';
                 return mapID;
             }
-            if (intX < 250000)
-            {
+            if (intX < 250000) {
                 mapID = 'K';
                 return mapID;
             }
-            if (intX < 330000)
-            {
+            if (intX < 330000) {
                 mapID = 'L';
                 return mapID;
             }
             return mapID;
         }
-        if (intY >= 2550000)
-        {
-            if (intX < 90000)
-            {
+        if (intY >= 2550000) {
+            if (intX < 90000) {
                 return mapID;
             }
-            if (intX < 170000)
-            {
+            if (intX < 170000) {
                 mapID = 'M';
                 return mapID;
             }
 
-            if (intX < 250000)
-            {
+            if (intX < 250000) {
                 mapID = 'N';
                 return mapID;
             }
-            if (intX < 330000)
-            {
+            if (intX < 330000) {
                 mapID = 'O';
                 return mapID;
             }
             return mapID;
         }
-        if (intY >= 2500000)
-        {
-            if (intX < 90000)
-            {
+        if (intY >= 2500000) {
+            if (intX < 90000) {
                 return mapID;
             }
-            if (intX < 170000)
-            {
+            if (intX < 170000) {
                 mapID = 'P';
                 return mapID;
             }
-            if (intX < 250000)
-            {
+            if (intX < 250000) {
                 mapID = 'Q';
                 return mapID;
             }
-            if (intX < 330000)
-            {
+            if (intX < 330000) {
                 mapID = 'R';
                 return mapID;
             }
             return mapID;
         }
-        if (intY >= 2450000)
-        {
-            if (intX < 90000)
-            {
+        if (intY >= 2450000) {
+            if (intX < 90000) {
                 return mapID;
             }
-            if (intX < 170000)
-            {
+            if (intX < 170000) {
                 mapID = 'S';
                 return mapID;
             }
-            if (intX < 250000)
-            {
+            if (intX < 250000) {
                 mapID = 'T';
                 return mapID;
             }
-            if (intX < 330000)
-            {
+            if (intX < 330000) {
                 mapID = 'U';
                 return mapID;
             }
             return mapID;
         }
-        if (intY >= 2400000)
-        {
-            if (intX < 170000)
-            {
+        if (intY >= 2400000) {
+            if (intX < 170000) {
                 return mapID;
             }
-            if (intX < 250000)
-            {
+            if (intX < 250000) {
                 mapID = 'V';
                 return mapID;
             }
-            if (intX < 330000)
-            {
+            if (intX < 330000) {
                 mapID = 'W';
                 return mapID;
             }
@@ -292,16 +240,14 @@
         return mapID;
     }
 
-    public static Envelope convertTpclIdToEnvelope(String tpclid)
-    {
+    public static Envelope convertTpclIdToEnvelope(String tpclid) {
         String tempString = "";
 
         Coordinate point = null;
         Coordinate tempPoint = null;
         double width, height;
 
-        if (tpclid.length() < 5)
-        {
+        if (tpclid.length() < 5) {
             return null;
         }
 
@@ -311,8 +257,7 @@
         // Get the origin point
         point = getOriginPoint(tempString, xmapid);
 
-        if (point == null)
-        {
+        if (point == null) {
             return null;
         }
 
@@ -322,18 +267,15 @@
         height = SY1200;
 
         tempPoint = twoNumberScale(tempString, 800, 500);
-        if (tempPoint != null)
-        {
+        if (tempPoint != null) {
             point.x = (point.x + tempPoint.x);
             point.y = (point.y + tempPoint.y);
         }
 
-        if (tpclid.length() >= 7)
-        {
+        if (tpclid.length() >= 7) {
             tempString = (asciiToInt(tpclid.substring(5, 6)) - 65) + "" + (asciiToInt(tpclid.substring(6, 7)) - 65);
             tempPoint = twoNumberScale(tempString, 100);
-            if (tempPoint != null)
-            {
+            if (tempPoint != null) {
                 point.x = point.x + tempPoint.x;
                 point.y = point.y + tempPoint.y;
             }
@@ -341,12 +283,10 @@
             height = 100.0;
         }
 
-        if (tpclid.length() >= 9)
-        {
+        if (tpclid.length() >= 9) {
             tempString = tpclid.substring(7, 8);
             tempPoint = twoNumberScale(tempString, 10);
-            if (tempPoint != null)
-            {
+            if (tempPoint != null) {
                 point.x = point.x + tempPoint.x;
                 point.y = point.y + tempPoint.y;
             }
@@ -354,12 +294,10 @@
             height = 10.0;
         }
 
-        if (tpclid.length() >= 11)
-        {
+        if (tpclid.length() >= 11) {
             tempString = tpclid.substring(10);
             tempPoint = twoNumberScale(tempString, 1);
-            if (tempPoint != null)
-            {
+            if (tempPoint != null) {
                 point.x = point.x + tempPoint.x;
                 point.y = point.y + tempPoint.y;
             }
@@ -373,15 +311,13 @@
         return new Envelope(point, pt2);
     }
 
-    public static Coordinate convertTpclIdToCoordinate(String tpclid)
-    {
+    public static Coordinate convertTpclIdToCoordinate(String tpclid) {
         String tempString = "";
 
         Coordinate point = null;
         Coordinate tempPoint = null;
 
-        if (tpclid.length() < 5)
-        {
+        if (tpclid.length() < 5) {
             return null;
         }
 
@@ -391,8 +327,7 @@
         // Get the origin point
         point = getOriginPoint(tempString, xmapid);
 
-        if (point == null)
-        {
+        if (point == null) {
             return null;
         }
 
@@ -400,40 +335,33 @@
         tempString = tpclid.substring(1, 5);
 
         tempPoint = twoNumberScale(tempString, 800, 500);
-        if (tempPoint != null)
-        {
+        if (tempPoint != null) {
             point.x = (point.x + tempPoint.x);
             point.y = (point.y + tempPoint.y);
         }
 
-        if (tpclid.length() >= 7)
-        {
+        if (tpclid.length() >= 7) {
             tempString = (asciiToInt(tpclid.substring(5, 6)) - 65) + "" + (asciiToInt(tpclid.substring(6, 7)) - 65);
             tempPoint = twoNumberScale(tempString, 100);
-            if (tempPoint != null)
-            {
+            if (tempPoint != null) {
                 point.x = point.x + tempPoint.x;
                 point.y = point.y + tempPoint.y;
             }
         }
 
-        if (tpclid.length() >= 9)
-        {
+        if (tpclid.length() >= 9) {
             tempString = tpclid.substring(7, 9);
             tempPoint = twoNumberScale(tempString, 10);
-            if (tempPoint != null)
-            {
+            if (tempPoint != null) {
                 point.x = point.x + tempPoint.x;
                 point.y = point.y + tempPoint.y;
             }
         }
 
-        if (tpclid.length() >= 11)
-        {
+        if (tpclid.length() >= 11) {
             tempString = tpclid.substring(10);
             tempPoint = twoNumberScale(tempString, 1);
-            if (tempPoint != null)
-            {
+            if (tempPoint != null) {
                 point.x = point.x + tempPoint.x;
                 point.y = point.y + tempPoint.y;
             }
@@ -442,8 +370,7 @@
     }
 
 
-    private static int intDivision(double p1, int p2)
-    {
+    private static int intDivision(double p1, int p2) {
         double resultValue = 0.0;
         String result;
         resultValue = p1 / p2;
@@ -454,24 +381,19 @@
     }
 
 
-    private static Coordinate twoNumberScale(String number, int scaleX, int scaleY)
-    {
+    private static Coordinate twoNumberScale(String number, int scaleX, int scaleY) {
         Coordinate tempPoint = new Coordinate();
 
-        if (number.length() == 2)
-        {
+        if (number.length() == 2) {
             tempPoint.x = Double.parseDouble(number.substring(0, 1)) * scaleX;
             tempPoint.y = Double.parseDouble(number.substring(1, 2)) * scaleY;
-        } else if (number.length() == 1)
-        {
+        } else if (number.length() == 1) {
             tempPoint.x = Double.parseDouble(number.substring(0, 1)) * scaleX;
             tempPoint.y = 0;
-        } else if (number.length() == 4)
-        {
+        } else if (number.length() == 4) {
             tempPoint.x = Double.parseDouble(number.substring(0, 2)) * scaleX;
             tempPoint.y = Double.parseDouble(number.substring(2, 4)) * scaleY;
-        } else
-        {
+        } else {
             tempPoint.x = 0;
             tempPoint.y = 0;
         }
@@ -479,8 +401,7 @@
     }
 
 
-    public static int asciiToInt(String p1)
-    {
+    public static int asciiToInt(String p1) {
         if (p1.endsWith("A")) return 65;
         if (p1.endsWith("B")) return 66;
         if (p1.endsWith("C")) return 67;
@@ -511,10 +432,8 @@
     }
 
 
-    public static char intToAscii(int p1)
-    {
-        switch (p1)
-        {
+    public static char intToAscii(int p1) {
+        switch (p1) {
         case 65:
             return 'A';
         case 66:
@@ -573,12 +492,10 @@
     }
 
 
-    private static Coordinate getOriginPoint(String letter, int xMapId)
-    {
+    private static Coordinate getOriginPoint(String letter, int xMapId) {
         int aSwitch = asciiToInt(letter);
         Coordinate Point = new Coordinate();
-        switch (aSwitch)
-        {
+        switch (aSwitch) {
         case 65: //A
         {
             Point.x = 170000;
@@ -687,7 +604,7 @@
             Point.y = 2500000;
             break;
         }
-        case 83: //���� S
+        case 83: // S
         {
             Point.x = 10000;
             Point.y = 2894000;
@@ -717,26 +634,25 @@
             Point.y = 2400000;
             break;
         }
-        case 88: //��� X
+        case 88: //X
         {
             Point.x = 10000;
             Point.y = 2614000;
             break;
         }
-        case 89: //��� Y
+        case 89: //Y
         {
             Point.x = 10000;
             Point.y = 2564000;
             break;
         }
-        case 90: //���� ��Z
+        case 90: //Z
         {
             Point.x = (xMapId < 51) ? 90000 : 10000;
             Point.y = 2675800;
             break;
         }
-        default:
-        {
+        default: {
             return null;
         }
         }
@@ -744,14 +660,12 @@
     }
 
 
-    private static Coordinate twoNumberScale(String number, int scale)
-    {
+    private static Coordinate twoNumberScale(String number, int scale) {
         return twoNumberScale(number, scale, scale);
     }
 
 
-    private static String dataFormat(int p1)
-    {
+    private static String dataFormat(int p1) {
         String s1 = Integer.toString(p1);
         if (s1.length() < 2)
             s1 = "0" + s1;

--
Gitblit v0.0.0-SNAPSHOT