I have a shapefile with some polygons. I would like to change the height for this elements using Java. The rest of the attributes should be the same. I've thought using GeoTools but I haven't found how to implement this.

Any help?

1 Answer 1


The following is assuming that you know how to read and write a FeatureCollection in geotools.

SimpleFeatureCollection inVector = "read it"
SimpleFeatureCollection outVector = FeatureCollections.newCollection();
String elevationFieldName = "elev";

int size = inVector.size();
FeatureIterator<SimpleFeature> inFeatureIterator = inVector.features();
while( inFeatureIterator.hasNext() ) {
    SimpleFeature feature = inFeatureIterator.next();
    feature.setAttribute(elevationFieldName, yourNewElevation);

Then just write outVector to a new shapefile.

Reading and writing is covered in the tutorials: http://docs.geotools.org/latest/userguide/tutorial/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.