TransWikia.com

Speeding up rendering of GeoTiff images

Geographic Information Systems Asked on April 9, 2021

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'

One Answer

As discussed by Paul Ramsey as well as compressing and tiling the images you need to provide overviews to save GeoTools (and other programs) from having to read the whole file when you are zoomed out.

Use gdaladdo to add overviews:

gdaladdo 
  --config COMPRESS_OVERVIEW JPEG 
  --config PHOTOMETRIC_OVERVIEW YCBCR 
  --config INTERLEAVE_OVERVIEW PIXEL 
  -r average 
  5255C_JPEG_YCBCR.tif 
  2 4 8 16

Answered by Ian Turton on April 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP