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?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityI 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?
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/