From 7840e31dd97db0efe77bdf859ac2fe9767d3dd1a Mon Sep 17 00:00:00 2001
From: ?? ? <ulysseskao@ximple.com.tw>
Date: Mon, 14 Apr 2008 15:35:17 +0800
Subject: [PATCH] update for EOFM-42

---
 /dev/null                                                                                           |    5 -
 .gitattributes                                                                                      |    2 
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java                     |    2 
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java                                 |    5 +
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/TWD97GeometryConverterDecorator.java |   75 +++++++++++++++++++++++++
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TWDDatumConverter.java               |   34 ++++++-----
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineStringStrategy.java      |    8 ++
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java            |    8 ++
 8 files changed, 111 insertions(+), 28 deletions(-)

diff --git a/.gitattributes b/.gitattributes
index 07b16d5..672505c 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -56,11 +56,11 @@
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/TypeIdDispatchableFilter.java svneol=native#text/plain
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/AbstractOracleDatabaseJob.java svneol=native#text/plain
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/AbstractOracleJobContext.java svneol=native#text/plain
-xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeometryCoordinateDecorator.java svneol=native#text/plain
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java svneol=native#text/plain
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertJobContext.java svneol=native#text/plain
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleUpgradeBlob2UDTJob.java svneol=native#text/plain
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleUpgradeJobContext.java svneol=native#text/plain
+xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/TWD97GeometryConverterDecorator.java svneol=native#text/plain
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/BinConverter.java svneol=native#text/plain
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/Bits.java svneol=native#text/plain
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/ByteArrayCompressor.java svneol=native#text/plain
diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java
index 1e0d605..c4dec54 100644
--- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java
+++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java
@@ -21,7 +21,7 @@
  */
 public class ComplexChainElement extends Element implements ComplexElement, GeometryConverter
 {
-    ArrayList list = new ArrayList();
+    protected ArrayList list = new ArrayList();
 
     public ComplexChainElement(short[] raw)
     {
diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java
index 8bdb62c..c8282b4 100644
--- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java
+++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/Element.java
@@ -32,8 +32,9 @@
     public static final int PATTERN_HATCH           = 0;
     public static final int PRIMARY_CLASS           = 0;
     public static final int PRIMARY_RULE_CLASS      = 0;
-    short[]                 raw;
-    byte                    attrOffset = 0;
+
+    protected short[]   raw;
+    protected byte      attrOffset = 0;
 
     public Element(short[] raw)
     {
diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineStringStrategy.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineStringStrategy.java
index a9a731c..0bf7f05 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineStringStrategy.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineStringStrategy.java
@@ -13,11 +13,13 @@
 import com.vividsolutions.jts.geom.Geometry;
 
 import com.ximple.io.dgn7.*;
+import com.ximple.eofms.jobs.TWD97GeometryConverterDecorator;
 
 public class CreateLineStringStrategy implements CreateFeatureTypeStrategy
 {
     GeometryFactory geometryFactory = new GeometryFactory();
     FeatureTypeBuilder typeBuilder = null;
+    TWD97GeometryConverterDecorator convertDecordator = new TWD97GeometryConverterDecorator();
 
     public CreateLineStringStrategy()
     {
@@ -64,8 +66,9 @@
         if (element instanceof LineStringElement)
         {
             LineStringElement lineStringElement = (LineStringElement) element;
+            convertDecordator.setConverter(lineStringElement);
             Feature feature = featureType.create(new Object[]{
-                    lineStringElement.toGeometry(geometryFactory),
+                    convertDecordator.toGeometry(geometryFactory),
                     (int) fLinkage.getFsc(),
                     (long) fLinkage.getUfid(),
                     (int) fLinkage.getComponentID(),
@@ -79,8 +82,9 @@
         } else if (element instanceof ComplexChainElement)
         {
             ComplexChainElement complexChain = (ComplexChainElement) element;
+            convertDecordator.setConverter(complexChain);
             Feature feature = featureType.create(new Object[]{
-                    complexChain.toGeometry(geometryFactory),
+                    convertDecordator.toGeometry(geometryFactory),
                     (int) fLinkage.getFsc(),
                     (long) fLinkage.getUfid(),
                     (int) fLinkage.getComponentID(),
diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java
index 254d071..9a231ef 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java
@@ -17,11 +17,13 @@
 import com.ximple.io.dgn7.TextElement;
 import com.ximple.io.dgn7.UserAttributeData;
 import com.ximple.io.dgn7.TextNodeElement;
+import com.ximple.eofms.jobs.TWD97GeometryConverterDecorator;
 
 public class CreateTextStrategy implements CreateFeatureTypeStrategy
 {
     GeometryFactory geometryFactory = new GeometryFactory();
     FeatureTypeBuilder typeBuilder = null;
+    TWD97GeometryConverterDecorator convertDecordator = new TWD97GeometryConverterDecorator();
 
     public CreateTextStrategy()
     {
@@ -74,8 +76,9 @@
         if (element instanceof TextElement)
         {
             TextElement txtElement = (TextElement) element;
+            convertDecordator.setConverter(txtElement);
             Feature feature = featureType.create(new Object[]{
-                    txtElement.toGeometry(geometryFactory),
+                    convertDecordator.toGeometry(geometryFactory),
                     (int) fLinkage.getFsc(),
                     (long) fLinkage.getUfid(),
                     (int) fLinkage.getComponentID(),
@@ -95,6 +98,7 @@
         } else if (element instanceof TextNodeElement)
         {
             TextNodeElement nodeElement = (TextNodeElement) element;
+            convertDecordator.setConverter(nodeElement);
             String[] texts = nodeElement.getTextArray();
             StringBuffer sb = new StringBuffer();
             for (String text : texts)
@@ -105,7 +109,7 @@
             }
 
             Feature feature = featureType.create(new Object[]{
-                    nodeElement.toGeometry(geometryFactory),
+                    convertDecordator.toGeometry(geometryFactory),
                     (int) fLinkage.getFsc(),
                     (long) fLinkage.getUfid(),
                     (int) fLinkage.getComponentID(),
diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeometryCoordinateDecorator.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeometryCoordinateDecorator.java
deleted file mode 100644
index b0afc7f..0000000
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeometryCoordinateDecorator.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.ximple.eofms.jobs;
-
-public interface GeometryCoordinateDecorator
-{
-}
diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/TWD97GeometryConverterDecorator.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/TWD97GeometryConverterDecorator.java
new file mode 100644
index 0000000..8968e34
--- /dev/null
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/TWD97GeometryConverterDecorator.java
@@ -0,0 +1,75 @@
+package com.ximple.eofms.jobs;
+
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.CoordinateSequenceFilter;
+import com.vividsolutions.jts.geom.CoordinateSequence;
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.util.Assert;
+
+import com.ximple.io.dgn7.GeometryConverter;
+import com.ximple.eofms.util.TWDDatumConverter;
+
+public class TWD97GeometryConverterDecorator implements GeometryConverter
+{
+    private GeometryConverter converter;
+    private TWD97ConvertFilter coordinatesFilter = new TWD97ConvertFilter();
+
+    public TWD97GeometryConverterDecorator()
+    {
+    }
+
+    public GeometryConverter getConverter()
+    {
+        return converter;
+    }
+
+    public void setConverter(GeometryConverter converter)
+    {
+        this.converter = converter;
+    }
+
+    public Geometry toGeometry(GeometryFactory factory)
+    {
+        if (converter == null) Assert.shouldNeverReachHere();
+
+        coordinatesFilter.reset();
+
+        Geometry geom = converter.toGeometry(factory);
+        geom.apply(coordinatesFilter);
+        return geom;
+    }
+
+    class TWD97ConvertFilter implements CoordinateSequenceFilter
+    {
+        private boolean done = false;
+        private boolean geometryChanged = false;
+
+        public void filter(CoordinateSequence coordinateSequence, int i)
+        {
+            Coordinate pt = coordinateSequence.getCoordinateCopy(i);
+            Coordinate pt97 = TWDDatumConverter.toTWD97(pt);
+            pt.x = pt97.x;
+            pt.y = pt97.y;
+            pt.z = pt97.z;
+            done = (i >= coordinateSequence.size());
+            geometryChanged = true;
+        }
+
+        public boolean isDone()
+        {
+            return done;
+        }
+
+        public boolean isGeometryChanged()
+        {
+            return geometryChanged;
+        }
+
+        public void reset()
+        {
+            done = false;
+            geometryChanged = false;
+        }
+    }
+}
diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TWDDatumConverter.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TWDDatumConverter.java
index aae577e..e208caf 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TWDDatumConverter.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/TWDDatumConverter.java
@@ -1,5 +1,7 @@
 package com.ximple.eofms.util;
 
+import com.vividsolutions.jts.geom.Coordinate;
+
 /**
  * TWDDatumConverter
  * User: Ulysses
@@ -49,7 +51,7 @@
     /*
      * datum convert function
      */
-    void toTWD97(double x, double y, double z)
+    public static Coordinate toTWD97(Coordinate pt)
     {
         double newX, newY, newZ;
         double r, pole, sin_lat, cos_lat;
@@ -57,9 +59,9 @@
         double x1, y1, z1, x2, y2, z2;
         double q, q2, t, t1, s, s1, sum, sin_b, cos_b, sin_p, cos_p;
 
-        lon    = x * DEG_RAD;
-        lat    = y * DEG_RAD;
-        height = z * DEG_RAD;
+        lon    = pt.x * DEG_RAD;
+        lat    = pt.y * DEG_RAD;
+        height = pt.z * DEG_RAD;
 
         if ((lat < -HALF_PI) && (lat > -1.001 * HALF_PI))
         {
@@ -69,7 +71,7 @@
             lat = HALF_PI;
         } else if ((lat < -HALF_PI) || (lat > HALF_PI))
         {
-            return;
+            return null;
         }
 
         if (lon > PI)
@@ -117,7 +119,7 @@
                     newY = lat * RAD_DEG;
                     newZ = -TWD97_B;
 
-                    return;
+                    return new Coordinate(newX, newY, newZ);
                 }
             }
         }
@@ -154,9 +156,10 @@
         newX = lon * RAD_DEG;
         newY = lat * RAD_DEG;
         newZ = height;
+        return new Coordinate(newX, newY, newZ);
     }
 
-    void toTWD67(double x, double y, double z)
+    public static Coordinate toTWD67(Coordinate pt)
     {
         double newX, newY, newZ;
         double r, pole, sin_lat, cos_lat;
@@ -164,9 +167,9 @@
         double x1, y1, z1, x2, y2, z2;
         double q, q2, t, t1, s, s1, sum, sin_b, cos_b, sin_p, cos_p;
 
-        lon    = x * DEG_RAD;
-        lat    = y * DEG_RAD;
-        height = z * DEG_RAD;
+        lon    = pt.x * DEG_RAD;
+        lat    = pt.y * DEG_RAD;
+        height = pt.z * DEG_RAD;
 
         if ((lat < -HALF_PI) && (lat > -1.001 * HALF_PI))
         {
@@ -176,7 +179,7 @@
             lat = HALF_PI;
         } else if ((lat < -HALF_PI) || (lat > HALF_PI))
         {
-            return;
+            return null;
         }
 
         if (lon > PI)
@@ -224,7 +227,7 @@
                     newY = lat * RAD_DEG;
                     newZ = -TWD67_B;
 
-                    return;
+                    return new Coordinate(newX, newY, newZ);
                 }
             }
         }
@@ -261,9 +264,10 @@
         newX = lon * RAD_DEG;
         newY = lat * RAD_DEG;
         newZ = height;
+        return new Coordinate(newX, newY, newZ);
     }
 
-    void toTM2(double a, double ecc, double ecc2, double lat, double lon, double scale, double x, double y)
+    public static void toTM2(double a, double ecc, double ecc2, double lat, double lon, double scale, double x, double y)
     {
         double x0, y0, x1, y1, m0, m1;
         double n, t, c, A;
@@ -289,7 +293,7 @@
                        + (61.0 - 58.0 * t + t * t + 600.0 * c - 330.0 * ecc2) * Math.pow(A, 6.0) / 720.0));
     }
 
-    void fromTM2(double a, double ecc, double ecc2, double lat, double lon, double scale, double x, double y)
+    public static void fromTM2(double a, double ecc, double ecc2, double lat, double lon, double scale, double x, double y)
     {
         double newX, newY;
         double x0, y0, x1, y1, phi, m, m0, mu, e1;
@@ -321,7 +325,7 @@
                        / 72.0)) * RAD_DEG;
     }
 
-    double mercator(double y, double a, double ecc)
+    private static double mercator(double y, double a, double ecc)
     {
         if (y == 0.0)
         {

--
Gitblit v0.0.0-SNAPSHOT