Data model (hubdc.model)

class hubdc.model.ENVIBILDriver[source]

Bases: hubdc.model.RasterDriver

ENVI BIL driver.

__init__()[source]
DEFAULT_OPTIONS = RasterCreationOptions(options={'INTERLEAVE': 'BIL'})
class hubdc.model.ENVIBIPDriver[source]

Bases: hubdc.model.RasterDriver

ENVI BIP driver.

__init__()[source]
DEFAULT_OPTIONS = RasterCreationOptions(options={'INTERLEAVE': 'BIP'})
class hubdc.model.ENVIBSQDriver[source]

Bases: hubdc.model.RasterDriver

ENVI BSQ driver.

__init__()[source]
DEFAULT_OPTIONS = RasterCreationOptions(options={'INTERLEAVE': 'BSQ'})
class hubdc.model.ESRIShapefileDriver[source]

Bases: hubdc.model.VectorDriver

ESRI Shapefile driver.

__init__()[source]
class hubdc.model.ErdasDriver[source]

Bases: hubdc.model.RasterDriver

Erdas Imagine driver.

__init__()[source]
DEFAULT_OPTIONS = RasterCreationOptions(options={})
class hubdc.model.Extent(xmin, xmax, ymin, ymax)[source]

Bases: object

Class for managing extents (i.e. bounding boxes).

__init__(xmin, xmax, ymin, ymax)[source]
Parameters:
  • xmin (float) –
  • xmax (float) –
  • ymin (float) –
  • ymax (float) –
static fromGeometry(geometry)[source]

Create an extent from the bounding box a Geometry.

geometry()[source]

Returns self as a Geometry.

intersection(other)[source]

Returns a new instance which is the intersection of self and other.

intersects(other)[source]

Returns whether self and other intersects.

lowerLeft()[source]

Returns the lower left corner as a Point

lowerRight()[source]

Returns the lower right corner as a Point

reproject(sourceProjection, targetProjection)[source]

Returns a new intsance which is the reprojection of self from sourceProjection into targetProjection.

Parameters:
Returns:

Return type:

hubdc.model.Extent

size(resolution)[source]

Returns the grid Size that corresponds to the given Resolution.

union(other)[source]

Returns a new instance which is the union of self with other.

upperLeft()[source]

Returns the upper left corner as a Point

upperRight()[source]

Returns the upper right corner as a Point

xmax()[source]

Returns the xmax.

xmin()[source]

Returns the xmin.

ymax()[source]

Returns the ymax.

ymin()[source]

Returns the ymin.

class hubdc.model.GDALMetadataFormatter[source]

Bases: object

Class for managing GDAL metadata value formatting.

classmethod gdalStringToValue(gdalString, dtype)[source]

Returns a representation of gdalString as value of given dtype. If gdalString represents a list of values in curly brackets (e.g. {1, 2, 3}), a list of values is returned.

Parameters:
  • gdalString (str) –
  • dtype (int | float | str | ...) –
classmethod valueToGDALString(value)[source]

Returns a string representation of value.

Parameters:value (number | str | list(number) | list(str)) –
Returns:
Return type:

todo: add examples

class hubdc.model.GTiffDriver[source]

Bases: hubdc.model.RasterDriver

GTiff driver.

__init__()[source]
DEFAULT_OPTIONS = RasterCreationOptions(options={'INTERLEAVE': 'BAND', 'BLOCKYSIZE': 256, 'COMPRESS': 'LZW', 'TILED': 'YES', 'BLOCKXSIZE': 256})
class hubdc.model.GeoPackageDriver[source]

Bases: hubdc.model.VectorDriver

ESRI Shapefile driver.

__init__()[source]
class hubdc.model.Geometry(wkt)[source]

Bases: object

Class for managing geometries.

__init__(wkt)[source]

Create by given well known text string.

intersection(other)[source]

Returns the intersection of self and other.

intersects(other)[source]

Returns whether self and other intersect.

ogrGeometry()[source]

Returns ogr.Geometry object.

reproject(sourceProjection, targetProjection)[source]

