Data model (hubdc.model)¶
-
class
hubdc.model.
ENVIBILDriver
[source]¶ Bases:
hubdc.model.RasterDriver
ENVI BIL driver.
-
DEFAULT_OPTIONS
= RasterCreationOptions(options={'INTERLEAVE': 'BIL'})¶
-
-
class
hubdc.model.
ENVIBIPDriver
[source]¶ Bases:
hubdc.model.RasterDriver
ENVI BIP driver.
-
DEFAULT_OPTIONS
= RasterCreationOptions(options={'INTERLEAVE': 'BIP'})¶
-
-
class
hubdc.model.
ENVIBSQDriver
[source]¶ Bases:
hubdc.model.RasterDriver
ENVI BSQ driver.
-
DEFAULT_OPTIONS
= RasterCreationOptions(options={'INTERLEAVE': 'BSQ'})¶
-
-
class
hubdc.model.
ESRIShapefileDriver
[source]¶ Bases:
hubdc.model.VectorDriver
ESRI Shapefile driver.
-
class
hubdc.model.
ErdasDriver
[source]¶ Bases:
hubdc.model.RasterDriver
Erdas Imagine driver.
-
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) –
-
reproject
(sourceProjection, targetProjection)[source]¶ Returns a new intsance which is the reprojection of self from
sourceProjection
intotargetProjection
.Parameters: - sourceProjection (hubdc.model.Projection) – projection of self
- targetProjection (hubdc.model.Projection) – target projection
Returns: Return type:
-
size
(resolution)[source]¶ Returns the grid
Size
that corresponds to the givenResolution
.
-
-
class
hubdc.model.
GDALMetadataFormatter
[source]¶ Bases:
object
Class for managing GDAL metadata value formatting.
-
class
hubdc.model.
GTiffDriver
[source]¶ Bases:
hubdc.model.RasterDriver
GTiff driver.
-
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.
-
class
hubdc.model.
Geometry
(wkt)[source]¶ Bases:
object
Class for managing geometries.
-
reproject
(sourceProjection, targetProjection)[source]¶ Returns a new intsance which is the reprojection of self from
sourceProjection
intotargetProjection
.Parameters: - sourceProjection (hubdc.model.Projection) – projection of self
- targetProjection (hubdc.model.Projection) – target projection
Returns: Return type:
-
-
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: - extent (hubdc.model.Extent) –
- resolution (hubdc.model.Resolution) –
- projection (hubdc.model.Projection) – if
extent
is aSpatialExtent
, then the extentsprojection
is used.
-
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.
-
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:
-
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
.
-
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 rasterSize
(i.e.size
). Optionally settrim=True
to restrain the grid extent to the extent of self.
-
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
.
-
-
class
hubdc.model.
MEMDriver
[source]¶ Bases:
hubdc.model.RasterDriver
MEM driver.
-
class
hubdc.model.
Point
(x, y)[source]¶ Bases:
object
Class for managing map locations.
-
class
hubdc.model.
Projection
(wkt)[source]¶ Bases:
object
Class for managing projections.
-
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/
-
static
-
class
hubdc.model.
Raster
(gdalDataset)[source]¶ Bases:
object
Class for managing raster files.
-
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 byindex
.
-
bands
()[source]¶ Returns an iterator over each
RasterBand
.
-
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) –
-
setMetadataItem
(key, value, domain='')[source]¶ Set a metadata item.
value
can be a string, a number or a list of strings or numbers.
-
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: - grid (hubdc.model.Grid) –
- filename (str) –
- driver (hubdc.model.RasterDriver) –
- options (hubdc.model.RasterCreationOptions) –
- kwargs – passed to gdal.TranslateOptions
Returns: Return type:
-
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: - grid (hubdc.model.Grid) –
- filename (str) – output filename
- driver (hubdc.model.RasterDriver) –
- options (hubdc.model.RasterCreationOptions) –
- kwargs – passed to gdal.WarpOptions
Returns: Return type:
-
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.
RasterBand
(raster, index)[source]¶ Class for managing raster bands.
-
noDataValue
(default=None)[source]¶ Returns band no data value, or
default
if no data value is unfefined.
-
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
-
setMetadataItem
(key, value, domain='')[source]¶ Set a metadata item.
value
can be a string, a number or a list of strings or numbers.
-
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.
-
class
hubdc.model.
RasterDriver
(name)[source]¶ Bases:
object
Class for managing GDAL Drivers
-
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:
-
DEFAULT_OPTIONS
= RasterCreationOptions(options={})¶
-
-
class
hubdc.model.
Resolution
(x, y)[source]¶ Bases:
object
Class for managing pixel resolutions.
-
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: - xmin (float) –
- xmax (float) –
- ymin (float) –
- ymax (float) –
- projection (hubdc.model.Projection) –
-
static
fromExtent
(extent, projection)[source]¶ Create an instance from an
Extent
and aProjection
.
-
static
fromGeometry
(geometry)[source]¶ Create an instance from a
SpatialGeometry
.
-
geometry
()[source]¶ Returns self as a
SpatialGeometry
.
-
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
. ThesourceProjection
is for internal use only.Parameters: targetProjection (hubdc.model.Projection) – target projection Returns: Return type: hubdc.model.SpatialExtent
-
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
.
-
projection
()[source]¶ Returns the
Projection
.
-
reproject
(targetProjection, sourceProjection=None)[source]¶ Returns a new intsance which is the reprojection of self into
targetProjection
. ThesourceProjection
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.
-
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
. ThesourceProjection
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 byextent
.
-
-
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
.
-
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 givengrid
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:
-
reprojectOnTheFly
(projection)[source]¶ Returns a reprojection of self into the given
Projection
.
-
spatialExtent
()[source]¶ Returns the
SpatialExtent
.
-
-
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 overviewlevels
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 thanminsize
.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: - 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
- driver (hubdc.model.RasterDriver) –
- options (hubdc.model.RasterCreationOptions) –
Returns: Return type:
-
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 bygrid
.Parameters: - grid (hubdc.model.Grid) –
- array (numpy.ndarray) –
- filename (str) – output filename
- driver (hubdc.model.RasterDriver) –
- options (hubdc.model.RasterCreationOptions) –
Returns: Return type:
-
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.
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
orgdal.GA_Update
Returns: Return type:
-
hubdc.model.
openVector
(filename, layerNameOrIndex=0, update=False)[source]¶ Opens the vector layer given by
filename
andlayerNameOrIndex
.Parameters: - filename (str) – input filename
- layerNameOrIndex (int | str) – layer index or name
- update (bool) – whether to open in update mode
Returns: Return type: