Search in sources :

Example 6 with ListFeatureCollection

use of org.geotools.data.collection.ListFeatureCollection in project sldeditor by robward-scisys.

the class InLineFeatureModel method addNewColumn.

/**
 * Adds the new column.
 */
public void addNewColumn() {
    if (featureCollection != null) {
        String attributeName = getUniqueAttributeName();
        columnList.add(attributeName);
        // Populate field names
        SimpleFeatureTypeBuilder featureTypeBuilder = new SimpleFeatureTypeBuilder();
        featureTypeBuilder.init(featureCollection.getSchema());
        featureTypeBuilder.add(attributeName, String.class);
        SimpleFeatureType newFeatureType = featureTypeBuilder.buildFeatureType();
        String typeName = userLayer.getInlineFeatureType().getTypeName();
        try {
            SimpleFeatureSource featureSource = userLayer.getInlineFeatureDatastore().getFeatureSource(typeName);
            SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(newFeatureType);
            ArrayList<SimpleFeature> featureList = new ArrayList<SimpleFeature>();
            SimpleFeatureIterator it = featureSource.getFeatures().features();
            try {
                while (it.hasNext()) {
                    SimpleFeature sf = it.next();
                    sfb.addAll(sf.getAttributes());
                    sfb.add(new String(""));
                    featureList.add(sfb.buildFeature(null));
                }
            } finally {
                it.close();
            }
            SimpleFeatureCollection collection = new ListFeatureCollection(newFeatureType, featureList);
            featureCollection = collection;
            cachedFeature = null;
            lastRow = -1;
            DataStore dataStore = DataUtilities.dataStore(collection);
            userLayer.setInlineFeatureDatastore(dataStore);
            userLayer.setInlineFeatureType(newFeatureType);
        } catch (IOException e) {
            ConsoleManager.getInstance().exception(this, e);
        }
        this.fireTableStructureChanged();
        this.fireTableDataChanged();
        if (parentObj != null) {
            parentObj.inlineFeatureUpdated();
        }
    }
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) DataStore(org.geotools.data.DataStore) ListFeatureCollection(org.geotools.data.collection.ListFeatureCollection) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Aggregations

IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 ListFeatureCollection (org.geotools.data.collection.ListFeatureCollection)6 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)6 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)6 SimpleFeature (org.opengis.feature.simple.SimpleFeature)6 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)6 DataStore (org.geotools.data.DataStore)5 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)5 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)5 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)1 LineString (com.vividsolutions.jts.geom.LineString)1 SpatialDataItem (io.opentraffic.engine.data.SpatialDataItem)1 File (java.io.File)1 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 ShapefileDataStore (org.geotools.data.shapefile.ShapefileDataStore)1 ShapefileDataStoreFactory (org.geotools.data.shapefile.ShapefileDataStoreFactory)1