Returns a new intsance which is the reprojection of self from sourceProjection into targetProjection.

Parameters:
Returns:

Return type:

hubdc.model.Geometry

within(other)[source]

Returns whether self is within other.

wkt()[source]

Returns well known text string.

class hubdc.model.Grid(extent, resolution, projection=None)[source]

Bases: object

Class for managing raster grids in terms of extent, resolution and projection.

__init__(extent, resolution, projection=None)[source]
Parameters:
anchor(point)[source]

Returns a new instance that is anchored to a Point. Anchoring will result in a subpixel shift. See the source code for implementation details.

equal(other)[source]

Returns whether self is equal to other.

extent()[source]

Returns the Extent.

geoTransform()[source]

Returns a GDAL georeferencing transform tuple (xmin, xres, 0, ymax, 0, -yres) from bounds and resolution, without any rotation or shearing.

pixelBuffer(buffer, left=True, right=True, up=True, down=True)[source]

Returns a new instance with a pixel buffer applied in different directions.

Parameters:
  • buffer (int) – number of pixels to be buffered (can also be negativ)
  • left (bool) – whether to buffer to the left/west
  • right (bool) – whether to buffer to the right/east
  • up (bool) – whether to buffer upwards/north
  • down (bool) – whether to buffer downwards/south
Returns:

Return type:

hubdc.model.Grid

projection()[source]

Returns the Projection.

reproject(other)[source]

Returns a new instance with: a) extent reprojected into the projection of other, b) resolution of other, and c) anchored to other.

resolution()[source]

Returns the Resolution.

shape()[source]

Returns size as (ysize, xsize) tuple.

size()[source]

Returns the Size.

spatialExtent()[source]

Returns the SpatialExtent.

subgrids(size)[source]

Returns the decomposition of self into subgrids of given Size. Subgrids at the border are trimmed to the extent of self.

subset(offset, size, trim=False)[source]

Returns a new instance that is a subset given by a Pixel location (i.e. offset) and a raster Size (i.e. size). Optionally set trim=True to restrain the grid extent to the extent of self.

xMapCoordinates()[source]

Returns the list of map coordinates in x dimension.

xMapCoordinatesArray()[source]

Returns the 2d array of map x coordinates.

xPixelCoordinates(offset=0)[source]

Returns the list of pixel coordinates in x dimension with optional offset.

xPixelCoordinatesArray(offset=0)[source]

Returns the 2d array of pixel x coordinates with optional offset.

yMapCoordinates()[source]

Returns the list of map coordinates in y dimension.

yMapCoordinatesArray()[source]

Returns the 2d array of map y coordinates.

yPixelCoordinates(offset=0)[source]

Returns the list of pixel coordinates in y dimension with optional offset.

yPixelCoordinatesArray(offset=0)[source]

Returns the 2d array of pixel y coordinates with optional offset.

class hubdc.model.MEMDriver[source]

Bases: hubdc.model.RasterDriver

MEM driver.

__init__()[source]
class hubdc.model.Pixel(x, y)[source]

Bases: object

Class for managing image pixel location.

__init__(x, y)[source]
Parameters:
  • x (int) –
  • y (int) –
x()[source]

Returns pixel x coordinate.

y()[source]

Returns pixel y coordinate.

class hubdc.model.Point(x, y)[source]

Bases: object

Class for managing map locations.

__init__(x, y)[source]

Create by given x and y coordinates. :param x: :type x: float :param y: :type y: float

geometry()[source]

Returns self as a Geometry.

reproject(sourceProjection, targetProjection)[source]
x()[source]

Returns map x coordinate.

y()[source]

Returns map y coordinate.

class hubdc.model.Projection(wkt)[source]

Bases: object

Class for managing projections.

classmethod UTM(zone, north=True)[source]

Create UTM projection of given zone.

static WGS84()[source]

Create WGS84 projection (epsg=4326), also see http://spatialreference.org/ref/epsg/wgs-84/

static WGS84WebMercator()[source]

Create WGS84 Web Mercator projection (epsg=3857), also see http://spatialreference.org/ref/sr-org/7483/

