From 10445847ed1bfa5755127e828b603a3cdd49c5e3 Mon Sep 17 00:00:00 2001 From: ?? ? <ulysseskao@ximple.com.tw> Date: Wed, 07 May 2008 12:58:22 +0800 Subject: [PATCH] update for EOFM-75 --- xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/GeneralDgnConvertJobContext.java | 131 ++++++++++++++++++++++++++++++++++++------- 1 files changed, 108 insertions(+), 23 deletions(-) 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 715b4f2..0e1fc7a 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 @@ -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; -- Gitblit v0.0.0-SNAPSHOT