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;
}
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 {
}
}
}
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;
}
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;
}
Aggregations