__init__(wkt)[source]

Create by given well known text string.

equal(other)[source]

Returns whether self is equal to other.

static fromEPSG(epsg)[source]

Create by given epsg authority ID.

osrSpatialReference()[source]

Returns osr.SpatialReference object.

wkt()[source]

Returns the well known text string.

class hubdc.model.Raster(gdalDataset)[source]

Bases: object

Class for managing raster files.

__init__(gdalDataset)[source]

Create an instance by a given gdal.Dataset.

acquisitionTime()[source]

Returns the acquisition time. Restore it from ‘acquisition time’ metadata item inside the ‘ENVI’ domain.

Returns:
Return type:datetime.datetime
array(grid=None, resampleAlg=<Mock name='mock.gdal.GRA_NearestNeighbour' id='140313600122064'>, noData=None, errorThreshold=0.0, warpMemoryLimit=104857600, multithread=False)[source]

Returns raster data as 3d array of shape = (zsize, ysize, xsize) for the given grid, where zsize is the number of raster bands, and ysize, xsize = grid.shape().

Parameters:
  • grid (hubdc.model.Grid) – if not specified self.grid() is used
  • resampleAlg (int) – one of the GDAL resampling algorithms gdal.GRA_*
  • noData (float) – if not specified, no data value of self is used
  • errorThreshold (float) – error threshold for approximation transformer (in pixels)
  • warpMemoryLimit (int) – size of working buffer in bytes
  • multithread (bool) – whether to multithread computation and I/O operations
Returns:

Return type:

numpy.ndarray

band(index)[source]

Return the RasterBand given by index.

bands()[source]

Returns an iterator over each RasterBand.

close()[source]

Close the gdal.Dataset.

copyMetadata(other)[source]

Copy raster and raster band metadata from other to self.

description()[source]

Returns the description.

driver()[source]

Return the Driver.

dtype()[source]

Returns the raster data type.

filename()[source]
filenames()[source]
flushCache()[source]

Flush the cache.

gdalDataset()[source]

Return the gdal.Dataset.

grid()[source]

Return the Grid.

metadataDict()[source]

Returns the metadata dictionary for all domains.

metadataDomain(domain='')[source]

Returns the metadata dictionary for the given domain.

metadataDomainList()[source]

Returns the list of metadata domain names.

metadataItem(key, domain='', dtype=<type 'str'>)[source]

Returns the value (casted to a specific dtype) of a metadata item.

noDataValue(default=None)[source]

Returns a single no data value. Raises an exception if not all bands share the same no data value. If all bands are without a no data value, default is returned.

noDataValues(default=None)[source]

Returns band no data values. For bands without a no data value, default is returned.

readAsArray(grid=None, resampleAlg=<Mock name='mock.gdal.GRA_NearestNeighbour' id='140313600122064'>)[source]

Returns raster data as 3d array.

Parameters:
  • grid (hubdc.model.Grid) – if provided, only data inside the grid extent is returned
  • resampleAlg (int) – one of the GDAL resampling algorithms (i.e. gdal.GRA_*)
Returns:

Return type:

numpy.ndarray

setAcquisitionTime(acquisitionTime)[source]

Set the acquisition time. Store it as ‘acquisition time’ metadata item inside the ‘ENVI’ domain.

Parameters:acquisitionTime (datetime.datetime) –
setDescription(value)[source]

Set the description.

setMetadataDict(metadataDict)[source]

Set the metadata dictionary

setMetadataItem(key, value, domain='')[source]

Set a metadata item. value can be a string, a number or a list of strings or numbers.

setNoDataValue(value)[source]

Set a single no data value to all bands.

setNoDataValues(values)[source]

Set band no data values.

shape()[source]

Returns the (zsize, ysize, xsize) tuple.

translate(grid=None, filename='', driver=MEMDriver(name='MEM'), options=None, **kwargs)[source]

Returns a new instance of self translated into the given grid (default is self.grid()).

Parameters:
Returns:

Return type:

hubdc.model.Raster

