我正在尝试使用GeoTools库编写/编辑我的shapefile属性。
File file = new File("U:/xyz.shp");
Map<String, Serializable> map = new HashMap<>();
map.put( "url", file.toURI().toURL() );
DataStore dataStore = DataStoreFinder.getDataStore( map );
String typeName = dataStore.getTypeNames()[0];
System.out.println( typeName );
FeatureSource source = dataStore.getFeatureSource( typeName );
FeatureCollection collection = source.getFeatures();
FeatureIterator<SimpleFeature> results = collection.features();
try {
while (results.hasNext()) {
SimpleFeature feature = (SimpleFeature) results.next();
feature.setAttribute("FIELD_NAME","NEW_NAME");
//FIELD_NAME is the name of the attribute
//NEW_NAME is the modified value oif the attribute
}
} finally {
results.close();
}
这确实会更改 SimpleFeature 类对象功能中的属性值,但不会将其更新为实际的shapefile。 有人能告诉我哪里出错了。 谢谢。