forked from geodmms/xdgnjobs

?? ?
2008-03-17 2fae905a591201e3d4ee3d463d1d94a504171017
ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/CreateLineStringStrategy.java
@@ -1,14 +1,43 @@
package com.ximple.eofms.jobs;
import java.util.List;
import org.geotools.feature.AttributeTypeFactory;
import org.geotools.feature.Feature;
import org.geotools.feature.FeatureType;
import org.geotools.feature.FeatureTypeBuilder;
import org.geotools.feature.IllegalAttributeException;
import org.geotools.feature.SchemaException;
import org.opengis.geometry.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.ximple.io.dgn7.Element;
import com.ximple.io.dgn7.FrammeAttributeData;
import com.ximple.io.dgn7.LineStringElement;
import com.ximple.io.dgn7.UserAttributeData;
public class CreateLineStringStrategy implements CreateFeatureTypeStrategy
{
    GeometryFactory geometryFactory = new GeometryFactory();
    FeatureTypeBuilder typeBuilder = null;
    protected FrammeAttributeData getFeatureLinkage(Element element)
    {
        if (!element.hasUserAttributeData())
            return null;
        List<UserAttributeData> usrDatas = element.getUserAttributeData();
        for (UserAttributeData anUsrData : usrDatas)
        {
            if (anUsrData instanceof FrammeAttributeData)
            {
                FrammeAttributeData featureLinkage = (FrammeAttributeData) anUsrData;
                return featureLinkage;
            }
        }
        return null;
    }
    public FeatureType createFeatureElement(String featureName) throws SchemaException
    {
@@ -27,4 +56,27 @@
        }
        return typeBuilder.getFeatureType();
    }
    public Feature createFeature(FeatureType featureType, Element element) throws IllegalAttributeException
    {
        FrammeAttributeData fLinkage = getFeatureLinkage(element);
        if (fLinkage == null) return null;
        if (element instanceof LineStringElement)
        {
            LineStringElement lineStringElement = (LineStringElement) element;
            Feature feature = featureType.create(new Object[]{
                    geometryFactory.createLineString(lineStringElement.getVertices()),
                    (int) fLinkage.getFsc(),
                    (long) fLinkage.getUfid(),
                    (int) fLinkage.getComponentID(),
                    0,
                    lineStringElement.getLevelIndex(),
                    lineStringElement.getColorIndex(),
                    lineStringElement.getWeight(),
                    lineStringElement.getLineStyle(),
            });
            return feature;
        }
        return null;
    }
}