Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to colorized geometries from shapefiles and convert them to raster image (geotiff).

I tried to use geotools's VectorToRasterProcess and ImageWorker ("d:\gis\tmp\32 27 25 w4.shp" is path to my test shapefile):

URL url =  new File("d:\\gis\\tmp\\32 27 25 w4.shp").toURI().toURL();
ShapefileDataStore ds = new ShapefileDataStore(url);
FeatureSource fs = ds.getFeatureSource("32%2027%2025%20w4");

GridCoverage2D raster = VectorToRasterProcess.process(fs.getFeatures(),
     "ID", new Dimension(400, 400), fs.getBounds(),"test", null);

ImageWorker imageWorker = new ImageWorker(raster.getRenderedImage());
imageWorker = imageWorker.rescaleToBytes();

raster = new GridCoverageFactory().create("one", imageWorker.getRenderedImage(),  fs.getBounds());

GeoTiffWriter writer = new GeoTiffWriter(output);
GeoTiffWriteParams params = new GeoTiffWriteParams();
ParameterValue<GeoToolsWriteParams> value = GeoTiffFormat.GEOTOOLS_WRITE_PARAMS.createValue();
writer.write(raster, new GeneralParameterValue[]{value});

The result geotiff is here

What is not right in my configuration of ImageWorker? Give, please, some advices.

Regards, Dmitry

share|improve this question

Your Answer


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

Browse other questions tagged or ask your own question.