Class GDALUtils
- java.lang.Object
-
- gov.nasa.worldwind.util.gdal.GDALUtils
-
public class GDALUtils extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static long
ALPHA_MASK
protected static byte
ALPHA_OPAQUE
protected static byte
ALPHA_TRANSPARENT
protected static java.util.concurrent.CopyOnWriteArraySet<java.lang.String>
FAILED_LIBRARIES
protected static java.lang.String
GDAL_ALL_JNI
protected static java.lang.String
GDAL_DATA_PATH
protected static java.lang.String
GDAL_DRIVER_PATH
protected static java.util.concurrent.atomic.AtomicBoolean
GDAL_IS_AVAILABLE
protected static java.lang.String
JAVA_LIBRARY_PATH
protected static java.util.concurrent.CopyOnWriteArraySet<java.lang.String>
LOADED_LIBRARIES
protected static java.lang.String
OGR_DRIVER_PATH
-
Constructor Summary
Constructors Constructor Description GDALUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static void
applyImageMask(byte[] alphaBand, java.nio.IntBuffer maskBand)
protected static void
applyImageMask(int[] alphaBand, java.nio.IntBuffer maskBand)
protected static void
applyImageMask(short[] alphaBand, java.nio.IntBuffer maskBand)
static double[]
calcGetGeoTransform(Sector sector, int width, int height)
Calculates geo-transform matrix for a north-up rasterstatic boolean
canOpen(java.lang.Object source)
Checks if a data raster can is readablestatic 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 java.lang.Double
convertStringToDouble(java.lang.String s)
static org.gdal.osr.SpatialReference
createGeographicSRS()
protected static java.awt.image.BufferedImage
detectVoidsAndMakeThemTransparent(java.awt.image.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 java.nio.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 AVListprotected static java.lang.String
findGdalDataFolder()
protected static java.util.ArrayList<java.lang.String>
findGdalFolders()
protected static boolean
gdalPreLoadNativeLibrary(java.lang.String folder, boolean allowLogErrors)
protected static java.lang.String
getCurrentDirectory()
static java.lang.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(java.lang.Object source)
Opens image or elevation file, returns a DataSet objectstatic org.gdal.gdal.Dataset
open(java.lang.Object source, boolean isSilentMode)
Opens image or elevation file, returns a DataSet objectprotected static void
replaceLibraryLoader()
protected static void
scanFill(java.awt.image.BufferedImage sourceImage)
protected static boolean
setNoDataValue(org.gdal.gdal.Band band, java.lang.Double nodata)
protected static java.awt.image.BufferedImage
verticalFlip(java.awt.image.BufferedImage img)
Flips image raster vertically
-
-
-
Field Detail
-
ALPHA_MASK
public static long ALPHA_MASK
-
ALPHA_TRANSPARENT
protected static byte ALPHA_TRANSPARENT
-
ALPHA_OPAQUE
protected static byte ALPHA_OPAQUE
-
JAVA_LIBRARY_PATH
protected static final java.lang.String JAVA_LIBRARY_PATH
- See Also:
- Constant Field Values
-
GDAL_DRIVER_PATH
protected static final java.lang.String GDAL_DRIVER_PATH
- See Also:
- Constant Field Values
-
OGR_DRIVER_PATH
protected static final java.lang.String OGR_DRIVER_PATH
- See Also:
- Constant Field Values
-
GDAL_DATA_PATH
protected static final java.lang.String GDAL_DATA_PATH
- See Also:
- Constant Field Values
-
GDAL_IS_AVAILABLE
protected static final java.util.concurrent.atomic.AtomicBoolean GDAL_IS_AVAILABLE
-
GDAL_ALL_JNI
protected static final java.lang.String GDAL_ALL_JNI
-
LOADED_LIBRARIES
protected static final java.util.concurrent.CopyOnWriteArraySet<java.lang.String> LOADED_LIBRARIES
-
FAILED_LIBRARIES
protected static final java.util.concurrent.CopyOnWriteArraySet<java.lang.String> FAILED_LIBRARIES
-
-
Method Detail
-
replaceLibraryLoader
protected static void replaceLibraryLoader()
-
is32bitArchitecture
protected static boolean is32bitArchitecture()
-
gdalPreLoadNativeLibrary
protected static boolean gdalPreLoadNativeLibrary(java.lang.String folder, boolean allowLogErrors)
-
initialize
protected static void initialize()
-
getCurrentDirectory
protected static java.lang.String getCurrentDirectory()
-
findGdalFolders
protected static java.util.ArrayList<java.lang.String> findGdalFolders()
-
findGdalDataFolder
protected static java.lang.String findGdalDataFolder()
-
listAllRegisteredDrivers
protected static void listAllRegisteredDrivers()
-
getErrorMessage
public static java.lang.String getErrorMessage()
- Returns:
- returns an error string, if no errors returns null
-
open
public static org.gdal.gdal.Dataset open(java.lang.Object source, boolean isSilentMode) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException, java.lang.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:
java.io.FileNotFoundException
- if file not foundjava.lang.IllegalArgumentException
- if file is nulljava.lang.SecurityException
- if file could not be readWWRuntimeException
- if GDAL library was not initialized
-
open
public static org.gdal.gdal.Dataset open(java.lang.Object source) throws java.io.FileNotFoundException, java.lang.IllegalArgumentException, java.lang.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:
java.io.FileNotFoundException
- if file not foundjava.lang.IllegalArgumentException
- if file is nulljava.lang.SecurityException
- if file could not be readWWRuntimeException
- if GDAL library was not initialized
-
canOpen
public static boolean canOpen(java.lang.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
-
composeImageDataRaster
protected static DataRaster composeImageDataRaster(org.gdal.gdal.Dataset ds, AVList params) throws java.lang.IllegalArgumentException, java.lang.SecurityException, WWRuntimeException
Opens image or elevation file, returns as a BufferedImage (even for elevations)- Parameters:
ds
- GDAL's Dataset objectparams
- AVList of parameters- Returns:
- DataRaster returns as a BufferedImage (even for elevations)
- Throws:
java.lang.IllegalArgumentException
- if file is nulljava.lang.SecurityException
- if file could not be readWWRuntimeException
- if GDAL library was not initialized
-
detectVoidsAndMakeThemTransparent
protected static java.awt.image.BufferedImage detectVoidsAndMakeThemTransparent(java.awt.image.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 morehttp://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
-
scanFill
protected static void scanFill(java.awt.image.BufferedImage sourceImage)
-
verticalFlip
protected static java.awt.image.BufferedImage verticalFlip(java.awt.image.BufferedImage img)
Flips image raster vertically- Parameters:
img
- A source raster as a BufferedImage- Returns:
- A vertically flipped image raster as a BufferedImage
-
applyImageMask
protected static void applyImageMask(byte[] alphaBand, java.nio.IntBuffer maskBand)
-
applyImageMask
protected static void applyImageMask(short[] alphaBand, java.nio.IntBuffer maskBand)
-
applyImageMask
protected static void applyImageMask(int[] alphaBand, java.nio.IntBuffer maskBand)
-
extractImageMask
protected static java.nio.IntBuffer extractImageMask(AVList params)
-
calcGetGeoTransform
public static double[] calcGetGeoTransform(Sector sector, int width, int height) throws java.lang.IllegalArgumentException
Calculates geo-transform matrix for a north-up raster- Parameters:
sector
- Geographic area, a Sectorwidth
- none-zero width of a rasterheight
- none-zero height of a raster- Returns:
- an array of 6 doubles that contain a geo-transform matrix
- Throws:
java.lang.IllegalArgumentException
- if sector is null, or raster size is zero
-
createGeographicSRS
public static org.gdal.osr.SpatialReference createGeographicSRS() throws WWRuntimeException
- Throws:
WWRuntimeException
-
getLatLonForRasterPoint
protected static LatLon getLatLonForRasterPoint(double[] gt, int x, int y, org.gdal.osr.CoordinateTransformation ct)
-
extractRasterParameters
public static AVList extractRasterParameters(org.gdal.gdal.Dataset ds) throws java.lang.IllegalArgumentException, WWRuntimeException
- Throws:
java.lang.IllegalArgumentException
WWRuntimeException
-
extractRasterParameters
public static AVList extractRasterParameters(org.gdal.gdal.Dataset ds, AVList params, boolean quickReadingMode) throws java.lang.IllegalArgumentException, WWRuntimeException
Extracts raster parameters to an AVList- Parameters:
ds
- A GDAL datasetparams
- AVList to hold retrieved metadata, if null, a new instance will be created and returned as a return valuequickReadingMode
- 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:
java.lang.IllegalArgumentException
- when the passed dataset is null pr emtpy, or any of the dimension is 0WWRuntimeException
- if GDAL is not available, or a dataset contains no bandsThe 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 and 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 WorldWind"
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
-
convertStringToDouble
protected static java.lang.Double convertStringToDouble(java.lang.String s)
-
extractMinMaxSampleValues
protected static void extractMinMaxSampleValues(org.gdal.gdal.Dataset ds, org.gdal.gdal.Band band, AVList params)
-
setNoDataValue
protected static boolean setNoDataValue(org.gdal.gdal.Band band, java.lang.Double nodata)
-
composeDataRaster
public static DataRaster composeDataRaster(org.gdal.gdal.Dataset ds, AVList params) throws java.lang.IllegalArgumentException, WWRuntimeException
- Throws:
java.lang.IllegalArgumentException
WWRuntimeException
-
extractBandOrder
public static int[] extractBandOrder(org.gdal.gdal.Dataset ds, AVList params) throws java.lang.IllegalArgumentException, WWRuntimeException
- Throws:
java.lang.IllegalArgumentException
WWRuntimeException
-
composeNonImageDataRaster
protected static DataRaster composeNonImageDataRaster(org.gdal.gdal.Dataset ds, AVList params) throws java.lang.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() methodparams
- , The AVList with properties (usually used to force projection info or sector)- Returns:
- ByteBufferRaster as DataRaster
- Throws:
java.lang.IllegalArgumentException
- if raster parameters (height, width, sector, etc) are invalidWWRuntimeException
- when invalid raster detected (like attempt to use the method for imagery raster)
-
-