NASA World Wind

gov.nasa.worldwind.util.gdal
Class GDALUtils

java.lang.Object
  extended by gov.nasa.worldwind.util.gdal.GDALUtils

public class GDALUtils
extends Object


Field Summary
static long ALPHA_MASK
           
protected static byte ALPHA_OPAQUE
           
protected static byte ALPHA_TRANSPARENT
           
protected static CopyOnWriteArraySet<String> failedLibraries
           
protected static String GDAL_DATA_PATH
           
protected static String GDAL_DRIVER_PATH
           
protected static String gdalalljni
           
protected static AtomicBoolean gdalIsAvailable
           
protected static String JAVA_LIBRARY_PATH
           
protected static CopyOnWriteArraySet<String> loadedLibraries
           
protected static String OGR_DRIVER_PATH
           
 
Constructor Summary
GDALUtils()
           
 
Method Summary
protected static void alterJavaLibraryPath(String newJavaLibraryPath)
           
protected static void applyImageMask(byte[] alphaBand, IntBuffer maskBand)
           
protected static void applyImageMask(int[] alphaBand, IntBuffer maskBand)
           
protected static void applyImageMask(short[] alphaBand, IntBuffer maskBand)
           
protected static String buildPathString(String[] folders, boolean addDefaultValues)
           
static double[] calcGetGeoTransform(Sector sector, int width, int height)
          Calculates geo-transform matrix for a north-up raster
static boolean canOpen(Object source)
          Checks if a data raster can is readable
static DataRaster composeDataRaster(org.gdal.gdal.Dataset ds, AVList params)
           
protected static DataRaster composeImageDataRaster(org.gdal.gdal.Dataset ds, AVList params)
          Opens image or elevation file, returns as a BufferedImage (even for elevations)
protected static DataRaster composeNonImageDataRaster(org.gdal.gdal.Dataset ds, AVList params)
          The "composeDataRaster" method creates a ByteBufferRaster from an elevation (or non-image) Dataset.
protected static Double convertStringToDouble(String s)
           
static org.gdal.osr.SpatialReference createGeographicSRS()
           
protected static BufferedImage detectVoidsAndMakeThemTransparent(BufferedImage sourceImage)
          Attempts to detect if there are any black|white|gray voids (also called black skirts) i n the image raster caused by inaccurate clipping.
static int[] extractBandOrder(org.gdal.gdal.Dataset ds, AVList params)
           
protected static IntBuffer extractImageMask(AVList params)
           
protected static void extractMinMaxSampleValues(org.gdal.gdal.Dataset ds, org.gdal.gdal.Band band, AVList params)
           
static AVList extractRasterParameters(org.gdal.gdal.Dataset ds)
           
static AVList extractRasterParameters(org.gdal.gdal.Dataset ds, AVList params, boolean quickReadingMode)
          Extracts raster parameters to an AVList
protected static String findGdalDataFolder()
           
protected static String[] findGdalFolders()
           
protected static boolean gdalPreLoadNativeLibrary(boolean allowLogErrors)
           
protected static String getCurrentDirectory()
           
static String getErrorMessage()
           
protected static LatLon getLatLonForRasterPoint(double[] gt, int x, int y, org.gdal.osr.CoordinateTransformation ct)
           
protected static void initialize()
           
protected static boolean is32bitArchitecture()
           
protected static void listAllRegisteredDrivers()
           
static org.gdal.gdal.Dataset open(Object source)
          Opens image or elevation file, returns a DataSet object
static org.gdal.gdal.Dataset open(Object source, boolean isSilentMode)
          Opens image or elevation file, returns a DataSet object
protected static void replaceLibraryLoader()
           
protected static void restoreJavaLibraryPath()
           
protected static void scanFill(BufferedImage sourceImage)
           
protected static boolean setNoDataValue(org.gdal.gdal.Band band, Double nodata)
           
protected static BufferedImage verticalFlip(BufferedImage img)
          Flips image raster vertically
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALPHA_MASK

public static long ALPHA_MASK

ALPHA_OPAQUE

protected static byte ALPHA_OPAQUE

ALPHA_TRANSPARENT

protected static byte ALPHA_TRANSPARENT

