Search in sources :

Example 1 with SchemaException

use of org.geotools.feature.SchemaException 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)

Example 2 with SchemaException

use of org.geotools.feature.SchemaException in project traffic-engine by opentraffic.

the class OSMUtils method toShapefile.

public static void toShapefile(List<SpatialDataItem> segs, String filename) throws SchemaException, IOException {
    final SimpleFeatureType TYPE = DataUtilities.createType("Location", "the_geom:LineString:srid=4326," + "name:String");
    System.out.println("TYPE:" + TYPE);
    List<SimpleFeature> features = new ArrayList<SimpleFeature>();
    /*
         * GeometryFactory will be used to create the geometry attribute of each feature,
         * using a Point object for the location.
         */
    GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
    SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
    for (SpatialDataItem seg : segs) {
        featureBuilder.add(seg.getGeometry());
        featureBuilder.add(seg.id);
        SimpleFeature feature = featureBuilder.buildFeature(null);
        features.add(feature);
    }
    File newFile = new File(filename);
    ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
    Map<String, Serializable> params = new HashMap<String, Serializable>();
    params.put("url", newFile.toURI().toURL());
    params.put("create spatial index", Boolean.TRUE);
    ShapefileDataStore newDataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
    /*
         * TYPE is used as a template to describe the file contents
         */
    newDataStore.createSchema(TYPE);
    ContentFeatureSource cfs = newDataStore.getFeatureSource();
    if (cfs instanceof SimpleFeatureStore) {
        SimpleFeatureStore featureStore = (SimpleFeatureStore) cfs;
        SimpleFeatureCollection collection = new ListFeatureCollection(TYPE, features);
        try {
            featureStore.addFeatures(collection);
        } catch (Exception problem) {
            problem.printStackTrace();
        } finally {
        }
    }
}
Also used : Serializable(java.io.Serializable) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SpatialDataItem(io.opentraffic.engine.data.SpatialDataItem) LineString(com.vividsolutions.jts.geom.LineString) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SchemaException(org.geotools.feature.SchemaException) IOException(java.io.IOException) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) ListFeatureCollection(org.geotools.data.collection.ListFeatureCollection) ShapefileDataStoreFactory(org.geotools.data.shapefile.ShapefileDataStoreFactory) File(java.io.File) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) ContentFeatureSource(org.geotools.data.store.ContentFeatureSource)

Example 3 with SchemaException

use of org.geotools.feature.SchemaException in project GeoGig by boundlessgeo.

the class CachingModuleTest method ft.

private static RevFeatureType ft(String name) {
    SimpleFeatureType type;
    try {
        type = DataUtilities.createType("", name, RepositoryTestCase.pointsTypeSpec);
    } catch (SchemaException e) {
        throw Throwables.propagate(e);
    }
    RevFeatureType rft = RevFeatureTypeImpl.build(type);
    return rft;
}
Also used : SchemaException(org.geotools.feature.SchemaException) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Example 4 with SchemaException

use of org.geotools.feature.SchemaException in project incubator-rya by apache.

the class GeoWaveGeoIndexer method initInternal.

private void initInternal() throws IOException {
    validPredicates = ConfigUtils.getGeoPredicates(conf);
    try {
        geoToolsDataStore = createDataStore(conf);
        geoWaveDataStore = ((GeoWaveGTDataStore) geoToolsDataStore).getDataStore();
    } catch (final GeoWavePluginException e) {
        logger.error("Failed to create GeoWave data store", e);
    }
    try {
        featureType = getStatementFeatureType(geoToolsDataStore);
    } catch (final IOException | SchemaException e) {
        throw new IOException(e);
    }
    featureDataAdapter = new FeatureDataAdapter(featureType);
    featureSource = geoToolsDataStore.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) IOException(java.io.IOException) FeatureDataAdapter(mil.nga.giat.geowave.adapter.vector.FeatureDataAdapter) FeatureStore(org.geotools.data.FeatureStore) SimpleFeature(org.opengis.feature.simple.SimpleFeature) GeoWavePluginException(mil.nga.giat.geowave.adapter.vector.plugin.GeoWavePluginException)

Aggregations

SchemaException (org.geotools.feature.SchemaException)4 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)4 IOException (java.io.IOException)3 SimpleFeature (org.opengis.feature.simple.SimpleFeature)3 FeatureStore (org.geotools.data.FeatureStore)2 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 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 FeatureDataAdapter (mil.nga.giat.geowave.adapter.vector.FeatureDataAdapter)1 GeoWavePluginException (mil.nga.giat.geowave.adapter.vector.plugin.GeoWavePluginException)1 DataStore (org.geotools.data.DataStore)1 ListFeatureCollection (org.geotools.data.collection.ListFeatureCollection)1 ShapefileDataStore (org.geotools.data.shapefile.ShapefileDataStore)1 ShapefileDataStoreFactory (org.geotools.data.shapefile.ShapefileDataStoreFactory)1 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)1 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)1