本文整理匯總了Java中org.geotools.data.simple.SimpleFeatureSource類的典型用法代碼示例。如果您正苦於以下問題:Java SimpleFeatureSource類的具體用法?Java SimpleFeatureSource怎麽用?Java SimpleFeatureSource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SimpleFeatureSource類屬於org.geotools.data.simple包,在下文中一共展示了SimpleFeatureSource類的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: updateUAZArea
import org.geotools.data.simple.SimpleFeatureSource; //導入依賴的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);
}
}
示例5: getFeatureSourcefromDB
import org.geotools.data.simple.SimpleFeatureSource; //導入依賴的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);
}
}
示例6: getFeatureStorefromDB
import org.geotools.data.simple.SimpleFeatureSource; //導入依賴的package包/類
/**
* Gets the feature storefrom db.
*
* @param uazTbl
* the uaz tbl
* @return the feature storefrom db
* @throws WifInvalidInputException
* the wif invalid input exception
*/
public SimpleFeatureStore getFeatureStorefromDB(final String uazTbl)
throws WifInvalidInputException {
LOGGER.info("getFeatureStorefromDB for table : {}", uazTbl);
SimpleFeatureSource featureSourceUD;
featureSourceUD = getFeatureSourcefromDB(uazTbl);
if (featureSourceUD instanceof SimpleFeatureStore) {
LOGGER.info("UAZ featureSource Name: {} ", featureSourceUD.getName());
return (SimpleFeatureStore) featureSourceUD;
} else {
throw new WifInvalidInputException(
"table doesn't have write priviledges " + uazTbl);
}
}
示例7: 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);
}
}
示例8: run
import org.geotools.data.simple.SimpleFeatureSource; //導入依賴的package包/類
@Override
public void run() {
final Display display = WorkbenchHelper.getDisplay();
final Shell shell = new Shell(display);
final File openFile = JFileDataStoreChooser.showOpenFile(new String[] { "*.shp" }, shell); //$NON-NLS-1$
try {
if (openFile != null && openFile.exists()) {
final MapContent mapContent = mapPane.getMapContent();
final FileDataStore store = FileDataStoreFinder.getDataStore(openFile);
final SimpleFeatureSource featureSource = store.getFeatureSource();
final Style style = Utils.createStyle(openFile, featureSource);
final FeatureLayer featureLayer = new FeatureLayer(featureSource, style);
mapContent.addLayer(featureLayer);
mapPane.redraw();
}
} catch (final IOException e) {
e.printStackTrace();
}
}
示例9: OSMInfo
import org.geotools.data.simple.SimpleFeatureSource; //導入依賴的package包/類
public OSMInfo(final URL url, final long modificationStamp) {
super(modificationStamp);
CoordinateReferenceSystem crs = null;
ReferencedEnvelope env2 = new ReferencedEnvelope();
int number = 0;
try {
final File f = new File(url.toURI());
final GamaOsmFile osmfile = new GamaOsmFile(null, f.getAbsolutePath());
attributes.putAll(osmfile.getOSMAttributes(GAMA.getRuntimeScope()));
final SimpleFeatureType TYPE = DataUtilities.createType("geometries", "geom:LineString");
final ArrayList<SimpleFeature> list = new ArrayList<SimpleFeature>();
for (final IShape shape : osmfile.iterable(null)) {
list.add(SimpleFeatureBuilder.build(TYPE, new Object[] { shape.getInnerGeometry() }, null));
}
final SimpleFeatureCollection collection = new ListFeatureCollection(TYPE, list);
final SimpleFeatureSource featureSource = DataUtilities.source(collection);
env2 = featureSource.getBounds();
number = osmfile.nbObjects;
crs = osmfile.getOwnCRS(null);
} catch (final Exception e) {
System.out.println("Error in reading metadata of " + url);
hasFailed = true;
} finally {
// approximation of the width and height in meters.
width = env2 != null ? env2.getWidth() * (FastMath.PI / 180) * 6378137 : 0;
height = env2 != null ? env2.getHeight() * (FastMath.PI / 180) * 6378137 : 0;
itemNumber = number;
this.crs = crs;
}
}
示例10: 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);
}
示例11: 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);
}
示例12: createCoastlineLayer
import org.geotools.data.simple.SimpleFeatureSource; //導入依賴的package包/類
private static Layer createCoastlineLayer() {
try {
// File file = new File(
// "/home/dxm/Downloads/shapefile-australia-coastline-polygon/cstauscd_r.shp");
File file = new File("src/main/resources/shapes/countries.shp");
FileDataStore store = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource featureSource = store.getFeatureSource();
// Style style = SLD.createSimpleStyle(featureSource.getSchema());
Style style = SLD.createPolygonStyle(Color.black, new Color(242, 237, 206), 1);
Layer layer = new FeatureLayer(featureSource, style);
return layer;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例13: 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();
}
}
示例14: writeShapefile
import org.geotools.data.simple.SimpleFeatureSource; //導入依賴的package包/類
private void writeShapefile(MemoryDataStore memoryDataStore, File outputFile) throws Exception {
SimpleFeatureSource featureSource = memoryDataStore.getFeatureSource(memoryDataStore.getTypeNames()[0]);
SimpleFeatureType featureType = featureSource.getSchema();
Map<String, java.io.Serializable> creationParams = new HashMap<String, java.io.Serializable>();
creationParams.put("url", DataUtilities.fileToURL(outputFile));
ShapefileDataStoreFactory factory = (ShapefileDataStoreFactory) FileDataStoreFinder.getDataStoreFactory("shp");
ShapefileDataStore dataStore = (ShapefileDataStore) factory.createNewDataStore(creationParams);
dataStore.setCharset(Charset.forName("UTF-8"));
dataStore.createSchema(featureType);
SimpleFeatureStore featureStore = (SimpleFeatureStore) dataStore.getFeatureSource(dataStore.getTypeNames()[0]);
Transaction transaction = new DefaultTransaction();
try {
SimpleFeatureCollection collection = featureSource.getFeatures();
featureStore.addFeatures(collection);
transaction.commit();
} catch (IOException e) {
try {
transaction.rollback();
throw new Exception("Failed to commit data to feature store", e);
} catch (IOException e2 ) {
logger.error("Failed to commit data to feature store", e);
throw new Exception("Transaction rollback failed", e2);
}
} finally {
transaction.close();
}
}
示例15: main
import org.geotools.data.simple.SimpleFeatureSource; //導入依賴的package包/類
/**
* This method demonstrates using a memory-based cache to speed up the display (e.g. when
* zooming in and out).
*
* There is just one line extra compared to the main method, where we create an instance of
* CachingFeatureStore.
*/
public static void main(String[] args) throws Exception {
// display a data store file chooser dialog for shapefiles
File file = JFileDataStoreChooser.showOpenFile("shp", null);
if (file == null) {
return;
}
FileDataStore store = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource featureSource = store.getFeatureSource();
CachingFeatureSource cache = new CachingFeatureSource(featureSource);
// Create a map content and add our shapefile to it
MapContent map = new MapContent();
map.setTitle("Using cached features");
Style style = SLD.createSimpleStyle(featureSource.getSchema());
Layer layer = new FeatureLayer(cache, style);
map.addLayer(layer);
// Now display the map
JMapFrame.showMap(map);
}