本文整理匯總了Java中org.geotools.data.DataStore.getFeatureSource方法的典型用法代碼示例。如果您正苦於以下問題:Java DataStore.getFeatureSource方法的具體用法?Java DataStore.getFeatureSource怎麽用?Java DataStore.getFeatureSource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.geotools.data.DataStore
的用法示例。
在下文中一共展示了DataStore.getFeatureSource方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: read
import org.geotools.data.DataStore; //導入方法依賴的package包/類
public void read(URL file) throws IOException {
Map<String, Object> map = new HashMap<>();
map.put("url", file);
DataStore dataStore = DataStoreFinder.getDataStore(map);
String typeName = dataStore.getTypeNames()[0];
FeatureSource<SimpleFeatureType, SimpleFeature> source = dataStore.getFeatureSource(typeName);
FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures();
FeatureIterator<SimpleFeature> features = collection.features();
int count = 0;
LOGGER.info("reading world time zones ...");
while (features.hasNext()) {
count++;
SimpleFeature feature = features.next();
ReferencedEnvelope referencedEnvelope = new ReferencedEnvelope(feature.getBounds());
quadtree.insert(referencedEnvelope,feature);
}
LOGGER.info(count + " features read");
}
示例2: testLoadShapeFile
import org.geotools.data.DataStore; //導入方法依賴的package包/類
/**
* Test if shapeRDD get correct number of shapes from .shp file
* @throws IOException
*/
@Test
public void testLoadShapeFile() throws IOException {
// load shape with geotool.shapefile
InputLocation = ShapefileRDDTest.class.getClassLoader().getResource("shapefiles/polygon").getPath();
File file = new File(InputLocation);
Map<String, Object> map = new HashMap<String, Object>();
map.put("url", file.toURI().toURL());
DataStore dataStore = DataStoreFinder.getDataStore(map);
String typeName = dataStore.getTypeNames()[0];
FeatureSource<SimpleFeatureType, SimpleFeature> source = dataStore
.getFeatureSource(typeName);
Filter filter = Filter.INCLUDE;
FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures(filter);
// load shapes with our tool
ShapefileRDD shapefileRDD = new ShapefileRDD(sc,InputLocation);
Assert.assertEquals(shapefileRDD.getShapeRDD().collect().size(), collection.size());
dataStore.dispose();
}
示例3: saveAll
import org.geotools.data.DataStore; //導入方法依賴的package包/類
/**
* Method to store analysed image params in a table on the DDBB for posterior data mining
*
* @param layer
* @param projection
* @param imageCis
*/
public void saveAll(GeometryImage layer, String projection, Object[] imageCis,GeoImageReader gir) {
try {
//Data store to get access to ddbb
DataStore datastore = (DataStore) DataStoreFinder.getDataStore(config);
//Access to the corresponding Imagery table on ddbb
FeatureStore featurestore = (FeatureStore) datastore.getFeatureSource(imageCis[0].toString());
SimpleFeatureType featuretype = (SimpleFeatureType) featurestore.getSchema();
FeatureCollection features = createTabFeatures(featuretype,imageCis);
featurestore.addFeatures(features);
writeToDB(datastore, features);
datastore.dispose();
// store extracted VDS points
save(null,projection,((SarImageReader)gir).getGeoTransform());
} catch (Exception ex) {
logger.error(ex.getMessage(),ex);
}
}
示例4: initInternal
import org.geotools.data.DataStore; //導入方法依賴的package包/類
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;
}
示例5: exportUAZ
import org.geotools.data.DataStore; //導入方法依賴的package包/類
/**
* Export uaz.
*
* @param project
* the project
* @param userId
* the user id
* @return the string
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws DataStoreCreationException
* the data store creation exception
* @throws MiddlewarePersistentException
*/
public String exportUAZ(final WifProject project, final String userId)
throws IOException, DataStoreCreationException,
MiddlewarePersistentException {
LOGGER.info("Entering exportUAZ/share in my aurin");
LOGGER.info("using the following server: {} for database/schema: {}",
postgisDataStoreConfig.getDataStoreParams().get(HOST.key),
postgisDataStoreConfig.getDataStoreParams().get(DATABASE.key) + "/"
+ postgisDataStoreConfig.getDataStoreParams().get(SCHEMA.key));
final String tableName = project.getSuitabilityConfig()
.getUnifiedAreaZone();
final DataStore dataStore = DataStoreFinder
.getDataStore(postgisDataStoreConfig.getDataStoreParams());
final SimpleFeatureSource featureSource = dataStore
.getFeatureSource(tableName);
final SimpleFeatureCollection features = featureSource.getFeatures();
final String result = shareUAZSnapshot(features, userId, project);
LOGGER
.info("exporting finished, information sent to AURIN/middleware persistence!");
return result;
}
示例6: getWifUAZfromDB
import org.geotools.data.DataStore; //導入方法依賴的package包/類
/**
* Gets the wif ua zfrom db.
*
* @param uazTbl
* the uaz tbl
* @return the wif ua zfrom db
*/
public SimpleFeatureCollection getWifUAZfromDB(final String uazTbl) {
LOGGER.info("getWifUAZfromDB for table : {}", uazTbl);
SimpleFeatureCollection uazFeatureCollection = FeatureCollections
.newCollection();
DataStore wifDataStore;
try {
wifDataStore = openPostgisDataStore();
final SimpleFeatureSource featureSourceUD = wifDataStore
.getFeatureSource(uazTbl);
uazFeatureCollection = featureSourceUD.getFeatures();
LOGGER.info("UAZ featureCollection size : {} ",
uazFeatureCollection.size());
} catch (final IOException e) {
LOGGER.error("could not access table {} ", uazTbl);
}
return uazFeatureCollection;
}
示例7: updateUAZArea
import org.geotools.data.DataStore; //導入方法依賴的package包/類
/**
* Update uaz area.
*
* @param uazTbl
* the uaz tbl
*/
public void updateUAZArea(final String uazTbl) {
LOGGER.info("updateUAZArea for table : {}", uazTbl);
DataStore wifDataStore;
try {
wifDataStore = openPostgisDataStore();
final SimpleFeatureSource featureSourceUD = wifDataStore
.getFeatureSource(uazTbl);
final SimpleFeatureType schema = featureSourceUD.getSchema();
final String geomColumnName = schema.getGeometryDescriptor()
.getLocalName();
final JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
final String queryTxt = "UPDATE "
+ postgisDataStoreConfig.getDataStoreParams().get(SCHEMA.key) + "."
+ uazTbl + " SET \"" + WifKeys.DEFAULT_AREA_COLUMN_NAME + "\" = "
+ " (ST_Area( " + geomColumnName + " )) ";
LOGGER.debug("updateUAZArea: {}", queryTxt);
jdbcTemplate.execute(queryTxt);
} catch (final IOException e) {
LOGGER.error("could not access table {} ", uazTbl);
}
}
示例8: getFeatureSourcefromDB
import org.geotools.data.DataStore; //導入方法依賴的package包/類
/**
* Gets the feature sourcefrom db.
*
* @param uazTbl
* the uaz tbl
* @return the feature sourcefrom db
* @throws WifInvalidInputException
* the wif invalid input exception
*/
public SimpleFeatureSource getFeatureSourcefromDB(final String uazTbl)
throws WifInvalidInputException {
LOGGER.info("getFeatureSourcefromDB for table : {}", uazTbl);
DataStore wifDataStore;
SimpleFeatureSource featureSourceUD;
try {
wifDataStore = openPostgisDataStore();
featureSourceUD = wifDataStore.getFeatureSource(uazTbl);
LOGGER.info("UAZ featureSource Name: {} ", featureSourceUD.getName());
return featureSourceUD;
}
catch (final IOException e) {
LOGGER.error("could not access table {} ", uazTbl);
throw new WifInvalidInputException("could not access table" + uazTbl);
}
}
示例9: testLoadShapeFilePolyLine
import org.geotools.data.DataStore; //導入方法依賴的package包/類
/**
* test if shapeRDD load .shp fie with shape type = PolyLine correctly.
* @throws IOException
*/
@Test
public void testLoadShapeFilePolyLine() throws IOException{
InputLocation = ShapefileRDDTest.class.getClassLoader().getResource("shapefiles/polyline").getPath();
// load shape with geotool.shapefile
File file = new File(InputLocation);
Map<String, Object> map = new HashMap<String, Object>();
map.put("url", file.toURI().toURL());
DataStore dataStore = DataStoreFinder.getDataStore(map);
String typeName = dataStore.getTypeNames()[0];
FeatureSource<SimpleFeatureType, SimpleFeature> source = dataStore
.getFeatureSource(typeName);
Filter filter = Filter.INCLUDE;
FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures(filter);
FeatureIterator<SimpleFeature> features = collection.features();
ArrayList<String> featureTexts = new ArrayList<String>();
while(features.hasNext()){
SimpleFeature feature = features.next();
featureTexts.add(String.valueOf(feature.getDefaultGeometry()));
}
final Iterator<String> featureIterator = featureTexts.iterator();
ShapefileRDD shapefileRDD = new ShapefileRDD(sc,InputLocation);
LineStringRDD spatialRDD = new LineStringRDD(shapefileRDD.getLineStringRDD());
try {
RangeQuery.SpatialRangeQuery(spatialRDD, new Envelope(-180,180,-90,90), false, false).count();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (Geometry geometry : shapefileRDD.getShapeRDD().collect()) {
Assert.assertEquals(featureIterator.next(), geometry.toText());
}
dataStore.dispose();
}
示例10: testLoadShapeFileMultiPoint
import org.geotools.data.DataStore; //導入方法依賴的package包/類
/**
* Test if shapeRDD load shape type = MultiPoint correctly.
* @throws IOException
*/
@Test
public void testLoadShapeFileMultiPoint() throws IOException{
InputLocation = ShapefileRDDTest.class.getClassLoader().getResource("shapefiles/multipoint").getPath();
// load shape with geotool.shapefile
File file = new File(InputLocation);
Map<String, Object> map = new HashMap<String, Object>();
map.put("url", file.toURI().toURL());
DataStore dataStore = DataStoreFinder.getDataStore(map);
String typeName = dataStore.getTypeNames()[0];
FeatureSource<SimpleFeatureType, SimpleFeature> source = dataStore
.getFeatureSource(typeName);
Filter filter = Filter.INCLUDE;
FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures(filter);
FeatureIterator<SimpleFeature> features = collection.features();
ArrayList<String> featureTexts = new ArrayList<String>();
while(features.hasNext()){
SimpleFeature feature = features.next();
featureTexts.add(String.valueOf(feature.getDefaultGeometry()));
}
final Iterator<String> featureIterator = featureTexts.iterator();
ShapefileRDD shapefileRDD = new ShapefileRDD(sc,InputLocation);
for (Geometry geometry : shapefileRDD.getShapeRDD().collect()) {
Assert.assertEquals(featureIterator.next(), geometry.toText());
}
dataStore.dispose();
}
示例11: example5
import org.geotools.data.DataStore; //導入方法依賴的package包/類
private static void example5() throws IOException, CQLException {
System.out.println("example5 start\n");
// example5 start
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put("directory", directory);
DataStore store = DataStoreFinder.getDataStore(params);
SimpleFeatureSource featureSource = store.getFeatureSource("example");
Filter filter = CQL.toFilter("name = 'dave'");
SimpleFeatureCollection features = featureSource.getFeatures(filter);
System.out.println("found :" + features.size() + " feature");
SimpleFeatureIterator iterator = features.features();
try {
while (iterator.hasNext()) {
SimpleFeature feature = iterator.next();
Geometry geometry = (Geometry) feature.getDefaultGeometry();
System.out.println(feature.getID() + " location " + geometry);
}
} catch (Throwable t) {
iterator.close();
}
// example5 end
System.out.println("\nexample5 end\n");
}
示例12: testEmpty
import org.geotools.data.DataStore; //導入方法依賴的package包/類
public void testEmpty()
throws Exception {
final SimpleFeatureType type = DataUtilities.createType(
"GeoWaveFeatureSourceTest_e",
"geometry:Geometry:srid=4326,pop:java.lang.Long,pid:String,when:Date");
final DataStore dataStore = createDataStore();
dataStore.createSchema(type);
final SimpleFeatureSource source = dataStore.getFeatureSource("GeoWaveFeatureSourceTest_e");
final ReferencedEnvelope env = source.getBounds();
assertEquals(
90.0,
env.getMaxX(),
0.0001);
assertEquals(
-180.0,
env.getMinY(),
0.0001);
final Query query = new Query(
"GeoWaveFeatureSourceTest_e",
Filter.INCLUDE);
assertEquals(
0,
source.getCount(query));
}
示例13: getFeatures
import org.geotools.data.DataStore; //導入方法依賴的package包/類
protected FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatures(URL baseUrl, HTTPClient client,
String typeName, Query query, WfsVersionDto version, String strategy) throws IOException, SAXException,
ParserConfigurationException, URISyntaxException {
URL url = URLBuilder.createWfsURL(baseUrl, version, "GetCapabilities");
String capa = url.toExternalForm();
Map<String, Serializable> connectionParameters = new HashMap<String, Serializable>();
connectionParameters.put(WFSDataStoreFactory.MAXFEATURES.key, query.getMaxFeatures());
connectionParameters.put(WFSDataStoreFactory.URL.key, capa);
connectionParameters.put(WFSDataStoreFactory.PROTOCOL.key, Boolean.TRUE);
if (strategy != null) {
connectionParameters.put(WFSDataStoreFactory.WFS_STRATEGY.key, strategy);
}
DataStore data = dataStoreFactory.createDataStore(connectionParameters, client);
SimpleFeatureSource features = data.getFeatureSource(typeName.replace(":", "_"));
return features.getFeatures(query);
}
示例14: getShapeFileFeatureCollection
import org.geotools.data.DataStore; //導入方法依賴的package包/類
/**
* Loads the shape file from the configuration path and returns the
* feature collection associated according to the configuration.
*
* @param shapePath with the path to the shapefile.
* @param featureString with the featureString to filter.
*
* @return FeatureCollection with the collection of features filtered.
*/
private FeatureCollection getShapeFileFeatureCollection(String shapePath, String featureString) throws IOException
{
File file = new File(shapePath);
// Create the map with the file URL to be passed to DataStore.
Map map = new HashMap();
try {
map.put("url", file.toURL());
} catch (MalformedURLException ex) {
Logger.getLogger(ShpConnector.class.getName()).log(Level.SEVERE, null, ex);
}
if (map.size() > 0) {
DataStore dataStore = DataStoreFinder.getDataStore(map);
FeatureSource featureSource = dataStore.getFeatureSource(featureString);
return featureSource.getFeatures();
}
return null;
}
示例15: save
import org.geotools.data.DataStore; //導入方法依賴的package包/類
/**
* Save the corresponding VDS into corresponding format [kmz,xml,ddbb]
* @param layer
* @param projection
*/
@Override
public void save(File output, String projection,GeoTransform transform) {
try {
//Data store to get access to ddbb
DataStore datastore = (DataStore) DataStoreFinder.getDataStore(config);
//Access to the corresponding VDS layer on ddbb f.i: 'VESSELS'
FeatureStore featurestore = (FeatureStore) datastore.getFeatureSource(layername);
SimpleFeatureType featuretype = (SimpleFeatureType) featurestore.getSchema();
/* @FIX I need explanation
impleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setName(featuretype.getName());
builder.setCRS(featuretype.getCoordinateReferenceSystem());
System.out.println(featuretype.getDescriptors().size());
//build the type
//SimpleFeatureType type = builder.buildFeatureType();
// System.out.println(type.getDescriptors().size());
//*/
FeatureCollection features = createFeatures(featuretype, glayer, projection, gir.getGeoTransform());
featurestore.addFeatures(features);
writeToDB(datastore, features);
datastore.dispose();
} catch (Exception ex) {
logger.error(ex.getMessage(),ex);
}
}