New file |
| | |
| | | package com.ximple.eofms.filter; |
| | | |
| | | import java.util.List; |
| | | |
| | | import org.geotools.feature.FeatureTypeBuilder; |
| | | import org.geotools.feature.FeatureType; |
| | | import org.geotools.feature.SchemaException; |
| | | import org.geotools.feature.AttributeTypeFactory; |
| | | import org.geotools.feature.Feature; |
| | | import org.geotools.feature.IllegalAttributeException; |
| | | |
| | | import com.vividsolutions.jts.geom.GeometryFactory; |
| | | import com.vividsolutions.jts.geom.Geometry; |
| | | import com.vividsolutions.jts.geom.Coordinate; |
| | | import com.vividsolutions.jts.geom.LineString; |
| | | |
| | | import com.ximple.eofms.jobs.TWD97GeometryConverterDecorator; |
| | | import com.ximple.eofms.util.DefaultColorTable; |
| | | import com.ximple.eofms.util.TWDDatumConverter; |
| | | import com.ximple.io.dgn7.FrammeAttributeData; |
| | | import com.ximple.io.dgn7.Element; |
| | | import com.ximple.io.dgn7.UserAttributeData; |
| | | import com.ximple.io.dgn7.LineStringElement; |
| | | import com.ximple.io.dgn7.ComplexChainElement; |
| | | import com.ximple.io.dgn7.TextElement; |
| | | import com.ximple.io.dgn7.LineElement; |
| | | |
| | | public class CreateLineTextStrategy implements CreateFeatureTypeStrategy |
| | | { |
| | | GeometryFactory geometryFactory = new GeometryFactory(); |
| | | FeatureTypeBuilder typeBuilder = null; |
| | | TWD97GeometryConverterDecorator convertDecordator = new TWD97GeometryConverterDecorator(); |
| | | |
| | | public CreateLineTextStrategy() |
| | | { |
| | | } |
| | | |
| | | protected FrammeAttributeData getFeatureLinkage(Element element) |
| | | { |
| | | if (!element.hasUserAttributeData()) |
| | | return null; |
| | | |
| | | List<UserAttributeData> usrDatas = element.getUserAttributeData(); |
| | | for (UserAttributeData anUsrData : usrDatas) |
| | | { |
| | | if (anUsrData instanceof FrammeAttributeData) |
| | | { |
| | | return (FrammeAttributeData) anUsrData; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public FeatureType createFeatureElement(String featureName) throws SchemaException |
| | | { |
| | | if (typeBuilder == null) |
| | | { |
| | | typeBuilder = FeatureTypeBuilder.newInstance(featureName); |
| | | typeBuilder.addType(AttributeTypeFactory.newAttributeType("GEOM", Geometry.class)); |
| | | typeBuilder.addType(AttributeTypeFactory.newAttributeType("TID", Integer.class)); |
| | | typeBuilder.addType(AttributeTypeFactory.newAttributeType("OID", Long.class)); |
| | | typeBuilder.addType(AttributeTypeFactory.newAttributeType("CID", Integer.class)); |
| | | typeBuilder.addType(AttributeTypeFactory.newAttributeType("LID", Integer.class)); |
| | | typeBuilder.addType(AttributeTypeFactory.newAttributeType("LEVEL", Integer.class)); |
| | | typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMCOLOR", Integer.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(); |
| | | FrammeAttributeData fLinkage = getFeatureLinkage(element); |
| | | if (fLinkage == null) return null; |
| | | if (element instanceof LineStringElement) |
| | | { |
| | | LineStringElement lineStringElement = (LineStringElement) element; |
| | | convertDecordator.setConverter(lineStringElement); |
| | | Feature feature = featureType.create(new Object[]{ |
| | | convertDecordator.toGeometry(geometryFactory), |
| | | (int) fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (int) fLinkage.getComponentID(), |
| | | 0, |
| | | lineStringElement.getLevelIndex(), |
| | | colorTable.getColor(lineStringElement.getColorIndex()).getRGB(), |
| | | lineStringElement.getWeight(), |
| | | lineStringElement.getLineStyle() |
| | | }); |
| | | return feature; |
| | | } else if (element instanceof TextElement) |
| | | { |
| | | TextElement txtElement = (TextElement) element; |
| | | Coordinate ptOrigin = txtElement.getUserOrigin(); |
| | | Coordinate ptEnd = new Coordinate(); |
| | | ptEnd.x = ptOrigin.x; |
| | | ptEnd.y = ptOrigin.y + txtElement.getTextHeight(); |
| | | Coordinate[] vect = new Coordinate[2]; |
| | | vect[0] = TWDDatumConverter.fromTM2ToTWD97(ptOrigin); |
| | | vect[1] = TWDDatumConverter.fromTM2ToTWD97(ptEnd); |
| | | |
| | | LineString line = geometryFactory.createLineString(vect); |
| | | // convertDecordator.setConverter(txtElement); |
| | | // Geometry geom = convertDecordator.toGeometry(geometryFactory); |
| | | |
| | | txtElement.getRotationAngle(); |
| | | |
| | | Feature feature = featureType.create(new Object[]{ |
| | | line, |
| | | (int) fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (int) fLinkage.getComponentID(), |
| | | 0, |
| | | txtElement.getLevelIndex(), |
| | | colorTable.getColor(txtElement.getColorIndex()).getRGB(), |
| | | txtElement.getWeight(), |
| | | txtElement.getLineStyle() |
| | | }); |
| | | return feature; |
| | | } else if (element instanceof LineElement) |
| | | { |
| | | LineElement lineElement = (LineElement) element; |
| | | convertDecordator.setConverter(lineElement); |
| | | Feature feature = featureType.create(new Object[]{ |
| | | convertDecordator.toGeometry(geometryFactory), |
| | | (int) fLinkage.getFsc(), |
| | | (long) fLinkage.getUfid(), |
| | | (int) fLinkage.getComponentID(), |
| | | 0, |
| | | lineElement.getLevelIndex(), |
| | | colorTable.getColor(lineElement.getColorIndex()).getRGB(), |
| | | lineElement.getWeight(), |
| | | lineElement.getLineStyle() |
| | | }); |
| | | return feature; |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | } |
| | | |