failedLibraries

protected static final CopyOnWriteArraySet<String> failedLibraries

GDAL_DATA_PATH

protected static final String GDAL_DATA_PATH
See Also:
Constant Field Values

GDAL_DRIVER_PATH

protected static final String GDAL_DRIVER_PATH
See Also:
Constant Field Values

gdalalljni

protected static final String gdalalljni

gdalIsAvailable

protected static final AtomicBoolean gdalIsAvailable

JAVA_LIBRARY_PATH

protected static final String JAVA_LIBRARY_PATH
See Also:
Constant Field Values

loadedLibraries

protected static final CopyOnWriteArraySet<String> loadedLibraries

OGR_DRIVER_PATH

protected static final String OGR_DRIVER_PATH
See Also:
Constant Field Values
Constructor Detail

GDALUtils

public GDALUtils()
Method Detail

alterJavaLibraryPath

protected static void alterJavaLibraryPath(String newJavaLibraryPath)
                                    throws IllegalAccessException,
                                           NoSuchFieldException
Throws:
IllegalAccessException
NoSuchFieldException

applyImageMask

protected static void applyImageMask(byte[] alphaBand,
                                     IntBuffer maskBand)

applyImageMask

protected static void applyImageMask(int[] alphaBand,
                                     IntBuffer maskBand)

applyImageMask

protected static void applyImageMask(short[] alphaBand,
                                     IntBuffer maskBand)

buildPathString

protected static String buildPathString(String[] folders,
                                        boolean addDefaultValues)

calcGetGeoTransform

public static double[] calcGetGeoTransform(Sector sector,
                                           int width,
                                           int height)
                                    throws IllegalArgumentException
Calculates geo-transform matrix for a north-up raster

Parameters:
sector - Geographic area, a Sector
width - none-zero width of a raster
height - none-zero height of a raster
Returns:
an array of 6 doubles that contain a geo-transform matrix
Throws:
IllegalArgumentException - if sector is null, or raster size is zero

canOpen

public static boolean canOpen(Object source)
Checks if a data raster can is readable

Parameters:
source - the location of the local file, expressed as either a String path, a File, or a file URL.
Returns:
true, if source is readable

composeDataRaster

public static DataRaster composeDataRaster(org.gdal.gdal.Dataset ds,
                                           AVList params)
                                    throws IllegalArgumentException,
                                           WWRuntimeException
Throws:
IllegalArgumentException
WWRuntimeException

composeImageDataRaster

protected static DataRaster composeImageDataRaster(org.gdal.gdal.Dataset ds,
                                                   AVList params)
                                            throws IllegalArgumentException,
                                                   SecurityException,
                                                   WWRuntimeException
Opens image or elevation file, returns as a BufferedImage (even for elevations)

Parameters:
ds - GDAL's Dataset object
params - AVList of parameters
Returns:
DataRaster returns as a BufferedImage (even for elevations)
Throws:
IllegalArgumentException - if file is null
SecurityException - if file could not be read
WWRuntimeException - if GDAL library was not initialized

composeNonImageDataRaster

protected static DataRaster composeNonImageDataRaster(org.gdal.gdal.Dataset ds,
                                                      AVList params)
                                               throws IllegalArgumentException,
                                                      WWRuntimeException
The "composeDataRaster" method creates a ByteBufferRaster from an elevation (or non-image) Dataset.

Parameters:
ds - The GDAL dataset with data raster (expected only elevation raster); f or imagery rasters use composeImageDataRaster() method
params - , The AVList with properties (usually used to force projection info or sector)
Returns:
ByteBufferRaster as DataRaster
Throws:
IllegalArgumentException - if raster parameters (height, width, sector, etc) are invalid
WWRuntimeException - when invalid raster detected (like attempt to use the method for imagery raster)

convertStringToDouble

protected static Double convertStringToDouble(String s)

createGeographicSRS

public static org.gdal.osr.SpatialReference createGeographicSRS()
                                                         throws WWRuntimeException
Throws:
WWRuntimeException

detectVoidsAndMakeThemTransparent

