本文整理匯總了Java中org.geotools.data.simple.SimpleFeatureSource.getFeatures方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleFeatureSource.getFeatures方法的具體用法?Java SimpleFeatureSource.getFeatures怎麽用?Java SimpleFeatureSource.getFeatures使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.geotools.data.simple.SimpleFeatureSource
的用法示例。
在下文中一共展示了SimpleFeatureSource.getFeatures方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: exportUAZ
import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的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;
}
示例2: getWifUAZfromShpFile
import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
/**
* Gets the wif ua zfrom shp file.
*
* @param uAZShpURL
* the u az shp url
* @return the wif ua zfrom shp file
*/
public SimpleFeatureCollection getWifUAZfromShpFile(final URL uAZShpURL) {
LOGGER.info("uAZShpURL FilePath: {} ", uAZShpURL.getFile());
SimpleFeatureCollection uazFeatureCollection = FeatureCollections
.newCollection();
FileDataStore storeUD;
try {
storeUD = openFileDataStore(uAZShpURL.getFile());
final SimpleFeatureSource featureSourceUD = storeUD.getFeatureSource();
uazFeatureCollection = featureSourceUD.getFeatures();
LOGGER.debug("featureCollection size : {} ", uazFeatureCollection.size());
} catch (final IOException e) {
LOGGER.error("getWifUAZfromShpFile ", e.getMessage());
}
return uazFeatureCollection;
}
示例3: getWifUAZfromDB
import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的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;
}
示例4: zipFileToPostGIS
import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
/**
* Zip file to post gis.
*
* @param shpFile
* the shp file
* @return the simple feature collection
* @throws ShapeFile2PostGISCreationException
* the shape file2 post gis creation exception
*/
public SimpleFeatureCollection zipFileToPostGIS(final File shpFile)
throws ShapeFile2PostGISCreationException {
final String msg = "Converting shape file operation failed...";
try {
final FileDataStore store = FileDataStoreFinder.getDataStore(shpFile);
final SimpleFeatureSource featureSource = store.getFeatureSource();
final SimpleFeatureCollection features = featureSource.getFeatures();
LOGGER.info("Shape filename = {}", featureSource.getSchema()
.getTypeName());
final CoordinateReferenceSystem crs = featureSource.getSchema()
.getCoordinateReferenceSystem();
validatorCRS.validateSimple(crs, msg);
return features;
} catch (final Exception e) {
LOGGER.error(msg, e.getMessage());
throw new ShapeFile2PostGISCreationException(msg, e);
}
}
示例5: simpleTest
import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
@Test
public void simpleTest() throws WorkflowException, IOException {
chain.execute(ctx);
assertTrue(ctx.getStatusElements().containsKey(WRITER_ID));
assertEquals(WorkflowStatus.Status.COMPLETED,
ctx.getStatusElements().get(WRITER_ID).getCurrentStatus());
SimpleFeatureSource featureSource = store.getFeatureSource(TestUtils.SAMPLE_FEATURE_NAME);
FeatureCollection fc = featureSource.getFeatures();
assertEquals(1, fc.size());
SimpleFeature readFeature = (SimpleFeature) fc.features().next();
assertEquals(TestUtils.SAMPLE_FEATURE_NAME, readFeature.getName().getLocalPart());
assertEquals("value0", readFeature.getAttribute("prop0"));
assertEquals(100.0, readFeature.getAttribute("prop1"));
assertTrue(readFeature.getAttribute("geometry") instanceof Point);
}
示例6: stripFeatureIDTest
import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
/**
* Test a chain of Actions to:
*
* - Read a GeoJSON
* - Manipulate the FeatureID stripping out the prefix, leaving only the ID
* - Store the modified Feature
*
* @throws WorkflowException
* @throws IOException
*/
@Test
public void stripFeatureIDTest() throws WorkflowException, IOException {
sequence_wo_email.execute(ctx);
assertTrue(ctx.getStatusElements().containsKey(WRITER_ID));
assertEquals(WorkflowStatus.Status.COMPLETED,
ctx.getStatusElements().get(WRITER_ID).getCurrentStatus());
SimpleFeatureSource featureSource = store.getFeatureSource(TestUtils.SAMPLE_FEATURE_NAME);
FeatureCollection fc = featureSource.getFeatures();
assertEquals(1, fc.size());
SimpleFeature readFeature = (SimpleFeature) fc.features().next();
assertEquals(TestUtils.SAMPLE_FEATURE_NAME, readFeature.getName().getLocalPart());
assertEquals("noto ", readFeature.getAttribute("RESPONSABILE_ABBANDONO"));
assertEquals("08/ott/2014", readFeature.getAttribute("DATA_AGG"));
assertEquals("42", readFeature.getAttribute("CIVICO"));
// the feature ID cannot be specified before the insert into the featureStore
// the feature ID is ignored and another one is created
//assertEquals("46", readFeature.getID());
assertTrue(readFeature.getAttribute("geometry") instanceof Point);
}
示例7: readFeatureCollection
import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
@Execute
public void readFeatureCollection() throws IOException {
if (!concatOr(geodata == null, doReset)) {
return;
}
try {
File shapeFile = new File(file);
pm.beginTask("Reading features from shapefile: " + shapeFile.getName(), -1);
FileDataStore store = FileDataStoreFinder.getDataStore(shapeFile);
SimpleFeatureSource featureSource = store.getFeatureSource();
geodata = featureSource.getFeatures();
store.dispose();
} finally {
pm.done();
}
}
示例8: example5
import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的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");
}
示例9: getFeatures
import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的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);
}
示例10: createLayer
import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
/**
*
* @param shpInput
* @param transform
* @return
*/
public static GeometryImage createLayer(File shpInput,GeoTransform transform) {
GeometryImage out=null;
try {
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put("url", shpInput.toURI().toURL());
//create a DataStore object to connect to the physical source
DataStore dataStore = DataStoreFinder.getDataStore(params);
//retrieve a FeatureSource to work with the feature data
SimpleFeatureSource featureSource = (SimpleFeatureSource) dataStore.getFeatureSource(dataStore.getTypeNames()[0]);
SimpleFeatureCollection fc=featureSource.getFeatures();
if (fc.isEmpty()) {
return null;
}
String[] schema = createSchema(fc.getSchema().getDescriptors());
String[] types = createTypes(fc.getSchema().getDescriptors());
String geoName = fc.getSchema().getGeometryDescriptor().getType().getName().toString();
out=GeometryImage.createLayerFromFeatures(geoName, dataStore,fc , schema, types,true ,transform);
dataStore.dispose();
//glout = GeometricLayer.createImageProjectedLayer(out, transform,null);
} catch (Exception ex) {
logger.error(ex.getMessage(),ex);
}
return out;
}
示例11: mergeShapeFile2
import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
/**
*
* @param collectionsLayer
* @param shpInput
* @param transform
* @param bbox
* @return
* @throws Exception
*/
public static GeometryImage mergeShapeFile2(SimpleFeatureCollection collectionsLayer, File shpInput,GeoTransform transform,Polygon bbox)throws Exception {
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put("url", shpInput.toURI().toURL());
//create a DataStore object to connect to the physical source
DataStore dataStore = DataStoreFinder.getDataStore(params);
//retrieve a FeatureSource to work with the feature data
SimpleFeatureSource shape2 = (SimpleFeatureSource) dataStore.getFeatureSource(dataStore.getTypeNames()[0]);
ClipProcess clip=new ClipProcess();
SimpleFeatureCollection collectionsShape2=shape2.getFeatures();
SimpleFeatureCollection fc=clip.execute(collectionsShape2, bbox,true);
SimpleFeatureSource source = new CollectionFeatureSource(fc);
SimpleFeatureCollection result=joinFeaures(source, shape2);
//create new datastore to save the new shapefile
FileDataStoreFactorySpi factory = new ShapefileDataStoreFactory();
File tmp=new File(SumoPlatform.getApplication().getCachePath()+"\\tmpshape_"+System.currentTimeMillis()+".shp");
Map<String, Serializable> params2 = new HashMap<String, Serializable>();
params2.put("url", tmp.toURI().toURL());
ShapefileDataStore newds=(ShapefileDataStore)factory.createNewDataStore(params2);
String geoName = collectionsLayer.getSchema().getGeometryDescriptor().getType().getName().toString();
//String nameOutput="merge_"+shpInput.getName()+"_"+LayerManager.getIstanceManager().getCurrentImageLayer().getName();
//from here create the new GeometricLayer
Collection<PropertyDescriptor>descriptorsMerge=new ArrayList<>();
descriptorsMerge.addAll(shape2.getSchema().getDescriptors());
descriptorsMerge.addAll(collectionsLayer.getSchema().getDescriptors());
String[] schema = createSchema(descriptorsMerge);
String[] types = createTypes(descriptorsMerge);
GeometryImage out=GeometryImage.createLayerFromFeatures(geoName, newds, result, schema, types,true,transform);
return out;
}
示例12: joinFeaures
import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
/**
*
* @param shapes
* @param shapes2
* @throws Exception
*/
private static SimpleFeatureCollection joinFeaures(SimpleFeatureSource shapes, SimpleFeatureSource shapes2) throws Exception {
SimpleFeatureCollection join =null;
SimpleFeatureType schema = shapes.getSchema();
String typeName = schema.getTypeName();
String geomName = schema.getGeometryDescriptor().getLocalName();
SimpleFeatureType schema2 = shapes2.getSchema();
String typeName2 = schema2.getTypeName();
String geomName2 = schema2.getGeometryDescriptor().getLocalName();
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
Query outerGeometry = new Query(typeName, Filter.INCLUDE, new String[] { geomName });
SimpleFeatureCollection outerFeatures = shapes.getFeatures(outerGeometry);
SimpleFeatureIterator iterator = outerFeatures.features();
int max = 0;
try {
while (iterator.hasNext()) {
SimpleFeature feature = iterator.next();
try {
Geometry geometry = (Geometry) feature.getDefaultGeometry();
if (!geometry.isValid()) {
// skip bad data
continue;
}
Filter innerFilter = ff.intersects(ff.property(geomName2), ff.literal(geometry));
Query innerQuery = new Query(typeName2, innerFilter, Query.NO_NAMES);
join = shapes2.getFeatures(innerQuery);
int size = join.size();
max = Math.max(max, size);
} catch (Exception skipBadData) {
}
}
} finally {
iterator.close();
}
return join;
}
示例13: getFeatureCollection
import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
/**
* Gets the feature collection.
*
* @return the feature collection
*/
public SimpleFeatureCollection getFeatureCollection() {
SimpleFeatureCollection featureCollection = null;
try {
if(dataStore != null)
{
SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
featureCollection = source.getFeatures();
}
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
return featureCollection;
}
示例14: getFeatureCollection
import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
/**
* Gets the feature collection.
*
* @return the feature collection
*/
public SimpleFeatureCollection getFeatureCollection() {
SimpleFeatureCollection featureCollection = null;
try {
if (dataStore != null) {
SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
featureCollection = source.getFeatures();
}
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
return featureCollection;
}
示例15: load
import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
public void load (ShapeDataStore store) throws Exception {
FileDataStore fds = FileDataStoreFinder.getDataStore(shapefile);
SimpleFeatureSource src = fds.getFeatureSource();
Query q = new Query();
q.setCoordinateSystem(src.getInfo().getCRS());
q.setCoordinateSystemReproject(CRS.decode("EPSG:4326", true));
SimpleFeatureCollection sfc = src.getFeatures(q);
for (SimpleFeatureIterator it = sfc.features(); it.hasNext();) {
GeobufFeature feat = new GeobufFeature(it.next());
feat.id = null;
feat.numericId = Long.parseLong((String) feat.properties.get("GEOID10"));
feat.properties = new HashMap<>();
store.add(feat);
}
}