gsdview.gdalbackend.gdalsupport

Support tools and classes for the GDAL library.

Functions

GetCachedStatistics(band) Retrieve cached statistics from a raster band.
SafeGetStatistics(band[, approx_ok, force]) Safe replacement of gdal.Band.GetSrtatistics.
colortable2numpy(colortable)
coordinate_mapper(dataset)
driverList([drivertype]) Return the list of available GDAL/OGR drivers
gdalFilters([mode]) Returns the list of GDAL file filters as expected by Qt.
hasFastStats(band[, approx_ok]) Return true if band statistics can be retrieved quickly.
has_complex_bands(dataset)
isRGB(dataset[, strict]) Return True if a dataset is compatible with RGB representaion.
ogrFilters() Returns the list of OGR file filters as expected by Qt
ovrBestIndex(gdalobj[, ovrlevel, policy]) Return the overview index that best fits ovrlevel.
ovrComputeLevels(gdalobj[, ovrsize, estep, ...]) Compute the overview levels to be generated.
ovrLevelAdjust(ovrlevel, xsize) Adjust the overview level
ovrLevelForSize(gdalobj[, ovrsize]) Compute the overview factor that fits the ovrsize request.
ovrLevels(gdalobj[, raw]) Return availabe overview levels.
ovrRead(dataset[, x, y, w, h, ovrindex, ...]) Read an image block from overviews of all spacified bands.
uniqueDatasetID(prod)

Classes

CoordinateMapper(dataset)

Exceptions

InvalidProjection
MissingOvrError(ovrlevel)
class gsdview.gdalbackend.gdalsupport.CoordinateMapper(dataset)[source]

Bases: object

geoToImgGrid(lon, lat)[source]

Coordinate conversion: (lon,lat) –> (pixel,line) on regular grids.

Elements of the return (pixel,line) touple are 2D array with shape (len(lon), len(lat)).

geoToImgPoints(lon, lat, h=0)[source]

Coordinate conversion: (lon,lat) –> (pixel,line).

geogCS = 'WGS84'
imgToGeoGrid(pixel, line)[source]

Coordinate conversion: (pixel,line) –> (lon,lat) on regular grids.

Elements of the return (lon, lat) touple are 2D array with shape (len(pixels), len(line)).

imgToGeoPoints(pixel, line)[source]

Coordinate conversion: (pixel,line) –> (lon,lat).

gsdview.gdalbackend.gdalsupport.GetCachedStatistics(band)[source]

Retrieve cached statistics from a raster band.

GDAL usually stores pre-computed statistics in the raster band metadata: STATISTICS_MINIMUM, STATISTICS_MAXIMUM, STATISTICS_MEAN and STATISTICS_STDDEV.

This function retrieves cached statistics and returns them as a four items tuple: (MINIMUM, MAXIMUM, MEAN, STDDEV).

exception gsdview.gdalbackend.gdalsupport.InvalidProjection[source]

Bases: exceptions.ValueError

exception gsdview.gdalbackend.gdalsupport.MissingOvrError(ovrlevel)[source]

Bases: exceptions.Exception

gsdview.gdalbackend.gdalsupport.SafeGetStatistics(band, approx_ok=False, force=True)[source]

Safe replacement of gdal.Band.GetSrtatistics.

The standard version of GetSrtatistics not always allows to know whenever statistics have beed actually computed or not (e.g. “force” flag set to False and no statistics available).

This function gracefully handles this case an also cases in which an error happend during statistics computation (e.g. to many nodata values).

Parameters:
  • band – GDAL raster band
  • approx_ok – if approximate statistics are sufficient, the approx_ok flag can be set to True in which case overviews, or a subset of image tiles may be used in computing the statistics (default: False)
  • force – if force is False results will only be returned if it can be done quickly (ie. without scanning the data). If force is False and results cannot be returned efficiently, the function will return four None instead of actual statistics values. Dafault: True.
Returns:

a tuple containing (min, max, mean, stddev) if statistics can be retriewed according to the input flags. A tuple of four None if statistics are not available or can’t be computer according to input flags or if some error occurs during computation.

gsdview.gdalbackend.gdalsupport.colortable2numpy(colortable)[source]
gsdview.gdalbackend.gdalsupport.coordinate_mapper(dataset)[source]
gsdview.gdalbackend.gdalsupport.driverList(drivertype='raster')[source]

Return the list of available GDAL/OGR drivers

gsdview.gdalbackend.gdalsupport.gdalFilters(mode='r')[source]

