From 383a22332d7df1481e090add1e25406a5a358fd9 Mon Sep 17 00:00:00 2001
From: ?? ? <ulysseskao@ximple.com.tw>
Date: Tue, 13 May 2008 18:27:28 +0800
Subject: [PATCH] update for EOFM-83

---
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateEllipseShapeStrategy.java  |   95 +++++++++++++++
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/EllipseElement.java                        |    2 
 .gitattributes                                                                                    |    2 
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateShapeStrategy.java         |    1 
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateArcLineStringStrategy.java |   94 +++++++++++++++
 xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ComplexChainElement.java                   |   45 +++---
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java   |   85 ++++++++++----
 7 files changed, 276 insertions(+), 48 deletions(-)

diff --git a/.gitattributes b/.gitattributes
index 647c266..cc8cb89 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -45,6 +45,8 @@
 xdgnjobs/ximple-spatialjob/pom.xml svneol=native#text/xml
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/AbstractDispatchableFilter.java svneol=native#text/plain
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/AbstractFLinkageDispatchableFilter.java svneol=native#text/plain
+xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateArcLineStringStrategy.java svneol=native#text/plain
+xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateEllipseShapeStrategy.java svneol=native#text/plain
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateFeatureTypeStrategy.java svneol=native#text/plain
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineStringStrategy.java svneol=native#text/plain
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateLineTextStrategy.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 c4dec54..24ab7b6 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
@@ -146,7 +146,7 @@
 
     public Geometry toGeometry(GeometryFactory factory)
     {
-        ArrayList list = new ArrayList();
+        ArrayList<Geometry> list = new ArrayList<Geometry>();
 
         if (size() == 1)
         {
@@ -154,17 +154,17 @@
 
             if (element instanceof LineStringElement)
             {
-               if( ((LineStringElement) element).getVerticeSize() == 0 || ((LineStringElement) element).getVerticeSize() > 1)
-               {
-                  return ((LineStringElement) element).toGeometry(factory);
-               }
+                if (((LineStringElement) element).getVerticeSize() == 0 || ((LineStringElement) element).getVerticeSize() > 1)
+                {
+                    return ((LineStringElement) element).toGeometry(factory);
+                }
 
             } else if (element instanceof LineElement)
             {
-               if( ((LineElement) element).getVertices().length  == 0 || ((LineElement) element).getVertices().length  > 1)
-               {
-                   return ((LineElement) element).toGeometry(factory);
-               }
+                if (((LineElement) element).getVertices().length == 0 || ((LineElement) element).getVertices().length > 1)
+                {
+                    return ((LineElement) element).toGeometry(factory);
+                }
 
             } else
             {
@@ -177,32 +177,33 @@
             }
         }
 
-        for (ListIterator it = listIterator(); it.hasNext(); )
+        for (ListIterator it = listIterator(); it.hasNext();)
         {
             Element element = (Element) it.next();
 
             if (element instanceof LineStringElement)
             {
-               if( ((LineStringElement) element).getVerticeSize() == 0 || ((LineStringElement) element).getVerticeSize() > 1)
-               {
-                 list.add(((LineStringElement) element).toGeometry(factory));
-               }
+                if (((LineStringElement) element).getVerticeSize() == 0 || ((LineStringElement) element).getVerticeSize() > 1)
+                {
+                    list.add(((LineStringElement) element).toGeometry(factory));
+                }
 
             } else if (element instanceof LineElement)
             {
 
-               if( ((LineElement) element).getVertices().length  == 0 || ((LineElement) element).getVertices().length > 1)
-               {
-                list.add(((LineElement) element).toGeometry(factory));
-               }
-
+                if (((LineElement) element).getVertices().length == 0 || ((LineElement) element).getVertices().length > 1)
+                {
+                    list.add(((LineElement) element).toGeometry(factory));
+                }
+            } else if (element instanceof ArcElement)
+            {
+                list.add(((ArcElement) element).toGeometry(factory));
             }
         }
 
-        Geometry[]         ga   = (Geometry[]) list.toArray(new Geometry[list.size()]);
-        GeometryCollection geos = new GeometryCollection(ga, factory);
+        Geometry[] ga = list.toArray(new Geometry[list.size()]);
 
-        return geos;
+        return new GeometryCollection(ga, factory);
     }
 
     public double getElementSize()
