Friday, 4 August 2017

java - Modifying feature attributes of a shapefile in geotools



I have a shapefile with an attribute I want to compute programmatically in Java for each feature. I have found a lot of documentation on how to read and create shapefiles with geotools (http://docs.geotools.org/stable/userguide/library/data/shape.html http://osgeo-org.1560.x6.nabble.com/Add-an-attribute-to-all-the-features-of-a-shape-file-td4318371.html), but no documentation on how to modify an attribute.


So far, I am loading the shapefile data into a FeatureCollection, and modifying each feature attribute with:


myFeature.setAttribute("ATTRIBUTE", myAttributeValue);

but these modifications are not stored into the shapefile (only in memory I guess).


Is there a way to make these modification persistent into the shapefile? Maybe there is a more standard and simple way to update feature attribute with geotools. The only thing I would like to avoid is to re-create a new shapefile.




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...