protected static BufferedImage detectVoidsAndMakeThemTransparent(BufferedImage sourceImage)
Attempts to detect if there are any black|white|gray voids (also called black skirts) i n the image raster caused by inaccurate clipping. The algorithm checks each corner of the image and if it detects black|white|gray pixel, uses a scanline version of flood fill algorithm to make the area transparent. See more http://en.wikipedia.org/wiki/Flood_fill#Scanline_fill

Parameters:
sourceImage - a source image raster
Returns:
BufferedImage with voids (if detected) filled with a transparent pixel values

extractBandOrder

public static int[] extractBandOrder(org.gdal.gdal.Dataset ds,
                                     AVList params)
                              throws IllegalArgumentException,
                                     WWRuntimeException
Throws:
IllegalArgumentException
WWRuntimeException

extractImageMask

protected static IntBuffer extractImageMask(AVList params)

extractMinMaxSampleValues

protected static void extractMinMaxSampleValues(org.gdal.gdal.Dataset ds,
                                                org.gdal.gdal.Band band,
                                                AVList params)

extractRasterParameters

public static AVList extractRasterParameters(org.gdal.gdal.Dataset ds)
                                      throws IllegalArgumentException,
                                             WWRuntimeException
Throws:
IllegalArgumentException
WWRuntimeException

extractRasterParameters

public static AVList extractRasterParameters(org.gdal.gdal.Dataset ds,
                                             AVList params,
                                             boolean quickReadingMode)
                                      throws IllegalArgumentException,
                                             WWRuntimeException
Extracts raster parameters to an AVList

Parameters:
ds - A GDAL dataset
params - AVList to hold retrieved metadata, if null, a new instance will be created and returned as a return value
quickReadingMode - if quick reading mode is enabled GDAL will not spend much time on heavy calculations, like for example calculating Min/Max for entire elevation raster
Returns:
AVList with retrieved metadata
Throws:
IllegalArgumentException - when the passed dataset is null pr emtpy, or any of the dimension is 0
WWRuntimeException - if GDAL is not available, or a dataset contains no bands

The extractRasterParameters() sets next key/value pairs:

AVKey.WIDTH - the maximum width of the image

AVKey.HEIGHT - the maximum height of the image

AVKey.COORDINATE_SYSTEM - one of the next values: AVKey.COORDINATE_SYSTEM_SCREEN AVKey.COORDINATE_SYSTEM_GEOGRAPHIC AVKey.COORDINATE_SYSTEM_PROJECTED

AVKey.SECTOR - in case of Geographic CS, contains a regular Geographic Sector defined by lat/lon coordinates of corners in case of Projected CS, contains a bounding box of the area

AVKey.COORDINATE_SYSTEM_NAME

AVKey.PIXEL_WIDTH (Double) pixel size, UTM images usually specify 1 (1 meter); if missing and Geographic Coordinate System is specified will be calculated as LongitudeDelta/WIDTH

AVKey.PIXEL_HEIGHT (Double) pixel size, UTM images usually specify 1 (1 meter); if missing and Geographic Coordinate System is specified will be calculated as LatitudeDelta/HEIGHT

AVKey.ORIGIN (LatLon) specifies coordinate of the image's origin (one of the corners, or center) If missing, upper left corner will be set as origin

AVKey.DATE_TIME (0 terminated String, length == 20) if missing, current date & time will be used

AVKey.PIXEL_FORMAT required (valid values: AVKey.ELEVATION | AVKey.IMAGE } specifies weather it is a digital elevation model or image

AVKey.IMAGE_COLOR_FORMAT required if AVKey.PIXEL_FORMAT is AVKey.IMAGE (valid values: AVKey.COLOR and AVKey.MONOCHROME)

AVKey.DATA_TYPE required ( valid values: AVKey.INT16, and AVKey.FLOAT32 )

AVKey.VERSION optional, if missing a default will be used "NASA World Wind"

AVKey.DISPLAY_NAME, (String) optional, specifies a name of the document/image

AVKey.DESCRIPTION (String) optional, for any kind of descriptions

