forked from geodmms/xdgnjobs

?? ?
2008-05-07 10445847ed1bfa5755127e828b603a3cdd49c5e3
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java
@@ -29,10 +29,12 @@
import com.vividsolutions.jts.geom.GeometryFactory;
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.LineElement;
import com.ximple.io.dgn7.LineStringElement;
import com.ximple.io.dgn7.ShapeElement;
import com.ximple.io.dgn7.TextElement;
import com.ximple.io.dgn7.UserAttributeData;
@@ -65,13 +67,22 @@
    public void putFeatureCollection(Element element) throws IllegalAttributeException, SchemaException
    {
        FeatureType ft = lookupFeatureType(element);
        if (ft == null)
        if (ft != null)
        {
            Feature feature = createFeature(ft, element);
            if (feature == null)
            {
                logger.info("cannot craete feature." + element.toString() + "'" +
                        ((TextElement) element).getText() + "'");
                if (element instanceof TextElement)
                    logger.info("cannot craete feature." + element.toString() + "'" +
                            ((TextElement) element).getText() + "'");
                else if (element instanceof ShapeElement)
                    logger.info("cannot craete feature." + element.toString() + "'" +
                            ((ShapeElement) element).getVerticeSize() + "'" +
                            ((ShapeElement) element).getStartPoint());
                else if (element instanceof LineStringElement)
                    logger.info("cannot craete feature." + element.toString() + "'" +
                            ((LineStringElement) element).getVerticeSize() + "'" +
                            ((LineStringElement) element).getStartPoint());
                return;
            }
@@ -126,7 +137,7 @@
            while (it.hasNext())
            {
                FeatureType featureType = (FeatureType) it.next();
                File sfile = new File(getDataOutPath() + "\\" + featureType.getTypeName());
                File sfile = new File(getDataOutPath() + File.separator + featureType.getTypeName());
                logger.debug("Begin Save shapefile:" + sfile.toURI());
                FeatureWriter writer;
@@ -180,7 +191,7 @@
            {
                outPath.mkdir();
            }
            dataOut = getDataPath() + SHPOUTPATH;
            dataOut = outPath.toString();
        }
        return dataOut;
    }
@@ -215,6 +226,19 @@
        return typeBuilder.getFeatureType();
    }
    public FeatureType createArcFeatureElement(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();
@@ -222,17 +246,42 @@
        {
            TextElement textElement = (TextElement) element;
            convertDecorator.setConverter(textElement);
            Feature feature = featureType.create(new Object[]{
                    convertDecorator.toGeometry(geometryFactory),
                    colorTable.getColorCode(textElement.getColorIndex()),
                    textElement.getFontIndex(),
                    textElement.getJustification(),
                    textElement.getTextHeight(),
                    textElement.getTextWidth(),
                    textElement.getRotationAngle(),
                    textElement.getText()
            });
            return feature;
            Geometry geom = convertDecorator.toGeometry(geometryFactory);
            if (geom != null)
            {
                return featureType.create(new Object[]{
                        geom,
                        colorTable.getColorCode(textElement.getColorIndex()),
                        textElement.getFontIndex(),
                        textElement.getJustification(),
                        textElement.getTextHeight(),
                        textElement.getTextWidth(),
                        textElement.getRotationAngle(),
                        textElement.getText()
                });
            } else
            {
                logger.info("geometry is null." + element.toString());
            }
            return null;
        } else if (element instanceof ShapeElement)
        {
            ShapeElement shapeElement = (ShapeElement) element;
            convertDecorator.setConverter(shapeElement);
            Geometry geom = convertDecorator.toGeometry(geometryFactory);
            if (geom != null)
            {
                return featureType.create(new Object[]{
                        geom,
                        colorTable.getColorCode(shapeElement.getColorIndex()),
                        shapeElement.getWeight(),
                        shapeElement.getLineStyle()
                });
            } else
            {
                logger.info("geometry is null." + element.toString());
            }
            return null;
        } else if (element instanceof LineStringElement)
        {
            LineStringElement linestring = (LineStringElement) element;
@@ -248,13 +297,30 @@
        {
            LineElement line = (LineElement) element;
            convertDecorator.setConverter(line);
            Feature feature = featureType.create(new Object[]{
                    convertDecorator.toGeometry(geometryFactory),
                    colorTable.getColorCode(line.getColorIndex()),
                    line.getWeight(),
                    line.getLineStyle()
            });
            return feature;
            Geometry geom = convertDecorator.toGeometry(geometryFactory);
            if (geom != null)
                return featureType.create(new Object[]{
                        geom,
                        colorTable.getColorCode(line.getColorIndex()),
                        line.getWeight(),
                        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;
        */
        }
        return null;
    }
@@ -273,6 +339,7 @@
        }
        return featureBaseName;
    }
    private FeatureType lookupFeatureType(Element element) throws SchemaException, IllegalAttributeException
    {
        String typeName;
@@ -282,6 +349,14 @@
            if (!featureTypes.containsKey(typeName))
            {
                featureTypes.put(typeName, createPointFeatureElement(typeName));
            }
            return featureTypes.get(typeName);
        } else if (element instanceof ShapeElement)
        {
            typeName = getFeatureBaseName() + "R";
            if (!featureTypes.containsKey(typeName))
            {
                featureTypes.put(typeName, createLineFeatureElement(typeName));
            }
            return featureTypes.get(typeName);
        } else if (element instanceof LineStringElement)
@@ -300,6 +375,16 @@
                featureTypes.put(typeName, createLineFeatureElement(typeName));
            }
            return featureTypes.get(typeName);
        /*
        } else if (element instanceof ArcElement)
        {
            typeName = getFeatureBaseName() + "A";
            if (!featureTypes.containsKey(typeName))
            {
                featureTypes.put(typeName, createArcFeatureElement(typeName));
            }
            return featureTypes.get(typeName);
        */
        }
        return null;