public class GDALUtils extends Object
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
GDALUtils() |
Modifier and Type | Method and Description |
---|---|
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
|
public static long ALPHA_MASK
protected static byte ALPHA_OPAQUE
protected static byte ALPHA_TRANSPARENT
protected static final CopyOnWriteArraySet<String> failedLibraries
protected static final String GDAL_DATA_PATH
protected static final String GDAL_DRIVER_PATH
protected static final String gdalalljni
protected static final AtomicBoolean gdalIsAvailable
protected static final String JAVA_LIBRARY_PATH
protected static final CopyOnWriteArraySet<String> loadedLibraries
protected static final String OGR_DRIVER_PATH
protected static void alterJavaLibraryPath(String newJavaLibraryPath) throws IllegalAccessException, NoSuchFieldException
protected static void applyImageMask(byte[] alphaBand, IntBuffer maskBand)
protected static void applyImageMask(int[] alphaBand, IntBuffer maskBand)
protected static void applyImageMask(short[] alphaBand, IntBuffer maskBand)
public static double[] calcGetGeoTransform(Sector sector, int width, int height) throws IllegalArgumentException
sector
- Geographic area, a Sectorwidth
- none-zero width of a rasterheight
- none-zero height of a rasterIllegalArgumentException
- if sector is null, or raster size is zeropublic static boolean canOpen(Object source)
source
- the location of the local file, expressed as either a String path, a File, or a file URL.public static DataRaster composeDataRaster(org.gdal.gdal.Dataset ds, AVList params) throws IllegalArgumentException, WWRuntimeException
protected static DataRaster composeImageDataRaster(org.gdal.gdal.Dataset ds, AVList params) throws IllegalArgumentException, SecurityException, WWRuntimeException
ds
- GDAL's Dataset objectparams
- AVList of parametersIllegalArgumentException
- if file is nullSecurityException
- if file could not be readWWRuntimeException
- if GDAL library was not initializedprotected static DataRaster composeNonImageDataRaster(org.gdal.gdal.Dataset ds, AVList params) throws IllegalArgumentException, WWRuntimeException
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)IllegalArgumentException
- if raster parameters (height, width, sector, etc) are invalidWWRuntimeException
- when invalid raster detected (like attempt to use the method for imagery
raster)public static org.gdal.osr.SpatialReference createGeographicSRS() throws WWRuntimeException
WWRuntimeException
protected static BufferedImage detectVoidsAndMakeThemTransparent(BufferedImage sourceImage)
http://en.wikipedia.org/wiki/Flood_fill#Scanline_fill
sourceImage
- a source image rasterpublic static int[] extractBandOrder(org.gdal.gdal.Dataset ds, AVList params) throws IllegalArgumentException, WWRuntimeException
protected static void extractMinMaxSampleValues(org.gdal.gdal.Dataset ds, org.gdal.gdal.Band band, AVList params)
public static AVList extractRasterParameters(org.gdal.gdal.Dataset ds) throws IllegalArgumentException, WWRuntimeException
public static AVList extractRasterParameters(org.gdal.gdal.Dataset ds, AVList params, boolean quickReadingMode) throws IllegalArgumentException, WWRuntimeException
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 rasterIllegalArgumentException
- 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 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 elevationsprotected static String findGdalDataFolder()
protected static String[] findGdalFolders()
protected static boolean gdalPreLoadNativeLibrary(boolean allowLogErrors)
protected static String getCurrentDirectory()
public 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()
public static org.gdal.gdal.Dataset open(Object source) throws FileNotFoundException, IllegalArgumentException, SecurityException, WWRuntimeException
source
- the location of the local file, expressed as either a String path, a File, or a file URL.FileNotFoundException
- if file not foundIllegalArgumentException
- if file is nullSecurityException
- if file could not be readWWRuntimeException
- if GDAL library was not initializedpublic static org.gdal.gdal.Dataset open(Object source, boolean isSilentMode) throws FileNotFoundException, IllegalArgumentException, SecurityException, WWRuntimeException
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())FileNotFoundException
- if file not foundIllegalArgumentException
- if file is nullSecurityException
- if file could not be readWWRuntimeException
- if GDAL library was not initializedprotected 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)
img
- A source raster as a BufferedImage