Search in sources :

Example 16 with SimpleFeatureSource

use of org.geotools.data.simple.SimpleFeatureSource in project sldeditor by robward-scisys.

the class DataSourceInfo method getFeatureCollection.

/**
 * Gets the feature collection.
 *
 * @return the feature collection
 */
public SimpleFeatureCollection getFeatureCollection() {
    SimpleFeatureCollection featureCollection = null;
    try {
        if (dataStore != null) {
            SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
            featureCollection = source.getFeatures();
        }
    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    return featureCollection;
}
Also used : SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) IOException(java.io.IOException) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection)

Example 17 with SimpleFeatureSource

use of org.geotools.data.simple.SimpleFeatureSource in project sldeditor by robward-scisys.

the class DataSourceInfo method getFeatureCollection.

/**
 * Gets the feature collection.
 *
 * @return the feature collection
 */
public SimpleFeatureCollection getFeatureCollection() {
    SimpleFeatureCollection featureCollection = null;
    try {
        if (dataStore != null) {
            SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
            featureCollection = source.getFeatures();
        }
    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    return featureCollection;
}
Also used : SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) IOException(java.io.IOException) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection)

Example 18 with SimpleFeatureSource

use of org.geotools.data.simple.SimpleFeatureSource in project sldeditor by robward-scisys.

the class DatabaseClient method hasGeometryField.

/**
 * Checks for the presence of a geometry field.
 *
 * @param dataStore the data store
 * @param name the name
 * @return true, if geometry field present
 */
private boolean hasGeometryField(DataStore dataStore, Name name) {
    try {
        SimpleFeatureSource featureSource = dataStore.getFeatureSource(name);
        GeometryDescriptor geometryDescriptor = featureSource.getSchema().getGeometryDescriptor();
        return (geometryDescriptor != null);
    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    return false;
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) IOException(java.io.IOException)

Example 19 with SimpleFeatureSource

use of org.geotools.data.simple.SimpleFeatureSource in project sldeditor by robward-scisys.

the class InLineFeatureModel method removeFeature.

/**
 * Removes the feature.
 *
 * @param selectedRow the selected row
 */
public void removeFeature(int selectedRow) {
    if ((selectedRow < 0) || (selectedRow >= getRowCount())) {
        return;
    }
    SimpleFeatureType featureType = userLayer.getInlineFeatureType();
    String typeName = userLayer.getInlineFeatureType().getTypeName();
    try {
        SimpleFeatureSource featureSource = userLayer.getInlineFeatureDatastore().getFeatureSource(typeName);
        SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(featureType);
        ArrayList<SimpleFeature> featureList = new ArrayList<SimpleFeature>();
        SimpleFeatureIterator it = featureSource.getFeatures().features();
        try {
            int index = 0;
            while (it.hasNext()) {
                SimpleFeature sf = it.next();
                if (index != selectedRow) {
                    List<Object> attributeValueList = sf.getAttributes();
                    sfb.addAll(attributeValueList);
                    featureList.add(sfb.buildFeature(null));
                }
                index++;
            }
        } finally {
            it.close();
        }
        SimpleFeatureCollection collection = new ListFeatureCollection(featureType, featureList);
        featureCollection = collection;
        cachedFeature = null;
        lastRow = -1;
        DataStore dataStore = DataUtilities.dataStore(collection);
        userLayer.setInlineFeatureDatastore(dataStore);
    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    this.fireTableStructureChanged();
    this.fireTableDataChanged();
    if (parentObj != null) {
        parentObj.inlineFeatureUpdated();
    }
}
Also used : 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)

Example 20 with SimpleFeatureSource

use of org.geotools.data.simple.SimpleFeatureSource in project sldeditor by robward-scisys.

the class InLineFeatureModel method updateCRS.

/**
 * Update CRS.
 *
 * @param selectedValue the selected value
 */
public void updateCRS(ValueComboBoxData selectedValue) {
    if (selectedValue != null) {
        String crsCode = selectedValue.getKey();
        CoordinateReferenceSystem newCRS = CoordManager.getInstance().getCRS(crsCode);
        SimpleFeatureType newFeatureType = SimpleFeatureTypeBuilder.retype(featureCollection.getSchema(), newCRS);
        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();
                    List<Object> attributeValueList = sf.getAttributes();
                    sfb.addAll(attributeValueList);
                    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 : 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) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Aggregations

SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)54 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)29 IOException (java.io.IOException)28 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)25 SimpleFeature (org.opengis.feature.simple.SimpleFeature)23 DataStore (org.geotools.data.DataStore)22 Test (org.junit.Test)21 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)20 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)19 Feature (org.opengis.feature.Feature)16 HashMap (java.util.HashMap)15 MemoryDataStore (org.geotools.data.memory.MemoryDataStore)13 URL (java.net.URL)10 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)10 GeoToolsOpException (org.locationtech.geogig.geotools.plumbing.GeoToolsOpException)10 ExportOp (org.locationtech.geogig.geotools.plumbing.ExportOp)9 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)8 InvalidParameterException (org.locationtech.geogig.cli.InvalidParameterException)8