| | |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | import java.nio.channels.FileChannel; |
| | | import java.nio.charset.Charset; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.SimpleFeature; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | import org.geotools.feature.FeatureCollection; |
| | | import org.geotools.feature.FeatureCollections; |
| | | import org.geotools.data.FeatureWriter; |
| | | import org.geotools.data.Transaction; |
| | | import org.geotools.data.FeatureStore; |
| | | import org.geotools.data.shapefile.ShapefileDataStore; |
| | | import org.xml.sax.SAXException; |
| | | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | |
| | | import com.ximple.eofms.filter.AbstractFLinkageDispatchableFilter; |
| | | import com.ximple.eofms.filter.ElementDispatcher; |
| | | import com.ximple.eofms.jobs.context.postgis.FeatureDgnConvertPostGISJobContext; |
| | | import com.ximple.eofms.util.FeatureTypeBuilderUtil; |
| | | import com.ximple.io.dgn7.ComplexElement; |
| | | import com.ximple.io.dgn7.Dgn7fileException; |
| | | import com.ximple.io.dgn7.Dgn7fileReader; |
| | |
| | | static final GeometryFactory geometryFactory = new GeometryFactory(); |
| | | |
| | | static final boolean isCompactMode = true; |
| | | static final boolean postOutMode = true; |
| | | |
| | | protected static final String ROOTDATAPATH = "DATAPATH"; |
| | | |
| | | protected static final String DEFAULT_DATAPATH = "G:\\Temp\\JobData\\tctpc"; |
| | | protected static final String DEFAULT_DGNINPATH = "elmin"; |
| | | protected static final String DEFAULT_DGNOUTPATH = "elmout"; |
| | | protected static final String DEFAULT_SHPOUTPATH = "out"; |
| | | |
| | | private HashMap<String, String> dataConfig; |
| | | private ElementDispatcher elementDispatcher; |
| | |
| | | private void initializeDataConfig() |
| | | { |
| | | dataConfig = new HashMap<String, String>(); |
| | | dataConfig.put("DATAPATH", "G:\\Temp\\JobData\\tctpc\\elmout"); |
| | | dataConfig.put(ROOTDATAPATH, DEFAULT_DATAPATH); |
| | | |
| | | elementDispatcher = createElementDispatcher(); |
| | | |
| | | FeatureTypeBuilderUtil.setNotAllowNull(true); |
| | | } |
| | | |
| | | private ElementDispatcher createElementDispatcher() |
| | |
| | | |
| | | public void run() |
| | | { |
| | | File dataDir = new File(dataConfig.get("DATAPATH")); |
| | | File rootDir = new File(dataConfig.get(ROOTDATAPATH)); |
| | | File dataDir = new File(rootDir, DEFAULT_DGNINPATH); |
| | | if ((!dataDir.exists()) || (!dataDir.isDirectory())) |
| | | { |
| | | return; |
| | |
| | | } |
| | | } |
| | | |
| | | postProcessFeatureContext(); |
| | | if (postOutMode) |
| | | { |
| | | try |
| | | { |
| | | postProcessFeatureContext(); |
| | | } catch (IOException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | } catch (IllegalAttributeException e) |
| | | { |
| | | logger.warn(e.getMessage(), e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void processFeatureElement(Element element) |
| | |
| | | } |
| | | |
| | | // §PÂ_¬O§_²Å©M±ø¥ó |
| | | Feature feature = elementDispatcher.execute(element); |
| | | Feature feature = elementDispatcher.execute(element, false); |
| | | if (feature == null) |
| | | { |
| | | FrammeAttributeData linkage = |
| | |
| | | { |
| | | } |
| | | |
| | | private void postProcessFeatureContext() |
| | | private void postProcessFeatureContext() throws IOException, IllegalAttributeException |
| | | { |
| | | if (featuresContext.size() == 0) return; |
| | | for (Object key : featuresContext.keySet()) |
| | | { |
| | | FeatureType featureType = (FeatureType) key; |
| | | List elements = (List) featuresContext.get(key); |
| | | |
| | | FeatureCollection features = FeatureCollections.newCollection(); |
| | | features.addAll(elements); |
| | | createFeatureStore(featureType).addFeatures(features); |
| | | |
| | | FeatureWriter writer = createFeatureWriter(featureType); |
| | | for (Object v : elements) |
| | | { |
| | | Feature feature1 = (Feature) v; |
| | | Object[] attrs = feature1.getAttributes(null); |
| | | if (attrs != null) |
| | | ((SimpleFeature) writer.next()).setAttributes(attrs); |
| | | |
| | | } |
| | | writer.close(); |
| | | } |
| | | } |
| | | |
| | | private FeatureStore createFeatureStore(FeatureType featureType) throws IOException |
| | | { |
| | | File sfile = new File(getDataOutPath() + File.separator + featureType.getTypeName()); |
| | | |
| | | ShapefileDataStore shapefileDataStore = null; |
| | | boolean existFile = sfile.exists(); |
| | | |
| | | shapefileDataStore = new ShapefileDataStore(sfile.toURI().toURL(), |
| | | true, Charset.forName("UTF-8")); |
| | | |
| | | if (!existFile) |
| | | { |
| | | shapefileDataStore.createSchema(featureType); |
| | | } |
| | | return (FeatureStore) shapefileDataStore.getFeatureSource(featureType.getTypeName()); |
| | | } |
| | | private FeatureWriter createFeatureWriter(FeatureType featureType) throws IOException |
| | | { |
| | | File sfile = new File(getDataOutPath() + File.separator + featureType.getTypeName()); |
| | | |
| | | ShapefileDataStore shapefileDataStore = null; |
| | | boolean existFile = sfile.exists(); |
| | | |
| | | shapefileDataStore = new ShapefileDataStore(sfile.toURI().toURL(), |
| | | true, Charset.forName("UTF-8")); |
| | | |
| | | FeatureWriter writer; |
| | | if (!existFile) |
| | | { |
| | | shapefileDataStore.createSchema(featureType); |
| | | writer = shapefileDataStore.getFeatureWriter(featureType.getTypeName(), Transaction.AUTO_COMMIT); |
| | | } else { |
| | | writer = shapefileDataStore.getFeatureWriterAppend(featureType.getTypeName(), Transaction.AUTO_COMMIT); |
| | | } |
| | | |
| | | return writer; |
| | | } |
| | | |
| | | public String getDataOutPath() |
| | | { |
| | | File rootDir = new File(dataConfig.get(ROOTDATAPATH)); |
| | | File dataDir = new File(rootDir, DEFAULT_SHPOUTPATH); |
| | | return dataDir.toString(); |
| | | } |
| | | |
| | | } |