warp(grid, filename='', driver=MEMDriver(name='MEM'), options=None, **kwargs)[source]

Returns a new instance of self warped into the given grid (default is self.grid()).

Parameters:
Returns:

Return type:

hubdc.model.Raster

writeArray(array, grid=None)[source]

Writes raster data.

Parameters:
  • array (3d array | list of 2d arrays) –
  • grid (hubdc.model.Grid) – if provided, data is written to the location given by the grid extent
writeENVIHeader()[source]

Creates an ENVI header file containing all metadata of the ‘ENVI’ metadata domain. This ensures the correct interpretation of all metadata items by the ENVI software. Currently only ENVI and GTiff formats are supported.

xsize()[source]

Returns raster x size in pixels.

ysize()[source]

Returns raster y size in pixels.

zsize()[source]

Returns raster z size in terms of number of raster bands.

class hubdc.model.RasterBand(raster, index)[source]

Class for managing raster bands.

__init__(raster, index)[source]

Creating a new instance given a Raster and a raster band index.

copyMetadata(other)[source]

Copy raster and raster band metadata from self to other

description()[source]

Returns band description.

fill(value)[source]

Write constant value to the whole raster band.

index()[source]

Returns the raster band index.

metadataDomainList()[source]

Returns the list of metadata domain names.

metadataItem(key, domain='', dtype=<type 'str'>)[source]
noDataValue(default=None)[source]

Returns band no data value, or default if no data value is unfefined.

raster()[source]

Returns the Raster.

readAsArray(grid=None, resample_alg=<Mock name='mock.gdal.GRA_NearestNeighbour' id='140313600122064'>)[source]

Returns raster band data as 2d array.

Parameters:
  • grid (hubdc.model.Grid) – if provided, only data inside the grid extent is returned.
  • resampleAlg (int) – one of the GDAL resampling algorithms (i.e. gdal.GRA_*)
Returns:

Return type:

numpy.ndarray

setDescription(value)[source]

Set band description.

setMetadataItem(key, value, domain='')[source]

Set a metadata item. value can be a string, a number or a list of strings or numbers.

setNoDataValue(value)[source]

Set no data value.

writeArray(array, grid=None)[source]

Writes raster data.

Parameters:
  • array (3d array | list of 2d arrays) –
  • grid (hubdc.model.Grid) – if provided, data is written to the location given by the grid extent
class hubdc.model.RasterCreationOptions(options=None)[source]

Bases: object

Class for managing raster creation options.

__init__(options=None)[source]

Create a new instance from dictionary given by options.

options()[source]

Returns options dictionary.

optionsList()[source]

Returns options as list.

class hubdc.model.RasterDriver(name)[source]

Bases: object

Class for managing GDAL Drivers

__init__(name)[source]
Parameters:name (str) – e.g. ‘GTiff’ or ‘ENVI’
create(grid, bands=1, gdalType=<Mock name='mock.gdal.GDT_Float32' id='140313600120016'>, filename='', options=None)[source]

Creates a new raster file with extent, resolution and projection given by grid.

Parameters:
  • grid (hubdc.model.Grid) –
  • bands (int) – number of raster bands
  • gdalType (int) – one of the gdal.GDT_* data types, or use gdal_array.NumericTypeCodeToGDALTypeCode
  • filename (str) – output filename
  • options (hubdc.model.RasterCreationOptions) –
Returns:

Return type:

hubdc.model.Raster

defaultOptions()[source]

Returns default creation options.

equal(other)[source]

Returns whether self is equal to the other driver.

classmethod fromFilename(filename)[source]
gdalDriver()[source]

Returns the GDAL driver object.

name()[source]

Returns the driver name.

DEFAULT_OPTIONS = RasterCreationOptions(options={})
class hubdc.model.Resolution(x, y)[source]

Bases: object

Class for managing pixel resolutions.

__init__(x, y)[source]
Parameters:
  • x (float > 0) – resolution in x dimension
  • y (float > 0) – resolution in y dimension
equal(other)[source]

Returns whether self is equal to other.

x()[source]

Returns x resolution.

