CREATE RASTER PYRAMID / OVERVIEW COMPATIBLE WITH ERDAS IMAGINE

Pyramid layers are image layers generated in low resolution for quick rendering at low zoom. Also known as overviews, these layers can be created externally as well as internally. Creating it externally is preferred since internal pyramid cannot be removed unless we create a new image file. In this blog, we will create pyramid layers externally up to 8 layers in .aux format which is compatible with Erdas Imagine software. The default format of pyramid layer in GDAL is .ovr.

We will create the pyramid layer of an raster image at D:\bluemarbel\A.tif. The java code is shown below:


package pyramidGenerator;
import org.gdal.gdal.*;
import org.gdal.gdalconst.*;

public class PyramidGenerator {
    public static void main(String[] args) {
		//Register GDAL
        gdal.AllRegister();
		
		//Validate input raster and number of pyramid layers as arguments
        if(args.length<1 || args.length>2){
            System.out.println ("Please provide input image location as first argument and saving location as second argument/n"+
                    "eg: java -jar PyramidGenerator.jar \"D:\\bluemarbel\\A.tif\" 8");
            System.exit(1);
        }
		
        //Read Input raster
		Dataset dataset = gdal.Open(args[0], gdalconstConstants.GA_ReadOnly);
		
		if (dataset==null){
            System.out.println ("Could not open image file");
            System.exit(1);
        }
		
		//Read and parse the number of pyramid layers
		String pyramid = args[1];
		
		int p = 1;
		int x = 0;
		
        try{
			p = Integer.parseInt(pyramid);
		}catch(NumberFormatException e){
			System.out.println("Second argument has to be number. Try again!!!");
			System.exit(1);
		}
		
		int[] py = new int[p];
		
		//Create pyramid array
        while(x < p){
			py[p++] = 2 * p;
		}
		
        //Set GDAL Config for compatibility with Erdas Imagine
        
		gdal.SetConfigOption("USE_RRD", "YES");
		
        //Generate pyramid and check for error
        if (dataset.BuildOverviews(py, new TermProgressCallback()) != gdalconst.CE_None)
            {
                System.out.println("The BuildOverviews operation doesn't work");
                System.exit(-1);
            }
		
     dataset.delete();
    }
}

The above code is valid for all raster images which has any radiometry. The generated pyramid layers work both with GDAL as well as Erdas

QUICK LINKS
Coordinates

Earth Shape

Ellipsoid & Geoid

Datum

Projection

UTM

Rasters

Vectors
GDAL

GDAL Setup

GDAL Rasters

GDAL Vectors

GDAL Tools
WMS

MS4W

Spatial DB

Oracle Spatial

SDO_GEOMETRY

Geo-Crawler
Web Clients

Openlayers

OL3

Closest Distance Map

Openlayers v2.x

ThreeJS

Terrain Viewer

Bluemarble (250m tiff)

JS Tools

Geographiclib

JS2Shapefile

CSV2Shape


GeoSpatialEarth.in Copyright © All rights reserved.