xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/ShapeElement.java
@@ -2,6 +2,9 @@ //~--- non-JDK imports -------------------------------------------------------- import org.apache.log4j.Logger; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.LinearRing; @@ -15,6 +18,8 @@ */ public class ShapeElement extends LineStringElement implements GeometryConverter { static final Logger logger = Logger.getLogger(ShapeElement.class); public ShapeElement(short[] raw) { super(raw); @@ -22,10 +27,15 @@ public Geometry toGeometry(GeometryFactory factory) { try { LinearRing ring = factory.createLinearRing(this.getVertices()); return factory.createPolygon(ring, null); // return factory.createPolygon(ring, null); } catch (IllegalArgumentException e) { logger.warn(e.getMessage(), e); return null; } } public static class ElementHandler extends Element.ElementHandler xdgnjobs/ximple-jobcarrier/src/main/resources/quartz_jobs.xml
@@ -46,7 +46,7 @@ </entry> <entry> <key>CONVERTDB</key> <value>true</value> <value>false</value> </entry> <entry> <key>CONVERTFILE</key> xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/AbstractOracleDatabaseJob.java
@@ -211,4 +211,36 @@ { return _testCount; } public String getConvertDB() { return _convertDB; } public void setConvertDB(String convertDB) { _convertDB = convertDB; } public String getConvertFile() { return _convertFile; } public void setConvertFile(String convertFile) { _convertFile = convertFile; } public boolean checkConvertDB() { return _convertDB != null && !_convertDB.equalsIgnoreCase("false") && !_convertDB.equalsIgnoreCase("no") && !_convertDB.equalsIgnoreCase("0"); } public boolean checkConvertFile() { return _convertFile != null && !_convertFile.equalsIgnoreCase("false") && !_convertFile.equalsIgnoreCase("no") && !_convertFile.equalsIgnoreCase("0"); } } 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) { 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,8 +246,11 @@ { TextElement textElement = (TextElement) element; convertDecorator.setConverter(textElement); Feature feature = featureType.create(new Object[]{ convertDecorator.toGeometry(geometryFactory), Geometry geom = convertDecorator.toGeometry(geometryFactory); if (geom != null) { return featureType.create(new Object[]{ geom, colorTable.getColorCode(textElement.getColorIndex()), textElement.getFontIndex(), textElement.getJustification(), @@ -232,7 +259,29 @@ textElement.getRotationAngle(), textElement.getText() }); return feature; } 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), Geometry geom = convertDecorator.toGeometry(geometryFactory); if (geom != null) return featureType.create(new Object[]{ geom, colorTable.getColorCode(line.getColorIndex()), line.getWeight(), line.getLineStyle() }); return feature; 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; xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/IndexDgnConvertJobContext.java
@@ -121,7 +121,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; @@ -176,7 +176,7 @@ { outPath.mkdir(); } dataOut = getDataPath() + SHPOUTPATH; dataOut = outPath.toString(); } return dataOut; } xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java
@@ -95,7 +95,12 @@ try { logger.info("-- step:clearOutputDirectory --"); clearOutputDirectory(); boolean bFirst = true; if (checkConvertDB()) { logger.info("-- step:convertOracleDB --"); for (String orgSchema : _orgSchema) { OracleConvertJobContext jobContext = (OracleConvertJobContext) prepareJobContext(_filterPath); @@ -117,9 +122,15 @@ //close all open filewriter instance jobContext.closeFeatureWrite(); } } if (checkConvertFile()) { logger.info("-- step:convertIndexDesignFile --"); convertIndexDesignFile(context); logger.info("-- step:convertOtherDesignFile --"); convertOtherDesignFile(context); } } catch (SQLException e) { logger.warn(e.getMessage(), e); @@ -129,10 +140,12 @@ logger.warn(ex.getMessage(), ex); throw new JobExecutionException("IO error. " + ex.getMessage(), ex); } logger.info(jobName + " end at " + new Date()); } /** * Connectivity½Æ»s¤@Óª©¥»¡A¦b¬d¸ß¹q¬y¤è¦V®É¥Î¨Ó¤ñ¹ïOMS¸ê®Æ®wªº¹q¾¹³s±µ©Ê(Connectivity) * * @param jobContext * @throws SQLException */ @@ -444,6 +457,7 @@ /** * °õ¦æÂà´«¯Á¤Þ¹ÏÀɪº¤u§@ * * @param context ¤u§@°õ¦æÀô¹Ò */ private void convertIndexDesignFile(JobExecutionContext context) throws JobExecutionException @@ -471,10 +485,11 @@ for (File dgnFile : dgnFiles) { IndexDgnConvertJobContext convertContext = new IndexDgnConvertJobContext(getDataPath()); logger.debug("--- start dgnfile-" + dgnFile.toString() + " ---"); try { convertContext.setExecutionContext(context); String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.pathSeparator); String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator); convertContext.setFilename(dgnPaths[dgnPaths.length - 1]); FileInputStream fs = new FileInputStream(dgnFile); @@ -485,6 +500,7 @@ scanIndexDgnElement(convertContext); convertContext.commitTransaction(); System.gc(); } catch (FileNotFoundException e) { convertContext.rollbackTransaction(); @@ -568,6 +584,7 @@ /** * °õ¦æÂà´«¨ä¥L³]p¹ÏÀɪº¤u§@ * * @param context */ private void convertOtherDesignFile(JobExecutionContext context) throws JobExecutionException @@ -595,10 +612,11 @@ for (File dgnFile : dgnFiles) { GeneralDgnConvertJobContext convertContext = new GeneralDgnConvertJobContext(getDataPath()); logger.info("--- start dgnfile-" + dgnFile.toString() + " ---"); try { convertContext.setExecutionContext(context); String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.pathSeparator); String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator); convertContext.setFilename(dgnPaths[dgnPaths.length - 1]); FileInputStream fs = new FileInputStream(dgnFile); @@ -683,9 +701,58 @@ private void processOtherElement(Element element, GeneralDgnConvertJobContext convertContext) throws IllegalAttributeException, SchemaException { if (element instanceof TextElement) { convertContext.putFeatureCollection(element); } private void clearOutputDirectory() { File outDataPath = new File(getDataPath(), OracleConvertJobContext.SHPOUTPATH); if (outDataPath.exists() && outDataPath.isDirectory()) { deleteFilesInPath(outDataPath); } outDataPath = new File(getDataPath(), IndexDgnConvertJobContext.SHPOUTPATH); if (outDataPath.exists() && outDataPath.isDirectory()) { deleteFilesInPath(outDataPath); } outDataPath = new File(getDataPath(), GeneralDgnConvertJobContext.SHPOUTPATH); if (outDataPath.exists() && outDataPath.isDirectory()) { deleteFilesInPath(outDataPath); } } private void deleteFilesInPath(File outDataPath) { deleteFilesInPath(outDataPath, true); } private void deleteFilesInPath(File outDataPath, boolean removeSubDir) { if (!outDataPath.isDirectory()) { return; } File[] files = outDataPath.listFiles(); for (File file : files) { if (file.isFile()) { if (!file.delete()) { logger.info("Cannot delete file-" + file.toString()); } } else if (file.isDirectory()) { deleteFilesInPath(file, removeSubDir); if (removeSubDir) { if (file.delete()) { logger.info("Cannot delete dir-" + file.toString()); } } } } } } xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertJobContext.java
@@ -42,7 +42,7 @@ static Log logger = LogFactory.getLog(OracleConvertJobContext.class); static final LoggerFacade sLogger = new CommonsLoggingLogger(logger); private static final String SHPOUTPATH = "shpout"; static final String SHPOUTPATH = "shpout"; static { @@ -183,7 +183,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 = null; xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/TWD97GeometryConverterDecorator.java
@@ -36,6 +36,7 @@ coordinatesFilter.reset(); Geometry geom = converter.toGeometry(factory); if (geom == null) return null; geom.apply(coordinatesFilter); return geom; }