y()[source]

Returns y resolution.

class hubdc.model.Size(x, y)[source]

Bases: object

Class for managing image sizes.

__init__(x, y)[source]
Parameters:
  • x (int) –
  • y (int) –
x()[source]

Returns the x size.

y()[source]

Returns the y size.

class hubdc.model.SpatialExtent(xmin, xmax, ymin, ymax, projection)[source]

Bases: hubdc.model.Extent

Class for managing spatial extents (i.e. bounding boxes with associated projection).

__init__(xmin, xmax, ymin, ymax, projection)[source]
Parameters:
static fromExtent(extent, projection)[source]

Create an instance from an Extent and a Projection.

static fromGeometry(geometry)[source]

Create an instance from a SpatialGeometry.

geometry()[source]

Returns self as a SpatialGeometry.

intersection(other)[source]

Returns the intersection of self and other.

intersects(other)[source]

Returns whether self and other intersect.

lowerLeft()[source]

Returns the lower left corner as a SpatialPoint

lowerRight()[source]

Returns the lower right corner as a SpatialPoint

projection()[source]

Returns the Projection.

reproject(targetProjection, sourceProjection=None)[source]

Returns a new intsance which is the reprojection of self into targetProjection. The sourceProjection is for internal use only.

Parameters:targetProjection (hubdc.model.Projection) – target projection
Returns:
Return type:hubdc.model.SpatialExtent
union(other)[source]

Returns the union of self and other.

upperLeft()[source]

Returns the upper left corner as a SpatialPoint

upperRight()[source]

Returns the upper right corner as a SpatialPoint

class hubdc.model.SpatialGeometry(wkt, projection)[source]

Bases: hubdc.model.Geometry

Class for managing spatial geometries (i.e. geometries with associated projection).

__init__(wkt, projection)[source]

Create by given well known text string and Projection.

static fromVector(vector)[source]

Create by given Vector.

intersection(other)[source]

Returns the intersection of self and other.

intersects(other)[source]

Returns whether self and other intersect.

projection()[source]

Returns the Projection.

reproject(targetProjection, sourceProjection=None)[source]

Returns a new intsance which is the reprojection of self into targetProjection. The sourceProjection is for internal use only.

Parameters:targetProjection (hubdc.model.Projection) – target projection
Returns:
Return type:hubdc.model.SpatialGeometry
class hubdc.model.SpatialPoint(x, y, projection)[source]

Bases: hubdc.model.Point

Class for managing map location with associated projection.

__init__(x, y, projection)[source]
geometry()[source]

Returns self as a SpatialGeometry.

projection()[source]

Returns the Projection.

reproject(targetProjection, sourceProjection=None)[source]

Returns a new intsance which is the reprojection of self into targetProjection. The sourceProjection is for internal use only.

Parameters:targetProjection (hubdc.model.Projection) – target projection
Returns:
Return type:hubdc.model.SpatialPoint
withinExtent(extent)[source]

Returns whether self is within the SpatialExtent given by extent.

class hubdc.model.Vector(ogrDataSource, layerNameOrIndex=0)[source]

Bases: object

Class for managing layers from vector files.

__init__(ogrDataSource, layerNameOrIndex=0)[source]

Creates new instance from given ogr.DataSource and layer name or index given by nameOrIndex.

close()[source]

Closes the ogr.DataSourse and ogr.Layer

featureCount()[source]

Returns the number of features.

fieldCount()[source]

Returns the number of attribute fields.

fieldNames()[source]

Returns the attribute field names.

fieldTypeNames()[source]

Returns the attribute field data type names.

filename()[source]

Returns the filename.

layerNameOrIndex()[source]

Returns the layer name/index.

ogrDataSource()[source]

Returns the ogr.DataSource.

ogrLayer()[source]

Retrurns the ogr.Layer.

projection()[source]

Returns the Projection.

rasterize(grid, gdalType=<Mock name='mock.gdal.GDT_Float32' id='140313600120016'>, initValue=0, burnValue=1, burnAttribute=None, allTouched=False, filterSQL=None, noDataValue=None, filename='', driver=MEMDriver(name='MEM'), options=None)[source]

