Search in sources :

Example 21 with DataStore

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

the class CreateSampleDataTest method testGetDataStore.

/**
 * Test method for {@link com.sldeditor.datasource.impl.CreateSampleData#getDataStore()}.
 */
@Test
public void testGetDataStore() {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    String typeName = "test type name";
    b.setName(typeName);
    String namespace = null;
    b.setNamespaceURI(namespace);
    // add a geometry property
    // set crs first
    b.setCRS(DefaultGeographicCRS.WGS84);
    b.add("the_geom", Polygon.class);
    b.setDefaultGeometry("the_geom");
    // Build the feature type
    SimpleFeatureType schema = b.buildFeatureType();
    CreateSampleData sampleData = new CreateSampleData();
    sampleData.create(null, null);
    sampleData.create(schema, null);
    DataStore dataStore = sampleData.getDataStore();
    assertTrue(dataStore != null);
    assertEquals(GeometryTypeEnum.POLYGON, sampleData.getGeometryType());
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) CreateSampleData(com.sldeditor.datasource.impl.CreateSampleData) DataStore(org.geotools.data.DataStore) Test(org.junit.Test)

Example 22 with DataStore

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

the class DataSourceInfoTest method testGetFeatures.

/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceInfo#getFeatures()}.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGetFeatures() {
    URL url = SLDEditorFile.class.getClassLoader().getResource("point/sld/shp/sld_cookbook_point.shp");
    Map map = new HashMap();
    map.put("url", url);
    DataStore dataStore;
    try {
        dataStore = DataStoreFinder.getDataStore(map);
        DataSourceInfo dsInfo = new DataSourceInfo();
        String typeName = dataStore.getTypeNames()[0];
        dsInfo.setTypeName(typeName);
        SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
        SimpleFeatureType schema = source.getSchema();
        assertNull(dsInfo.getFeatures());
        dsInfo.setSchema(schema);
        assertNull(dsInfo.getFeatures());
        dsInfo.setDataStore(dataStore);
        assertTrue(dsInfo.getFeatures() != null);
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : DataSourceInfo(com.sldeditor.datasource.impl.DataSourceInfo) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) HashMap(java.util.HashMap) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) DataStore(org.geotools.data.DataStore) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL) Test(org.junit.Test)

Example 23 with DataStore

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

the class DataSourceInfoTest method testGetGeometryFieldName.

/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceInfo#getGeometryFieldName()}.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGetGeometryFieldName() {
    URL url = SLDEditorFile.class.getClassLoader().getResource("point/sld/shp/sld_cookbook_point.shp");
    Map map = new HashMap();
    map.put("url", url);
    DataStore dataStore;
    try {
        dataStore = DataStoreFinder.getDataStore(map);
        DataSourceInfo dsInfo = new DataSourceInfo();
        String typeName = dataStore.getTypeNames()[0];
        dsInfo.setTypeName(typeName);
        SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
        SimpleFeatureType schema = source.getSchema();
        assertNull(dsInfo.getGeometryFieldName());
        dsInfo.setSchema(schema);
        assertEquals("the_geom", dsInfo.getGeometryFieldName());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : DataSourceInfo(com.sldeditor.datasource.impl.DataSourceInfo) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) HashMap(java.util.HashMap) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) DataStore(org.geotools.data.DataStore) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL) Test(org.junit.Test)

Example 24 with DataStore

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

the class DataSourceInfoTest method testGetFeatureCollection.

/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceInfo#getFeatureCollection()}.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGetFeatureCollection() {
    URL url = SLDEditorFile.class.getClassLoader().getResource("point/sld/shp/sld_cookbook_point.shp");
    Map map = new HashMap();
    map.put("url", url);
    DataStore dataStore;
    try {
        dataStore = DataStoreFinder.getDataStore(map);
        DataSourceInfo dsInfo = new DataSourceInfo();
        String typeName = dataStore.getTypeNames()[0];
        dsInfo.setTypeName(typeName);
        SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
        SimpleFeatureType schema = source.getSchema();
        assertNull(dsInfo.getGeometryFieldName());
        dsInfo.setSchema(schema);
        assertEquals("the_geom", dsInfo.getGeometryFieldName());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : DataSourceInfo(com.sldeditor.datasource.impl.DataSourceInfo) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) HashMap(java.util.HashMap) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) DataStore(org.geotools.data.DataStore) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL) Test(org.junit.Test)

Example 25 with DataStore

use of org.geotools.data.DataStore in project incubator-rya by apache.

the class GeoMesaGeoIndexer method initInternal.

private void initInternal() throws IOException {
    validPredicates = ConfigUtils.getGeoPredicates(conf);
    final DataStore dataStore = createDataStore(conf);
    try {
        featureType = getStatementFeatureType(dataStore);
    } catch (final IOException | SchemaException e) {
        throw new IOException(e);
    }
    featureSource = dataStore.getFeatureSource(featureType.getName());
    if (!(featureSource instanceof FeatureStore)) {
        throw new IllegalStateException("Could not retrieve feature store");
    }
    featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) featureSource;
}
Also used : SchemaException(org.geotools.feature.SchemaException) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) DataStore(org.geotools.data.DataStore) AccumuloDataStore(org.locationtech.geomesa.accumulo.data.AccumuloDataStore) IOException(java.io.IOException) FeatureStore(org.geotools.data.FeatureStore) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Aggregations

DataStore (org.geotools.data.DataStore)52 IOException (java.io.IOException)28 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)28 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)23 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)22 GeoToolsOpException (org.locationtech.geogig.geotools.plumbing.GeoToolsOpException)22 HashMap (java.util.HashMap)10 Map (java.util.Map)10 SimpleFeature (org.opengis.feature.simple.SimpleFeature)9 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)8 Test (org.junit.Test)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 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