本文整理汇总了Java中org.opengis.feature.simple.SimpleFeature类的典型用法代码示例。如果您正苦于以下问题:Java SimpleFeature类的具体用法?Java SimpleFeature怎么用?Java SimpleFeature使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleFeature类属于org.opengis.feature.simple包,在下文中一共展示了SimpleFeature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadShapeFile
import org.opengis.feature.simple.SimpleFeature; //导入依赖的package包/类
public void loadShapeFile(String shapefileName) {
try {
File shapefile = new File(shapefileName);
Map<String, Object> shapefileParams = Maps.newHashMap();
shapefileParams.put("url", shapefile.toURI().toURL());
DataStore dataStore = DataStoreFinder.getDataStore(shapefileParams);
if (dataStore == null)
throw new RuntimeException("couldn't load the damn data store: " + shapefile);
String typeName = dataStore.getTypeNames()[0];
FeatureSource<SimpleFeatureType, SimpleFeature> source = dataStore.getFeatureSource(typeName);
Filter filter = Filter.INCLUDE;
FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures(filter);
try (FeatureIterator<SimpleFeature> features = collection.features()) {
while (features.hasNext()) {
SimpleFeature feature = features.next();
GeoInfo geoInfo = GeoInfo.fromSimpleFeature(feature);
qt.insert(GeoUtils.getBoundingRectangleAsEnvelope(geoInfo.multiPolygon),
geoInfo);
}
}
System.err.printf("loaded shapefile %s\n", shapefile);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
示例2: correctFeatures
import org.opengis.feature.simple.SimpleFeature; //导入依赖的package包/类
public static SimpleFeatureCollection correctFeatures(SimpleFeatureCollection fc){
SimpleFeatureIterator iterator=fc.features();
DefaultFeatureCollection outVector = new DefaultFeatureCollection();
while(iterator.hasNext()){
SimpleFeature sf=iterator.next();
Geometry gm=(Geometry)sf.getDefaultGeometry();
if(!gm.isValid()){
gm=JTSUtil.repair(gm);
System.out.println(gm.isValid());
}
sf.setDefaultGeometry(gm);
outVector.add(sf);
}
return fc;
}
示例3: read
import org.opengis.feature.simple.SimpleFeature; //导入依赖的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");
}
示例4: exportFeaturesToShapeFile
import org.opengis.feature.simple.SimpleFeature; //导入依赖的package包/类
public static void exportFeaturesToShapeFile(File fileOutput,FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection){
DataStore data =null;
try {
if (!fileOutput.exists()){
fileOutput.createNewFile();
fileOutput.setWritable(true);
}
FileDataStoreFactorySpi factory = new ShapefileDataStoreFactory();
data = factory.createDataStore( fileOutput.toURI().toURL() );
data.createSchema(featureCollection.getSchema());
exportToShapefile(data,featureCollection);
} catch (Exception e) {
logger.error("Export to shapefile failed",e );
}finally{
if(data!=null)
data.dispose();
}
}
示例5: createCorrectFeatureCollection
import org.opengis.feature.simple.SimpleFeature; //导入依赖的package包/类
private SimpleFeatureCollection createCorrectFeatureCollection(FeatureCollection<?, ?> fc) {
List<SimpleFeature> simpleFeatureList = new ArrayList<SimpleFeature>();
SimpleFeatureType featureType = null;
FeatureIterator<?> iterator = fc.features();
String uuid = UUID.randomUUID().toString();
int i = 0;
while (iterator.hasNext()) {
SimpleFeature feature = (SimpleFeature) iterator.next();
//if (i == 0) {
featureType = gtHelper.createFeatureType(feature.getProperties(), (Geometry) feature.getDefaultGeometry(), uuid, feature.getFeatureType().getCoordinateReferenceSystem());
QName qname = gtHelper.createGML3SchemaForFeatureType(featureType);
SchemaRepository.registerSchemaLocation(qname.getNamespaceURI(), qname.getLocalPart());
//}
SimpleFeature resultFeature = gtHelper.createFeature("ID" + i, (Geometry) feature.getDefaultGeometry(), featureType, feature.getProperties());
simpleFeatureList.add(resultFeature);
i++;
}
iterator.close();
ListFeatureCollection resultFeatureCollection = new ListFeatureCollection(featureType, simpleFeatureList);
return resultFeatureCollection;
}
示例6: testCorrect3857Transform
import org.opengis.feature.simple.SimpleFeature; //导入依赖的package包/类
/**
* tests a coordinate transformation from epsg:4236 --> epsg:3857
*/
@Test
public void testCorrect3857Transform() {
algo.setTargetEPSG("EPSG:3857");
try {
algo.runAlgorithm();
FeatureCollection fc = algo.getResult();
FeatureIterator<?> featureIterator = fc.features();
SimpleFeature feature = (SimpleFeature) featureIterator.next();
Geometry geometry = (Geometry) feature.getDefaultGeometry();
Coordinate[] coords = geometry.getCoordinates();
assertEquals(5781631.60732, coords[0].x, 0.001);
assertEquals(1002058.9016, coords[0].y, 0.001);
assertEquals(5364555.78035, coords[1].x, 0.001);
assertEquals(908752.762799, coords[1].y, 0.001);
assertEquals(5810127.070382, coords[2].x, 0.001);
assertEquals(883747.339307, coords[2].y, 0.001);
assertEquals(5770326.33379, coords[3].x, 0.001);
assertEquals(861269.968343, coords[3].y, 0.001);
assertEquals(5581093.09574, coords[4].x, 0.001);
assertEquals(772727.762141, coords[4].y, 0.001);
} catch (Exception e) {
fail("Exception thrown: " + e.getMessage());
}
}
示例7: highlightSelectedPolygon
import org.opengis.feature.simple.SimpleFeature; //导入依赖的package包/类
/**
* hightlight the selected Polygon.
* @param polygonID the selected Polygon
*/
public void highlightSelectedPolygon(String polygonID) {
for (SimpleFeature simpleFeature : polygonFeatureCollection) {
String featureID = (String) simpleFeature.getAttribute("id");
if (featureID.equals(polygonID)) {
Style style =
createSelectedStyle(simpleFeature.getIdentifier());
org.geotools.map.Layer layer = null;
for (org.geotools.map.Layer layers : mapPane.getMapContent()
.layers()) {
String t = layers.getTitle();
if (t != null && t.equals(POLYGON_LAYER_TITLE)) {
layer = layers;
}
}
if (layer instanceof FeatureLayer) {
((FeatureLayer) layer).setStyle(style);
}
}
}
}
示例8: convertNodes
import org.opengis.feature.simple.SimpleFeature; //导入依赖的package包/类
public void convertNodes(String nodesOutputFile) {
Collection<SimpleFeature> nodeFeatures = new ArrayList<>();
PointFeatureFactory pointFeatureFactory = new PointFeatureFactory.Builder()
.setName("nodes")
.setCrs(MGC.getCRS(crs))
.addAttribute("id", String.class)
.addAttribute("inLinks", Double.class)
.addAttribute("outLinks", Double.class)
.create();
for(Node node : network.getNodes().values()) {
SimpleFeature f = pointFeatureFactory.createPoint(MGC.coord2Coordinate(node.getCoord()));
f.setAttribute("id", node.getId());
f.setAttribute("inLinks", node.getInLinks());
f.setAttribute("outLinks", node.getOutLinks());
nodeFeatures.add(f);
}
ShapeFileWriter.writeGeometries(nodeFeatures, nodesOutputFile);
}
示例9: CommunityAreas
import org.opengis.feature.simple.SimpleFeature; //导入依赖的package包/类
public CommunityAreas() {
communities = new HashMap<>();
try {
File f = new File(shapeFilePath);
ShapefileDataStore shapefile = new ShapefileDataStore(f.toURI().toURL());
SimpleFeatureIterator features = shapefile.getFeatureSource().getFeatures().features();
SimpleFeature shp;
while (features.hasNext()) {
shp = features.next();
int id = Integer.parseInt((String) shp.getAttribute("AREA_NUMBE"));
String name = (String) shp.getAttribute("COMMUNITY");
MultiPolygon boundary = (MultiPolygon) shp.getDefaultGeometry();
CommunityArea ca = new CommunityArea(id, name, boundary);
communities.put(id, ca);
}
features.close();
shapefile.dispose();
} catch (IOException e) {
e.printStackTrace();
}
}
示例10: testAllShapesArePolygon
import org.opengis.feature.simple.SimpleFeature; //导入依赖的package包/类
public void testAllShapesArePolygon() {
try {
SimpleFeatureIterator features = Tracts.getShapeFileFeatures();
SimpleFeature shp = features.next();
int fieldSize = shp.getType().getTypes().size();
assertEquals(fieldSize, 10);
assertEquals(shp.getType().getType(3).getName().getLocalPart(), "tractce10");
assertEquals(shp.getType().getType(0).getName().getLocalPart(), "MultiPolygon");
for (int i = 0; i < fieldSize; i++){
System.out.println(shp.getType().getType(i).getName().getLocalPart());
}
int cnt = 1;
while (features.hasNext()) {
shp = features.next();
MultiPolygon g = (MultiPolygon) shp.getDefaultGeometry();
cnt ++;
}
assertEquals(cnt, 801);
features.close();
Tracts.shapefile.dispose();
} catch (IOException e) {
e.printStackTrace();
}
}
示例11: buildTimedValuesFromFeature
import org.opengis.feature.simple.SimpleFeature; //导入依赖的package包/类
private List<TimedValue> buildTimedValuesFromFeature(Datasource datasource, SimpleFeature feature, Subject subject) {
List<TimedValue> timedValues = new ArrayList<>();
LocalDateTime modified;
try {
modified = getTimestampForFeature(feature);
} catch (ParsingException pe) {
log.warn("Unable to get timestamp for feature: {}", feature);
return timedValues;
}
for (Attribute attribute : datasource.getTimedValueAttributes()){
if (feature.getAttribute(attribute.getLabel()) == null)
continue;
Double value = Double.parseDouble(feature.getAttribute(attribute.getLabel()).toString());
timedValues.add(new TimedValue(subject, attribute, modified, value));
}
return timedValues;
}
开发者ID:FutureCitiesCatapult,项目名称:TomboloDigitalConnector,代码行数:18,代码来源:AbstractGeotoolsDataStoreImporter.java
示例12: importDatasource
import org.opengis.feature.simple.SimpleFeature; //导入依赖的package包/类
@Override
protected void importDatasource(Datasource datasource, List<String> geographyScope, List<String> temporalScope, List<String> datasourceLocation) throws Exception {
InputStream inputStream = downloadUtils.fetchInputStream(new URL(OaType.valueOf(datasource.getDatasourceSpec().getId()).datafile), getProvider().getLabel(), ".json");
FeatureIterator<SimpleFeature> featureIterator = new FeatureJSON().streamFeatureCollection(inputStream);
List<Subject> subjects = new ArrayList<Subject>();
while(featureIterator.hasNext()) {
Feature feature = featureIterator.next();
Geometry geometry = (Geometry) feature.getDefaultGeometryProperty().getValue();
geometry.setSRID(Subject.SRID);
subjects.add(new Subject(
datasource.getUniqueSubjectType(),
getFeatureSubjectLabel(feature),
getFeatureSubjectName(feature),
geometry
));
}
saveAndClearSubjectBuffer(subjects);
}
示例13: fromSimpleFeature
import org.opengis.feature.simple.SimpleFeature; //导入依赖的package包/类
public static GeoInfo fromSimpleFeature(SimpleFeature feature) {
GeoInfo that = new GeoInfo();
for (Property p: feature.getProperties()) {
if (p.getName().toString().equals("NAME"))
that.name = p.getValue().toString();
if (p.getName().toString().equals("STATE"))
that.state = p.getValue().toString();
if (p.getName().toString().equals("COUNTY"))
that.county = p.getValue().toString();
if (p.getName().toString().equals("CITY"))
that.city = p.getValue().toString();
}
that.multiPolygon = (MultiPolygon) feature.getDefaultGeometry();
return that;
}
示例14: getFeatures
import org.opengis.feature.simple.SimpleFeature; //导入依赖的package包/类
/**
* Gets the features.
*
* @return the features
*/
public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatures() {
FeatureSource<SimpleFeatureType, SimpleFeature> features = null;
try
{
if((schema != null) && (dataStore != null))
{
features = dataStore.getFeatureSource(schema.getName());
}
}catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
return features;
}
示例15: getFeatureStore
import org.opengis.feature.simple.SimpleFeature; //导入依赖的package包/类
/**
* Gets the feature store.
*
* @return the feature store
*/
public FeatureStore<SimpleFeatureType, SimpleFeature> getFeatureStore() {
FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = null;
if(dataStore != null)
{
try
{
FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = dataStore.getFeatureSource(typeName);
featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) featureSource;
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
}
return featureStore;
}