diff --git a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/EllipseElement.java b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/EllipseElement.java
index d176583..b8499fd 100644
--- a/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/EllipseElement.java
+++ b/xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/EllipseElement.java
@@ -114,7 +114,7 @@
         double temp = Math.abs(getStartAngle() - getSweepAngle());
         temp /= 4;
         int pts = (temp < 3) ? 3 : (int) temp;
-        return factory.createLineString(convertToLineString(pts));
+        return factory.createPolygon(factory.createLinearRing(convertToLineString(pts)), null);
     }
 
     private Coordinate[] convertToLineString(int pts)
diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateArcLineStringStrategy.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateArcLineStringStrategy.java
new file mode 100644
index 0000000..db43134
--- /dev/null
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateArcLineStringStrategy.java
@@ -0,0 +1,94 @@
+package com.ximple.eofms.filter;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.geotools.feature.AttributeTypeFactory;
+import org.geotools.feature.Feature;
+import org.geotools.feature.FeatureType;
+import org.geotools.feature.FeatureTypeBuilder;
+import org.geotools.feature.IllegalAttributeException;
+import org.geotools.feature.SchemaException;
+
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.GeometryFactory;
+
+import com.ximple.eofms.jobs.TWD97GeometryConverterDecorator;
+import com.ximple.eofms.util.DefaultColorTable;
+import com.ximple.io.dgn7.ArcElement;
+import com.ximple.io.dgn7.Element;
+import com.ximple.io.dgn7.FrammeAttributeData;
+import com.ximple.io.dgn7.UserAttributeData;
+
+public class CreateArcLineStringStrategy implements CreateFeatureTypeStrategy
+{
+    static final Log logger = LogFactory.getLog(CreateLineStringStrategy.class);
+    GeometryFactory geometryFactory = new GeometryFactory();
+    FeatureTypeBuilder typeBuilder = null;
+    TWD97GeometryConverterDecorator convertDecorator = new TWD97GeometryConverterDecorator();
+
+    public CreateArcLineStringStrategy()
+    {
+    }
+
+    protected FrammeAttributeData getFeatureLinkage(Element element)
+    {
+        if (!element.hasUserAttributeData())
+            return null;
+
+        List<UserAttributeData> usrDatas = element.getUserAttributeData();
+        for (UserAttributeData anUsrData : usrDatas)
+        {
+            if (anUsrData instanceof FrammeAttributeData)
+            {
+                return (FrammeAttributeData) anUsrData;
+            }
+        }
+        return null;
+    }
+
+    public FeatureType createFeatureElement(String featureName) throws SchemaException
+    {
+        if (typeBuilder == null)
+        {
+            typeBuilder = FeatureTypeBuilder.newInstance(featureName);
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("GEOM", Geometry.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("TID", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("OID", Long.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("CID", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("LID", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("LEVEL", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMCOLOR", String.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMWEIGHT", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMSTYLE", Integer.class));
+        }
+        return typeBuilder.getFeatureType();
+    }
+
+    public Feature createFeature(FeatureType featureType, Element element) throws IllegalAttributeException
+    {
+        DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance();
+        FrammeAttributeData fLinkage = getFeatureLinkage(element);
+        if (fLinkage == null) return null;
+        if (element instanceof ArcElement)
+        {
+            ArcElement lineStringElement = (ArcElement) element;
+            convertDecorator.setConverter(lineStringElement);
+            Feature feature = featureType.create(new Object[]{
+                    convertDecorator.toGeometry(geometryFactory),
+                    (int) fLinkage.getFsc(),
+                    (long) fLinkage.getUfid(),
+                    (int) fLinkage.getComponentID(),
+                    0,
+                    lineStringElement.getLevelIndex(),
+                    colorTable.getColorCode(lineStringElement.getColorIndex()),
+                    lineStringElement.getWeight(),
+                    lineStringElement.getLineStyle()
+            });
+            return feature;
+        }
+        return null;
+    }
+}
+
diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateEllipseShapeStrategy.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateEllipseShapeStrategy.java
new file mode 100644
index 0000000..143ab63
--- /dev/null
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateEllipseShapeStrategy.java
@@ -0,0 +1,95 @@
+package com.ximple.eofms.filter;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.geotools.feature.AttributeTypeFactory;
+import org.geotools.feature.Feature;
+import org.geotools.feature.FeatureType;
+import org.geotools.feature.FeatureTypeBuilder;
+import org.geotools.feature.IllegalAttributeException;
+import org.geotools.feature.SchemaException;
+
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.GeometryFactory;
+
+import com.ximple.eofms.jobs.TWD97GeometryConverterDecorator;
+import com.ximple.eofms.util.DefaultColorTable;
+import com.ximple.io.dgn7.Element;
+import com.ximple.io.dgn7.EllipseElement;
+import com.ximple.io.dgn7.FrammeAttributeData;
+import com.ximple.io.dgn7.UserAttributeData;
+
+public class CreateEllipseShapeStrategy implements CreateFeatureTypeStrategy
+{
+    static final Log logger = LogFactory.getLog(CreateShapeStrategy.class);
+    GeometryFactory geometryFactory = new GeometryFactory();
+    FeatureTypeBuilder typeBuilder = null;
+    TWD97GeometryConverterDecorator convertDecorator = new TWD97GeometryConverterDecorator();
+
+    public CreateEllipseShapeStrategy()
+    {
+    }
+
+    protected FrammeAttributeData getFeatureLinkage(Element element)
+    {
+        if (!element.hasUserAttributeData())
+            return null;
+
+        List<UserAttributeData> usrDatas = element.getUserAttributeData();
+        for (UserAttributeData anUsrData : usrDatas)
+        {
+            if (anUsrData instanceof FrammeAttributeData)
+            {
+                return (FrammeAttributeData) anUsrData;
+            }
+        }
+        return null;
+    }
+
+    public FeatureType createFeatureElement(String featureName) throws SchemaException
+    {
+        if (typeBuilder == null)
+        {
+            typeBuilder = FeatureTypeBuilder.newInstance(featureName);
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("GEOM", Geometry.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("TID", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("OID", Long.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("CID", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("LID", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("LEVEL", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMCOLOR", String.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMWEIGHT", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMSTYLE", Integer.class));
+        }
+        return typeBuilder.getFeatureType();
+    }
+
+    public Feature createFeature(FeatureType featureType, Element element) throws IllegalAttributeException
+    {
+        DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance();
+        FrammeAttributeData fLinkage = getFeatureLinkage(element);
+        if (fLinkage == null) return null;
+        if (element instanceof EllipseElement)
+        {
+            EllipseElement shapeElement = (EllipseElement) element;
+            convertDecorator.setConverter(shapeElement);
+            Feature feature = featureType.create(new Object[]{
+                    convertDecorator.toGeometry(geometryFactory),
+                    (int) fLinkage.getFsc(),
+                    (long) fLinkage.getUfid(),
+                    (int) fLinkage.getComponentID(),
+                    0,
+                    shapeElement.getLevelIndex(),
+                    colorTable.getColorCode(shapeElement.getColorIndex()),
+                    shapeElement.getWeight(),
+                    shapeElement.getLineStyle()
+            });
+            return feature;
+        }
+        return null;
+    }
+}
+
+
diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateShapeStrategy.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateShapeStrategy.java
index 427442b..b286d49 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateShapeStrategy.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateShapeStrategy.java
@@ -108,4 +108,3 @@
         return null;
     }
 }
-
diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java
index fef0b39..6062b40 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java
@@ -36,6 +36,8 @@
 import com.ximple.io.dgn7.ShapeElement;
 import com.ximple.io.dgn7.TextElement;
 import com.ximple.io.dgn7.UserAttributeData;
+import com.ximple.io.dgn7.ArcElement;
+import com.ximple.io.dgn7.EllipseElement;
 
 public class GeneralDgnConvertJobContext extends AbstractDgnFileJobContext
 {
@@ -82,6 +84,11 @@
                     logger.info("cannot craete feature." + element.toString() + "'" +
                             ((LineStringElement) element).getVerticeSize() + "'" +
                             ((LineStringElement) element).getStartPoint());
+                else if (element instanceof ArcElement)
+                    logger.info("cannot craete feature." + element.toString() + "'" +
+                            ((ArcElement) element).getOrigin().toString() + "'" +
+                            ((ArcElement) element).getRotationAngle());
+
                 return;
             }
 
@@ -244,6 +251,19 @@
         return typeBuilder.getFeatureType();
     }
 
+    public FeatureType createEllipseFeatureElement(String featureName) throws SchemaException
+    {
+        if (typeBuilder == null)
+        {
+            typeBuilder = FeatureTypeBuilder.newInstance(featureName);
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("GEOM", Geometry.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMCOLOR", String.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMWEIGHT", Integer.class));
+            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMSTYLE", Integer.class));
+        }
+        return typeBuilder.getFeatureType();
+    }
+
     public Feature createFeature(FeatureType featureType, Element element) throws IllegalAttributeException
     {
         DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance();
@@ -313,21 +333,32 @@
                         line.getLineStyle()
                 });
             return null;
-            /*
-            } else if (element instanceof ArcElement)
-            {
-                ArcElement arcElement = (ArcElement) element;
-                convertDecorator.setConverter(arcElement);
-                Geometry geom = convertDecorator.toGeometry(geometryFactory);
-                if (geom != null)
-                    return featureType.create(new Object[]{
-                            geom,
-                            colorTable.getColorCode(arcElement.getColorIndex()),
-                            arcElement.getWeight(),
-                            arcElement.getLineStyle()
-                    });
-                return null;
-            */
+        } else if (element instanceof ArcElement)
+        {
+            ArcElement arcElement = (ArcElement) element;
+            convertDecorator.setConverter(arcElement);
+            Geometry geom = convertDecorator.toGeometry(geometryFactory);
+            if (geom != null)
+                return featureType.create(new Object[]{
+                        geom,
+                        colorTable.getColorCode(arcElement.getColorIndex()),
+                        arcElement.getWeight(),
+                        arcElement.getLineStyle()
+                });
+            return null;
+        } else if (element instanceof EllipseElement)
+        {
+            EllipseElement arcElement = (EllipseElement) element;
+            convertDecorator.setConverter(arcElement);
+            Geometry geom = convertDecorator.toGeometry(geometryFactory);
+            if (geom != null)
+                return featureType.create(new Object[]{
+                        geom,
+                        colorTable.getColorCode(arcElement.getColorIndex()),
+                        arcElement.getWeight(),
+                        arcElement.getLineStyle()
+                });
+            return null;
         }
         return null;
     }
@@ -382,16 +413,22 @@
                 featureTypes.put(typeName, createLineFeatureElement(typeName));
             }
             return featureTypes.get(typeName);
-            /*
-            } else if (element instanceof ArcElement)
+        } else if (element instanceof ArcElement)
+        {
+            typeName = getFeatureBaseName() + "A";
+            if (!featureTypes.containsKey(typeName))
             {
-                typeName = getFeatureBaseName() + "A";
-                if (!featureTypes.containsKey(typeName))
-                {
-                    featureTypes.put(typeName, createArcFeatureElement(typeName));
-                }
-                return featureTypes.get(typeName);
-            */
+                featureTypes.put(typeName, createArcFeatureElement(typeName));
+            }
+            return featureTypes.get(typeName);
+        } else if (element instanceof EllipseElement)
+        {
+            typeName = getFeatureBaseName() + "R";
+            if (!featureTypes.containsKey(typeName))
+            {
+                featureTypes.put(typeName, createEllipseFeatureElement(typeName));
+            }
+            return featureTypes.get(typeName);
         }
 
         return null;

--
Gitblit v0.0.0-SNAPSHOT