Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

Thanks in advance

share|improve this question
add comment

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);
    outVector.add(feature);
}
inFeatureIterator.close();

Then just write outVector to a new shapefile.

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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