使用GeoTools编写shapefile

时间:2016-02-29 13:17:56

标签: java gis shapefile geotools

我正在尝试使用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。 有人能告诉我哪里出错了。 谢谢。

0 个答案:

没有答案