Search in sources :

Example 51 with DataStore

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

the class VectorReader method createSLDData.

/**
 * Creates the SLD data.
 *
 * @param map the map
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createSLDData(Map<String, Object> map, String featureClass) {
    StyledLayerDescriptor sld = null;
    DataStore dataStore = null;
    try {
        dataStore = DataStoreFinder.getDataStore(map);
    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
        return null;
    }
    if (dataStore != null) {
        // Try connecting to a vector data source
        String typeName;
        GeometryTypeEnum geometryTypeEnum = GeometryTypeEnum.UNKNOWN;
        try {
            if (featureClass == null) {
                typeName = dataStore.getTypeNames()[0];
            } else {
                typeName = featureClass;
            }
            SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
            SimpleFeatureType schema = source.getSchema();
            GeometryType geometryType = schema.getGeometryDescriptor().getType();
            Class<?> bindingType = geometryType.getBinding();
            geometryTypeEnum = GeometryTypeMapping.getGeometryType(bindingType);
        } catch (IOException e) {
            ConsoleManager.getInstance().exception(this, e);
            return null;
        } finally {
            dataStore.dispose();
        }
        switch(geometryTypeEnum) {
            case POINT:
                sld = DefaultSymbols.createNewPoint();
                break;
            case LINE:
                sld = DefaultSymbols.createNewLine();
                break;
            case POLYGON:
                sld = DefaultSymbols.createNewPolygon();
                break;
            default:
                break;
        }
    }
    return sld;
}
Also used : GeometryType(org.opengis.feature.type.GeometryType) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) DataStore(org.geotools.data.DataStore) IOException(java.io.IOException) GeometryTypeEnum(com.sldeditor.datasource.impl.GeometryTypeEnum)

Example 52 with DataStore

use of org.geotools.data.DataStore in project mkgmap by openstreetmap.

the class PrecompSeaGenerator method createShapefileAccess.

private void createShapefileAccess() throws IOException {
    Map<String, URL> map = new HashMap<String, URL>();
    map.put("url", shapeFile.toURI().toURL());
    DataStore dataStore = DataStoreFinder.getDataStore(map);
    String typeName = dataStore.getTypeNames()[0];
    SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
    shapeCollection = source.getFeatures();
}
Also used : HashMap(java.util.HashMap) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) DataStore(org.geotools.data.DataStore) URL(java.net.URL)

Aggregations

DataStore (org.geotools.data.DataStore)52 IOException (java.io.IOException)28 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)28 GeoToolsOpException (org.locationtech.geogig.geotools.plumbing.GeoToolsOpException)22 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)22 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)21 HashMap (java.util.HashMap)10 Map (java.util.Map)10 SimpleFeature (org.opengis.feature.simple.SimpleFeature)9 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)8 InvalidParameterException (org.locationtech.geogig.cli.InvalidParameterException)8 ExportOp (org.locationtech.geogig.geotools.plumbing.ExportOp)8 Serializable (java.io.Serializable)7 ArrayList (java.util.ArrayList)7 Test (org.junit.jupiter.api.Test)7 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)6 DataSourceInfo (com.sldeditor.datasource.impl.DataSourceInfo)6 URL (java.net.URL)6 ProgressListener (org.locationtech.geogig.api.ProgressListener)6 ListFeatureCollection (org.geotools.data.collection.ListFeatureCollection)5