1 package org
.argeo
.geotools
;
3 import java
.io
.IOException
;
5 import org
.argeo
.ArgeoException
;
6 import org
.geotools
.data
.DataStore
;
7 import org
.geotools
.data
.FeatureSource
;
8 import org
.geotools
.data
.FeatureStore
;
9 import org
.opengis
.feature
.simple
.SimpleFeature
;
10 import org
.opengis
.feature
.simple
.SimpleFeatureType
;
11 import org
.opengis
.feature
.type
.Name
;
13 /** Utilities related to the GeoTools framework */
14 public class GeoToolsUtils
{
16 /** Opens a read/write feature store */
17 public static FeatureStore
<SimpleFeatureType
, SimpleFeature
> getFeatureStore(
18 DataStore dataStore
, Name name
) {
19 FeatureSource
<SimpleFeatureType
, SimpleFeature
> featureSource
;
21 featureSource
= dataStore
.getFeatureSource(name
);
22 } catch (IOException e
) {
23 throw new ArgeoException("Cannot open feature source " + name
24 + " in data store " + dataStore
, e
);
26 if (!(featureSource
instanceof FeatureStore
)) {
27 throw new ArgeoException("Feature source " + name
28 + " is not writable.");
30 return (FeatureStore
<SimpleFeatureType
, SimpleFeature
>) featureSource
;
33 /** Creates the provided schema in the data store. */
34 public static void createSchemaIfNeeded(DataStore dataStore
,
35 SimpleFeatureType featureType
) {
37 dataStore
.getSchema(featureType
.getName());
38 } catch (IOException e
) {
39 // assume it does not exist
41 dataStore
.createSchema(featureType
);
42 } catch (IOException e1
) {
43 throw new ArgeoException("Cannot create schema " + featureType
,