Returns a Raster that is the rasterization of self into the given grid as.

Parameters:
  • grid (hubdc.model.Grid) –
  • gdalType (int) – one of the GDAL data types gdal.GDT_*
  • initValue (int) – value to pre-initialize the output array
  • burnValue (int) – value to burn into the output array for all objects; exclusive with burnAttribute
  • burnAttribute (str) – identifies an attribute field on the features to be used for a burn-in value; exclusive with burnValue
  • allTouched (bool) – whether to enable that all pixels touched by lines or polygons will be updated, not just those on the line render path, or whose center point is within the polygon
  • filterSQL (str) – set an SQL WHERE clause which will be used to filter vector features
  • noDataValue (float) – output raster no data value
  • filename (str) – output filename
  • driver (hubdc.model.RasterDriver) –
  • options (hubdc.model.RasterCreationOptions) –
Returns:

Return type:

hubdc.model.Raster

reprojectOnTheFly(projection)[source]

Returns a reprojection of self into the given Projection.

spatialExtent()[source]

Returns the SpatialExtent.

class hubdc.model.VectorDriver(name)[source]

Bases: object

Class for managing OGR Drivers

__init__(name)[source]
Parameters:name (str) – e.g. ‘ESRI Shapefile’ or ‘GPKG’
equal(other)[source]

Returns whether self is equal to the other driver.

classmethod fromFilename(filename)[source]
name()[source]

Returns the driver name.

ogrDriver()[source]

Returns the OGR driver object.

hubdc.model.buildOverviews(filename, levels=None, minsize=1024, resampling='average')[source]

Build image overviews (a.k.a. image pyramid) for raster given by filename. If the list of overview levels is not specified, overviews are generated for levels of powers of 2 (i.e. levels=[2, 4, 8…]) up to the level where the size of the overview is smaller than minsize.

Parameters:
  • filename (str) – input filename
  • minsize (int) – defines the levels (powers of 2) in the case where levels is None
  • levels (Union[Tuple, List]) – list of overview levels
  • resampling (str) – one of those: 'average', 'gauss', 'cubic', 'cubicspline', 'lanczos', 'average_mp', 'average_magphase', 'mode'
hubdc.model.createRaster(grid, bands=1, gdalType=<Mock name='mock.gdal.GDT_Float32' id='140313600120016'>, filename='', driver=MEMDriver(name='MEM'), options=None)[source]

Creates a new raster file with extent, resolution and projection given by grid.

Parameters:
Returns:

Return type:

hubdc.model.Raster

hubdc.model.createRasterFromArray(grid, array, filename='', driver=MEMDriver(name='MEM'), options=None)[source]

Creates a new raster file with content, data type and number of bands given by array and with extent, resolution and projection given by grid.

Parameters:
Returns:

Return type:

hubdc.model.Raster

hubdc.model.createVRT(filename, rastersOrFilenames, **kwargs)[source]

Creates a virtual raster file (VRT) from rasters or filenames given by rastersOrFilenames.

Parameters:
  • filename (str) – output filename
  • rastersOrFilenames (Union[Tuple, List]) – list of filenames or rasters
  • kwargs – all additional keyword arguments are passed to gdal.BuildVRTOptions
Returns:

Return type:

hubdc.model.Raster

hubdc.model.openRaster(filename, eAccess=<Mock name='mock.gdal.GA_ReadOnly' id='140313596605456'>)[source]

Opens the raster given by filename.

Parameters:
  • filename (str) – input filename
  • eAccess (int) – access mode gdal.GA_ReadOnly or gdal.GA_Update
Returns:

Return type:

hubdc.model.Raster

hubdc.model.openVector(filename, layerNameOrIndex=0, update=False)[source]

Opens the vector layer given by filename and layerNameOrIndex.

Parameters:
  • filename (str) – input filename
  • layerNameOrIndex (int | str) – layer index or name
  • update (bool) – whether to open in update mode
Returns:

Return type:

hubdc.model.Vector