I use the GeoTools API to read and render a compressed JPEG GeoTiff file:
AbstractGridFormat format = new GeoTiffFormat(); format.accepts(rasterFile); //this is a bit hacky but does make more geotiffs work Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); // InputStream stream = new BufferedInputStream(new FileInputStream(rasterFile), 40*1024); reader = format.getReader(rasterFile, hints); // Initially display the raster in greyscale using the // data from the first image band Style rasterStyle = createGreyscaleStyle(1); // Connect to the shapefile FileDataStore dataStore = FileDataStoreFinder.getDataStore(shpFile); SimpleFeatureSource shapefileSource = dataStore .getFeatureSource(); // Create a basic style with yellow lines and no fill Style shpStyle = SLD.createPolygonStyle(Color.YELLOW, null, 0.0f); // Set up a MapContent with the two layers final MapContent map = new MapContent(); map.setTitle("ImageLab"); Layer rasterLayer = new GridReaderLayer(reader, rasterStyle); map.addLayer(rasterLayer);
The issue is that for bigger GeoTiff Files (e.g. file size 30 MB) the rendering takes a couple of seconds on an up to date machine, this is especially problematic if the user uses functions, like zooming.
Is there any way to use the API differently to speed up the process ? I did a rough profiling but only have seen that the renderer works a couple of seconds if the image gets refreshed.
The GeoTiff was created with gdal
gdal_translate -of GTiff -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR -co TILED=yes -a_srs EPSG:4326'