Returns the list of GDAL file filters as expected by Qt.

gsdview.gdalbackend.gdalsupport.hasFastStats(band, approx_ok=True)[source]

Return true if band statistics can be retrieved quickly.

If precomputed stistics are in band metadata or small enough band overviews does exist then it is assumed that band statistics can be retriewed in a very quick way.

if the approx_ok only precomputed statistics are taken into account.

gsdview.gdalbackend.gdalsupport.has_complex_bands(dataset)[source]
gsdview.gdalbackend.gdalsupport.isRGB(dataset, strict=False)[source]

Return True if a dataset is compatible with RGB representaion.

Conditions tested are:

  • 3 or 4 raster bands (3 in strict mode)

  • raster band datatype is GDT_Byte

  • color interpretation respect the expected order:

    band1: GCI_RedBand band2: GCI_GreenBand band3: GCI_BlueBand band4: GCI_AlphaBand (RGBA only allowed in non strict mode)

    GCI_Undefined color interpretation is allowed in non strict mode.

gsdview.gdalbackend.gdalsupport.ogrFilters()[source]

Returns the list of OGR file filters as expected by Qt

gsdview.gdalbackend.gdalsupport.ovrBestIndex(gdalobj, ovrlevel=None, policy='NEAREST')[source]

Return the overview index that best fits ovrlevel.

If ovrlevel is None it is used the level returner by the ovrLevelForSize function i.e. the lavel ensures that the data size doesn’t exceede a certain memory size (defaut 300K).

The policy parameter can be set to:

Nearest :between available ovr factors the one closest to the requested one (ovrlevel) is returned
Greater :between available ovr factors it is returned the closest one that is greater or equal to the requested ovrlevel
Smaller :between available ovr factors it is returned the closest one that is smaller or equal to the requested ovrlevel

Note

plase note that GREATER for overview level implies a larger reduction factor hence a smaller image (and vice versa).

gsdview.gdalbackend.gdalsupport.ovrComputeLevels(gdalobj, ovrsize=409600, estep=3, threshold=0.1)[source]

Compute the overview levels to be generated.

GSDView relies on overviews to provide a confortable image navigation experience (scroll, pan, zoom etc). This function evaluated the number and overview factors to be pre-calculated in order to provide such a confortable experience.

Parameters:
  • ovrsize – memory size that the smallest overview should not exceede
  • estep

    step for overview levels computation:

    estep = 3 ==> 3, 9, 27, 81, ...
  • threshold – if already exist overview levels close (with respect to threshold) to requested ones then computation is skipped
gsdview.gdalbackend.gdalsupport.ovrLevelAdjust(ovrlevel, xsize)[source]

Adjust the overview level

Replicate the GDALOvLevelAdjust function from gdal/gcore/gdaldefaultoverviews.cpp:

int nOXSize = (nXSize + nOvLevel - 1) / nOvLevel;
return (int) (0.5 + nXSize / (double) nOXSize);
gsdview.gdalbackend.gdalsupport.ovrLevelForSize(gdalobj, ovrsize=409600)[source]

Compute the overview factor that fits the ovrsize request.

Default ovrsize = 300 KBytes ==> about 640x640 pixels paletted or 320x320 pixels RGB32.

gsdview.gdalbackend.gdalsupport.ovrLevels(gdalobj, raw=False)[source]

Return availabe overview levels.

gsdview.gdalbackend.gdalsupport.ovrRead(dataset, x=0, y=0, w=None, h=None, ovrindex=None, bstart=1, bcount=None, dtype=None)[source]

Read an image block from overviews of all spacified bands.

This function read a data block from the overview corresponding to ovrindex for all bcount raster bands starting drom the bstartth one.

Parameters:

dataset: GDAL dataset object
the GDAL dataset to read from
x, y: int
origin of the box to read in overview coordinates
w, h: int
size of the box to read in overview coordinates
ovrindex: int
index of the overview to read from. If the overview index is None data are retrieved directly from the raster band instead of overviews.
bstart: int
raster band start index (default 1).
bcount: int or None
raster band count (defaut all starting from bstart)

Returns:

data: ndarray
the array of data read with shape (h, w, bcount)
gsdview.gdalbackend.gdalsupport.uniqueDatasetID(prod)[source]

Get GSDView at SourceForge.net. Fast, secure and Free Open Source software downloads

Previous topic

gsdview.gdalbackend.gdalqt4

Next topic

gsdview.gdalbackend.helpers

This Page