AVKey.MISSING_DATA_SIGNAL optional, set the AVKey.MISSING_DATA_SIGNAL ONLY if you know for sure that the specified value actually represents void (NODATA) areas. Elevation data usually has "-32767" (like DTED), or "-32768" like SRTM, but some has "0" (mostly images) and "-9999" like NED. Note! Setting "-9999" is very ambiguos because -9999 for elevation is valid value;

AVKey.MISSING_DATA_REPLACEMENT (String type forced by spec) Most images have "NODATA" as "0", elevations have as "-9999", or "-32768" (sometimes "-32767")

AVKey.COORDINATE_SYSTEM required, valid values AVKey.COORDINATE_SYSTEM_GEOGRAPHIC or AVKey.COORDINATE_SYSTEM_PROJECTED

AVKey.COORDINATE_SYSTEM_NAME Optional, A name of the Coordinates System as a String

AVKey.PROJECTION_EPSG_CODE Required; Integer; EPSG code or Projection Code If CS is Geodetic and EPSG code is not specified, a default WGS84 (4326) will be used

AVKey.PROJECTION_DATUM Optional, AVKey.PROJECTION_DESC Optional, AVKey.PROJECTION_NAME Optional, AVKey.PROJECTION_UNITS Optional,

AVKey.ELEVATION_UNIT Required, if AVKey.PIXEL_FORMAT = AVKey.ELEVATION, value: AVKey.UNIT_FOOT or AVKey.UNIT_METER (default, if not specified)

AVKey.RASTER_PIXEL, optional, values: AVKey.RASTER_PIXEL_IS_AREA or AVKey.RASTER_PIXEL_IS_POINT if not specified, default for images is RASTER_PIXEL_IS_AREA, and AVKey.RASTER_PIXEL_IS_POINT for elevations


findGdalDataFolder

protected static String findGdalDataFolder()

findGdalFolders

protected static String[] findGdalFolders()

gdalPreLoadNativeLibrary

protected static boolean gdalPreLoadNativeLibrary(boolean allowLogErrors)

getCurrentDirectory

protected static String getCurrentDirectory()

getErrorMessage

public static String getErrorMessage()
Returns:
returns an error string, if no errors returns null

getLatLonForRasterPoint

protected static LatLon getLatLonForRasterPoint(double[] gt,
                                                int x,
                                                int y,
                                                org.gdal.osr.CoordinateTransformation ct)

initialize

protected static void initialize()

is32bitArchitecture

protected static boolean is32bitArchitecture()

listAllRegisteredDrivers

protected static void listAllRegisteredDrivers()

open

public static org.gdal.gdal.Dataset open(Object source)
                                  throws FileNotFoundException,
                                         IllegalArgumentException,
                                         SecurityException,
                                         WWRuntimeException
Opens image or elevation file, returns a DataSet object

Parameters:
source - the location of the local file, expressed as either a String path, a File, or a file URL.
Returns:
returns a Dataset object
Throws:
FileNotFoundException - if file not found
IllegalArgumentException - if file is null
SecurityException - if file could not be read
WWRuntimeException - if GDAL library was not initialized

open

public static org.gdal.gdal.Dataset open(Object source,
                                         boolean isSilentMode)
                                  throws FileNotFoundException,
                                         IllegalArgumentException,
                                         SecurityException,
                                         WWRuntimeException
Opens image or elevation file, returns a DataSet object

Parameters:
source - the location of the local file, expressed as either a String path, a File, or a file URL.
isSilentMode - specifies a silent mode of reading file (usually needed for canRead() and readMetadata())
Returns:
returns a Dataset object
Throws:
FileNotFoundException - if file not found
IllegalArgumentException - if file is null
SecurityException - if file could not be read
WWRuntimeException - if GDAL library was not initialized

replaceLibraryLoader

protected static void replaceLibraryLoader()

restoreJavaLibraryPath

protected static void restoreJavaLibraryPath()

scanFill

protected static void scanFill(BufferedImage sourceImage)

setNoDataValue

protected static boolean setNoDataValue(org.gdal.gdal.Band band,
                                        Double nodata)

verticalFlip

protected static BufferedImage verticalFlip(BufferedImage img)
Flips image raster vertically

Parameters:
img - A source raster as a BufferedImage
Returns:
A vertically flipped image raster as a BufferedImage

NASA World Wind