package com.ximple.eofms.jobs.context.postgis; import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.transaction.util.CommonsLoggingLogger; import org.apache.commons.transaction.util.LoggerFacade; import org.geotools.data.DataStore; import org.geotools.data.Transaction; import org.geotools.data.jdbc.JDBCUtils; import org.geotools.feature.IllegalAttributeException; import org.geotools.feature.SchemaException; import org.geotools.feature.simple.SimpleFeatureBuilder; import org.geotools.feature.simple.SimpleFeatureTypeBuilder; import org.geotools.feature.type.FeatureTypeImpl; import org.geotools.geometry.jts.JTSFactoryFinder; import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; import org.postgresql.util.PSQLException; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Envelope; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.Polygon; import com.ximple.eofms.util.DefaultColorTable; import com.ximple.eofms.util.FeatureTypeBuilderUtil; import com.ximple.eofms.util.GeometryConverterDecorator; import com.ximple.eofms.util.TPCLIDConverter; import com.ximple.eofms.util.TWDDatumConverter; import com.ximple.io.dgn7.Element; import com.ximple.io.dgn7.FrammeAttributeData; import com.ximple.io.dgn7.ShapeElement; import com.ximple.io.dgn7.TextElement; import com.ximple.io.dgn7.UserAttributeData; public class IndexDgnConvertPostGISJobContext extends AbstractDgnToPostGISJobContext { static final Log logger = LogFactory.getLog(IndexDgnConvertPostGISJobContext.class); static final LoggerFacade sLogger = new CommonsLoggingLogger(logger); static final GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null); private HashMap> txFeaturesContext = new HashMap>(); private HashMap typesMapping = new HashMap(); private SimpleFeatureType featureType1 = null; private SimpleFeatureType featureType2 = null; private SimpleFeatureType featureType3 = null; private boolean dropTableMode = true; private int accumulate = 0; public IndexDgnConvertPostGISJobContext(String dataPath, DataStore targetDataStore, String targetSchema, boolean profileMode, boolean useTransform) { super(dataPath, targetDataStore, targetSchema, profileMode, useTransform); } public void putFeatureCollection(Element element) throws IllegalAttributeException, SchemaException { if ((!(element instanceof TextElement)) && (!(element instanceof ShapeElement))) { return; } if ((element instanceof TextElement)) { putTextFeatureCollection((TextElement) element); } if ((element instanceof ShapeElement)) { putShapeFeatureCollection((ShapeElement) element); } } protected void putTextFeatureCollection(TextElement element) throws SchemaException, IllegalAttributeException { SimpleFeature feature = createFeature(element); if (feature == null) { logger.info("cannot craete feature. " + element.toString() + "'" + element.getText() + "'"); return; } if (!txFeaturesContext.containsKey(feature.getFeatureType())) { txFeaturesContext.put(feature.getFeatureType(), new ArrayList()); } ArrayList arrayList = txFeaturesContext.get(feature.getFeatureType()); arrayList.add(feature); feature = createFeature2(element); if (feature == null) { logger.info("cannot craete feature2. " + element.toString() + "'" + element.getText() + "'"); return; } if (!txFeaturesContext.containsKey(feature.getFeatureType())) { txFeaturesContext.put(feature.getFeatureType(), new ArrayList()); } arrayList = txFeaturesContext.get(feature.getFeatureType()); arrayList.add(feature); SimpleFeature[] features = createFeature3(element); if (features == null) { logger.info("cannot craete feature3." + element.toString() + "'" + element.getText() + "'"); return; } if (!txFeaturesContext.containsKey(features[0].getFeatureType())) { txFeaturesContext.put(features[0].getFeatureType(), new ArrayList()); } arrayList = txFeaturesContext.get(features[0].getFeatureType()); arrayList.addAll(Arrays.asList(features)); accumulate++; if (accumulate > BATCHSIZE) { commitTransaction(); } } protected void putShapeFeatureCollection(ShapeElement element) throws SchemaException, IllegalAttributeException { SimpleFeature feature = createFeature(element); if (feature == null) { Polygon polygon = (Polygon) element.toGeometry(geometryFactory); if (polygon == null) { logger.info("cannot craete feature. " + element.toString() + "'" + "linear is null" + "'"); } else { Coordinate pt = polygon.getEnvelopeInternal().centre(); String id = TPCLIDConverter.CoordinateToTpclId(pt); logger.info("cannot craete feature. " + element.toString() + "'" + id + "'- from pt=" + pt); } return; } if (!txFeaturesContext.containsKey(feature.getFeatureType())) { txFeaturesContext.put(feature.getFeatureType(), new ArrayList()); } ArrayList arrayList = txFeaturesContext.get(feature.getFeatureType()); arrayList.add(feature); feature = createFeature2(element); if (feature == null) { Polygon polygon = (Polygon) element.toGeometry(geometryFactory); if (polygon == null) { logger.info("cannot craete feature2." + element.toString() + "'" + "linear is null" + "'"); } else { Coordinate pt = polygon.getEnvelopeInternal().centre(); String id = TPCLIDConverter.CoordinateToTpclId(pt); logger.info("cannot craete feature2." + element.toString() + "'" + id + "'- from pt=" + pt); } return; } if (!txFeaturesContext.containsKey(feature.getFeatureType())) { txFeaturesContext.put(feature.getFeatureType(), new ArrayList()); } arrayList = txFeaturesContext.get(feature.getFeatureType()); arrayList.add(feature); SimpleFeature[] features = createFeature3(element); if (features == null) { Polygon polygon = (Polygon) element.toGeometry(geometryFactory); if (polygon == null) { logger.info("cannot craete feature3." + element.toString() + "'" + "linear is null" + "'"); } else { Coordinate pt = polygon.getEnvelopeInternal().centre(); String id = TPCLIDConverter.CoordinateToTpclId(pt); logger.info("cannot craete feature3." + element.toString() + "'" + id + "'- from pt=" + pt); } return; } if (!txFeaturesContext.containsKey(features[0].getFeatureType())) { txFeaturesContext.put(features[0].getFeatureType(), new ArrayList()); } arrayList = txFeaturesContext.get(features[0].getFeatureType()); arrayList.addAll(Arrays.asList(features)); accumulate++; if (accumulate > BATCHSIZE) { commitTransaction(); } } public void startTransaction() { } public void commitTransaction() { if (!txFeaturesContext.isEmpty()) { logger.debug("Transaction size = " + txFeaturesContext.size()); } else { logger.debug("Transaction is empty."); } if (!txFeaturesContext.isEmpty()) { updateDataStore(); } } public void rollbackTransaction() { } private void updateDataStore() { if (isProfileMode()) markUpdateTime(); Iterator it = txFeaturesContext.keySet().iterator(); Connection conn = null; try { conn = getConnection(); boolean autoCommit = conn.getAutoCommit(); conn.setAutoCommit(false); while (it.hasNext()) { SimpleFeatureType featureType = it.next(); logger.debug("Begin Save PostGIS:" + featureType.getTypeName()); String bindingStmt = makePrepareInsertSql(featureType); ArrayList features = txFeaturesContext.get(featureType); PreparedStatement pstmt = conn.prepareStatement(bindingStmt); for (SimpleFeature feature : features) { // currentStmt = feature; // Statement stmt = conn.createStatement(); try { // stmt.execute(feature); bindFeatureParameters(pstmt, feature); // pstmt.execute(); pstmt.addBatch(); } catch (PSQLException e) { if (bindingStmt != null) { logger.error("Execute:" + bindingStmt); } logger.error(e.getServerErrorMessage()); logger.error(e.getMessage(), e); /* } finally { stmt.close(); */ } } /* if ((i % BATCHSIZE) != 0) { stmt.executeBatch(); } stmt.close(); */ int[] numUpdates = pstmt.executeBatch(); for (int i = 0; i < numUpdates.length; i++) { if (numUpdates[i] == -2) logger.warn("Execution " + i + ": unknown number of rows updated"); } conn.commit(); pstmt.close(); features.clear(); logger.debug("End Save PostGIS:" + featureType.getTypeName()); } accumulate = 0; conn.setAutoCommit(autoCommit); JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); } catch (PSQLException e) { JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e); logger.error(e.getServerErrorMessage()); logger.error(e.getMessage(), e); } catch (SQLException e) { JDBCUtils.close(conn, Transaction.AUTO_COMMIT, e); logger.error(e.getMessage(), e); Exception nextE = e.getNextException(); if (nextE != null) { logger.error("getNextException:" + nextE.getMessage(), nextE); } } finally { if (isProfileMode()) this.accumulateUpdateTime(); } } public void closeFeatureWriter() { txFeaturesContext.clear(); /* for (FeatureWriter featureWriter : this.featuresWriterContext.values()) { featureWriter.close(); } this.featuresWriterContext.clear(); */ } public void createFeatureElement(String featureName) throws SchemaException { if (featureType1 == null) { Connection conn = null; SimpleFeatureTypeBuilder typeBuilder1 = FeatureTypeBuilderUtil.createNormalIndexFeatureTypeBuilder(featureName); featureType1 = typeBuilder1.buildFeatureType(); String currentSQL = null; if (isExistFeature(featureType1)) { try { conn = getConnection(); if (dropTableMode) { try { dropGeometryColumn(conn, getTargetSchema(), featureName, (featureType1).getGeometryDescriptor().getLocalName()); } catch (PSQLException e) { logger.debug(e.getMessage(), e); } try { dropTable(conn, featureName); } catch (PSQLException e) { logger.debug(e.getMessage(), e); } ArrayList schemaTexts = createNewSchemaTexts(conn, featureType1); for (String stmtText : schemaTexts) { Statement stmt = conn.createStatement(); currentSQL = stmtText; stmt.execute(stmtText); JDBCUtils.close(stmt); } } else { deleteTable(conn, featureName); } } catch (IOException e) { if (currentSQL != null) logger.warn("executeSQL:" + currentSQL); logger.warn(e.getMessage(), e); } catch (SQLException e) { if (currentSQL != null) logger.warn("executeSQL:" + currentSQL); logger.warn(e.getMessage(), e); } finally { JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); } } else { try { conn = getConnection(); ArrayList schemaTexts = createNewSchemaTexts(conn, featureType1); for (String stmtText : schemaTexts) { Statement stmt = conn.createStatement(); stmt.execute(stmtText); currentSQL = stmtText; JDBCUtils.close(stmt); } } catch (IOException e) { if (currentSQL != null) logger.warn("executeSQL:" + currentSQL); logger.warn(e.getMessage(), e); } catch (SQLException e) { if (currentSQL != null) logger.warn("executeSQL:" + currentSQL); logger.warn(e.getMessage(), e); } finally { JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); } } } } public void createFeatureElement2(String featureName) throws SchemaException { if (featureType2 == null) { Connection conn = null; SimpleFeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createNormalIndexTextFeatureTypeBuilder(featureName); featureType2 = typeBuilder.buildFeatureType(); String currentSQL = null; if (isExistFeature(featureType2)) { try { conn = getConnection(); if (dropTableMode) { dropGeometryColumn(conn, getTargetSchema(), featureName, (featureType2).getGeometryDescriptor().getLocalName()); dropTable(conn, featureName); ArrayList schemaTexts = createNewSchemaTexts(conn, featureType2); for (String stmtText : schemaTexts) { Statement stmt = conn.createStatement(); currentSQL = stmtText; stmt.execute(stmtText); JDBCUtils.close(stmt); } } else { deleteTable(conn, featureName); } } catch (IOException e) { if (currentSQL != null) logger.warn("executeSQL:" + currentSQL); logger.warn(e.getMessage(), e); } catch (SQLException e) { if (currentSQL != null) logger.warn("executeSQL:" + currentSQL); logger.warn(e.getMessage(), e); } finally { JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); } } else { try { conn = getConnection(); ArrayList schemaTexts = createNewSchemaTexts(conn, featureType2); for (String stmtText : schemaTexts) { Statement stmt = conn.createStatement(); currentSQL = stmtText; stmt.execute(stmtText); JDBCUtils.close(stmt); } } catch (IOException e) { if (currentSQL != null) logger.warn("executeSQL:" + currentSQL); logger.warn(e.getMessage(), e); } catch (SQLException e) { if (currentSQL != null) logger.warn("executeSQL:" + currentSQL); logger.warn(e.getMessage(), e); } finally { JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); } } } } public void createFeatureElement3(String featureName) throws SchemaException { if (featureType3 == null) { Connection conn = null; SimpleFeatureTypeBuilder typeBuilder = FeatureTypeBuilderUtil.createNormalIndexFeatureTypeBuilder(featureName); featureType3 = typeBuilder.buildFeatureType(); String currentSQL = null; if (isExistFeature(featureType3)) { try { conn = getConnection(); if (dropTableMode) { try { dropGeometryColumn(conn, getTargetSchema(), featureName, (featureType3).getGeometryDescriptor().getLocalName()); } catch (PSQLException e) { logger.debug(e.getMessage(), e); } try { dropTable(conn, featureName); } catch (PSQLException e) { logger.debug(e.getMessage(), e); } ArrayList schemaTexts = createNewSchemaTexts(conn, featureType3); for (String stmtText : schemaTexts) { Statement stmt = conn.createStatement(); currentSQL = stmtText; stmt.execute(stmtText); JDBCUtils.close(stmt); } } else { deleteTable(conn, featureName); } } catch (IOException e) { if (currentSQL != null) logger.warn("executeSQL:" + currentSQL); logger.warn(e.getMessage(), e); } catch (SQLException e) { if (currentSQL != null) logger.warn("executeSQL:" + currentSQL); logger.warn(e.getMessage(), e); } finally { JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); } } else { try { conn = getConnection(); ArrayList schemaTexts = createNewSchemaTexts(conn, featureType3); for (String stmtText : schemaTexts) { Statement stmt = conn.createStatement(); currentSQL = stmtText; stmt.execute(stmtText); JDBCUtils.close(stmt); } } catch (IOException e) { if (currentSQL != null) logger.warn("executeSQL:" + currentSQL); logger.warn(e.getMessage(), e); } catch (SQLException e) { if (currentSQL != null) logger.warn("executeSQL:" + currentSQL); logger.warn(e.getMessage(), e); } finally { JDBCUtils.close(conn, Transaction.AUTO_COMMIT, null); } } } } public SimpleFeature createFeature(SimpleFeatureType featureType, Element element) throws IllegalAttributeException { DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance(); if (element instanceof TextElement) { TextElement textElement = (TextElement) element; String tpclid = textElement.getText(); if(tpclid.trim().endsWith("")) { return null; } Envelope extent = TPCLIDConverter.convertTpclIdToEnvelope(tpclid); Geometry geom; if (FeatureTypeBuilderUtil.getDefaultFeatureSRID() == 3826) { geom = geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[] { TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMinX(), extent.getMinY())), TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMaxX(), extent.getMinY())), TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMaxX(), extent.getMaxY())), TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMinX(), extent.getMaxY())), TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMinX(), extent.getMinY())), }), null); } else { geom = geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[] { TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMinX(), extent.getMinY())), TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMaxX(), extent.getMinY())), TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMaxX(), extent.getMaxY())), TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMinX(), extent.getMaxY())), TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMinX(), extent.getMinY())), }), null); } return SimpleFeatureBuilder.build(featureType, new Object[]{ geom, extent.getMinX(), extent.getMinY(), extent.getMaxX(), extent.getMaxY(), tpclid, colorTable.getColorCode(textElement.getColorIndex()), textElement.getWeight(), textElement.getLineStyle() }, null); } else if (element instanceof ShapeElement) { ShapeElement shapeElement = (ShapeElement) element; Geometry geomShape = shapeElement.toGeometry(geometryFactory); Polygon polygon = (Polygon) geomShape; if (polygon.isRectangle()) { Envelope bounds = polygon.getEnvelopeInternal(); if (bounds.getWidth() == TPCLIDConverter.SX1200) { Coordinate center = bounds.centre(); String tpclid = TPCLIDConverter.CoordinateToTpclId(center); if ((tpclid == null) || (tpclid.length() == 0)) { logger.warn("Cannot convert coordinate to tpclid-[" + center.toString() + "]"); return null; } if (tpclid.length() > 5) { tpclid = tpclid.substring(0, 5); } Envelope extent = TPCLIDConverter.convertTpclIdToEnvelope(tpclid); Geometry geom = null; try { geom = (FeatureTypeBuilderUtil.getDefaultFeatureSRID() == 3826 ? geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[] { TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMinX(), extent.getMinY())), TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMaxX(), extent.getMinY())), TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMaxX(), extent.getMaxY())), TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMinX(), extent.getMaxY())), TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(extent.getMinX(), extent.getMinY())), }), null) : geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[] { TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMinX(), extent.getMinY())), TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMaxX(), extent.getMinY())), TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMaxX(), extent.getMaxY())), TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMinX(), extent.getMaxY())), TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(extent.getMinX(), extent.getMinY())), }), null)); } catch (NullPointerException e) { logger.warn("TPCLIDConverter has error at [" + tpclid + "]"); logger.warn(e.getMessage(), e); return null; } return (geom == null ? null : SimpleFeatureBuilder.build(featureType, new Object[]{ geom, extent.getMinX(), extent.getMinY(), extent.getMaxX(), extent.getMaxY(), tpclid, colorTable.getColorCode(shapeElement.getColorIndex()), shapeElement.getWeight(), shapeElement.getLineStyle() }, null)); } } } return null; } public SimpleFeature createFeature2(SimpleFeatureType featureType, Element element) throws IllegalAttributeException { DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance(); if (element instanceof TextElement) { SimpleFeature feature = null; TextElement txtElement = (TextElement) element; double angle = txtElement.getRotationAngle(); angle = BigDecimal.valueOf(angle).setScale(3, RoundingMode.HALF_UP).doubleValue(); GeometryConverterDecorator convertDecorator = FeatureTypeBuilderUtil.lookupDefaultGeometryConverter(); convertDecorator.setConverter(txtElement); Geometry gobj = convertDecorator.toGeometry(geometryFactory); if (gobj != null) feature = SimpleFeatureBuilder.build(featureType, new Object[]{ gobj, colorTable.getColorCode(txtElement.getColorIndex()), txtElement.getWeight(), txtElement.getLineStyle(), txtElement.getJustification(), txtElement.getTextHeight(), txtElement.getTextWidth(), angle, txtElement.getText() }, null); return feature; } else if (element instanceof ShapeElement) { SimpleFeature feature = null; ShapeElement shapeElement = (ShapeElement) element; double angle = 0.0; Geometry geomShape = shapeElement.toGeometry(geometryFactory); Polygon polygon = (Polygon) geomShape; if (polygon.isRectangle()) { Envelope bounds = polygon.getEnvelopeInternal(); if (bounds.getWidth() == TPCLIDConverter.SX1200) { Coordinate center = bounds.centre(); String tpclid = TPCLIDConverter.CoordinateToTpclId(center); if (tpclid.length() > 5) { tpclid = tpclid.substring(0, 5); Coordinate pos = (FeatureTypeBuilderUtil.getDefaultFeatureSRID() == 3826 ? TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate(center.x, center.y)) : TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate(center.x, center.y))); Geometry gobj = geometryFactory.createPoint(pos); if (gobj != null) feature = SimpleFeatureBuilder.build(featureType, new Object[]{ gobj, colorTable.getColorCode(shapeElement.getColorIndex()), shapeElement.getWeight(), shapeElement.getLineStyle(), 0, 15.0, 15 * 5, angle, tpclid }, null); return feature; } } } } return null; } public SimpleFeature[] createFeature3(SimpleFeatureType featureType, Element element) throws IllegalAttributeException { DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance(); if (element instanceof TextElement) { TextElement textElement = (TextElement) element; String tpclid = textElement.getText(); SimpleFeature[] result = new SimpleFeature[4]; Envelope extent = TPCLIDConverter.convertTpclIdToEnvelope(tpclid); for (int i = 0; i < 4; i++) { char mapSubId = TPCLIDConverter.intToAscii(65 + i); int dx = (i % 2) * TPCLIDConverter.SX600; int dy = (i / 2) * TPCLIDConverter.SY600; Geometry geom; if (FeatureTypeBuilderUtil.getDefaultFeatureSRID() == 3826) { geom = geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[] { TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate( extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate( extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate( extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - dy)), TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate( extent.getMinX() + dx, extent.getMaxY() - dy)), TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate( extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), }), null); } else { geom = geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[] { TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate( extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate( extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate( extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - dy)), TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate( extent.getMinX() + dx, extent.getMaxY() - dy)), TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate( extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), }), null); } Envelope innerExtent = geom.getEnvelopeInternal(); result[i] = SimpleFeatureBuilder.build(featureType, new Object[]{ geom, innerExtent.getMinX(), innerExtent.getMinY(), innerExtent.getMaxX(), innerExtent.getMaxY(), tpclid + mapSubId, colorTable.getColorCode(textElement.getColorIndex()), textElement.getWeight(), textElement.getLineStyle() }, null); } return result; } else if (element instanceof ShapeElement) { ShapeElement shapeElement = (ShapeElement) element; Geometry geomShape = shapeElement.toGeometry(geometryFactory); Polygon polygon = (Polygon) geomShape; if (polygon.isRectangle()) { Envelope extent = polygon.getEnvelopeInternal(); if (extent.getWidth() == TPCLIDConverter.SX1200) { SimpleFeature[] result = new SimpleFeature[4]; Coordinate center = extent.centre(); String tpclid = TPCLIDConverter.CoordinateToTpclId(center); if (tpclid.length() > 5) { tpclid = tpclid.substring(0, 5); } for (int i = 0; i < 4; i++) { char mapSubId = TPCLIDConverter.intToAscii(65 + i); int dx = (i % 2) * TPCLIDConverter.SX600; int dy = (i / 2) * TPCLIDConverter.SY600; Geometry geom = (FeatureTypeBuilderUtil.getDefaultFeatureSRID() == 3826 ? geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[] { TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate( extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate( extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate( extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - dy)), TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate( extent.getMinX() + dx, extent.getMaxY() - dy)), TWDDatumConverter.fromTM2ToEPSG3826(new Coordinate( extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), }), null) : geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[] { TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate( extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate( extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate( extent.getMinX() + TPCLIDConverter.SX600 + dx, extent.getMaxY() - dy)), TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate( extent.getMinX() + dx, extent.getMaxY() - dy)), TWDDatumConverter.fromTM2ToEPSG3825(new Coordinate( extent.getMinX() + dx, extent.getMaxY() - TPCLIDConverter.SY600 - dy)), }), null)); Envelope innerExtent = geom.getEnvelopeInternal(); result[i] = SimpleFeatureBuilder.build(featureType, new Object[]{ geom, innerExtent.getMinX(), innerExtent.getMinY(), innerExtent.getMaxX(), innerExtent.getMaxY(), tpclid + mapSubId, colorTable.getColorCode(shapeElement.getColorIndex()), shapeElement.getWeight(), shapeElement.getLineStyle() }, null); } return result; } } } return null; } private SimpleFeature createFeature(Element element) throws SchemaException, IllegalAttributeException { if (featureType1 == null) { String dgnname = getFilename().toLowerCase(); int i = dgnname.lastIndexOf("."); if (i != -1) { dgnname = dgnname.substring(0, i); } createFeatureElement(dgnname.toLowerCase()); } return createFeature(featureType1, element); } private SimpleFeature createFeature2(Element element) throws SchemaException, IllegalAttributeException { if (featureType2 == null) { String dgnname = getFilename().toLowerCase(); int i = dgnname.lastIndexOf("."); if (i != -1) { dgnname = dgnname.substring(0, i); } dgnname = dgnname + "_p"; createFeatureElement2(dgnname.toLowerCase()); } return createFeature2(featureType2, element); } private SimpleFeature[] createFeature3(Element element) throws SchemaException, IllegalAttributeException { if (featureType3 == null) { String dgnname = getFilename().toLowerCase(); int i = dgnname.lastIndexOf("."); if (i != -1) { dgnname = dgnname.substring(0, i); } dgnname = dgnname + "_s"; createFeatureElement3(dgnname.toLowerCase()); } return createFeature3(featureType3, element); } protected FrammeAttributeData getFeatureLinkage(Element element) { if (!element.hasUserAttributeData()) return null; List usrDatas = element.getUserAttributeData(); for (UserAttributeData anUsrData : usrDatas) { if (anUsrData instanceof FrammeAttributeData) { return (FrammeAttributeData) anUsrData; } } return null; } public Log getLogger() { return logger; } public boolean isDropTableMode() { return dropTableMode; } public void setDropTableMode(boolean dropTableMode) { this.dropTableMode = dropTableMode; } public void clearOutputDatabase() { } }