hubdc.core¶
-
class
hubdc.core.
ENVI
[source]¶ Bases:
object
-
classmethod
writeAttributeTable
(filename, table)[source]¶ Write attribute table values to csv file next to the given binary file.
-
SPATIAL_KEYS
= ['lines', 'samples', 'map info', 'projection info', 'coordinate system string']¶
-
classmethod
-
class
hubdc.core.
ESRIShapefileDriver
[source]¶ Bases:
hubdc.core.VectorDriver
ESRI Shapefile driver.
-
class
hubdc.core.
EnviDriver
[source]¶ Bases:
hubdc.core.RasterDriver
ENVI driver.
-
class
hubdc.core.
ErdasDriver
[source]¶ Bases:
hubdc.core.RasterDriver
Erdas Imagine driver.
-
class
hubdc.core.
Extent
(xmin, xmax, ymin, ymax, projection)[source]¶ Bases:
object
Class for managing extents (i.e. bounding boxes).
-
__init__
(xmin, xmax, ymin, ymax, projection)[source]¶ Parameters: - xmin (number) –
- xmax (number) –
- ymin (number) –
- ymax (number) –
- projection (hubdc.core.Projection) –
-
intersection
(other)[source]¶ Returns a new instance which is the intersection of self and other in the projection of self.
-
-
class
hubdc.core.
Feature
(ogrFeature, projection=None)[source]¶ Bases:
object
-
class
hubdc.core.
GTiffDriver
[source]¶ Bases:
hubdc.core.RasterDriver
GTiff driver.
-
class
Option
[source]¶ Bases:
object
-
class
ALPHA
[source]¶ Bases:
object
-
NON_PREMULTIPLIED
= 'ALPHA=NON-PREMULTIPLIED'¶
-
PREMULTIPLIED
= 'ALPHA=PREMULTIPLIED'¶
-
UNSPECIFIED
= 'ALPHA=UNSPECIFIED'¶
-
YES
= 'ALPHA=YES'¶
-
-
class
BIGTIFF
[source]¶ Bases:
object
-
IF_NEEDED
= 'BIGTIFF=IF_NEEDED'¶
-
IF_SAFER
= 'BIGTIFF=IF_SAFER'¶
-
NO
= 'BIGTIFF=NO'¶
-
YES
= 'BIGTIFF=YES'¶
-
-
class
COMPRESS
[source]¶ Bases:
object
-
CCITTFAX3
= 'COMPRESS=CCITTFAX3'¶
-
CCITTFAX4
= 'COMPRESS=CCITTFAX4'¶
-
CCITTRLE
= 'COMPRESS=CCITTRLE'¶
-
DEFLATE
= 'COMPRESS=PACKBITS'¶
-
JPEG
= 'COMPRESS=JPEG'¶
-
LERC
= 'COMPRESS=LERC'¶
-
LERC_DEFLATE
= 'COMPRESS=LERC_DEFLATE'¶
-
LERC_ZSTD
= 'COMPRESS=LERC_ZSTD'¶
-
LZMA
= 'COMPRESS=LZMA'¶
-
LZW
= 'COMPRESS=LZW'¶
-
NONE
= 'COMPRESS=NONE'¶
-
PACKBITS
= 'COMPRESS=JPEG'¶
-
WEBP
= 'COMPRESS=WEBP'¶
-
ZSTD
= 'COMPRESS=ZSTD'¶
-
-
class
COPY_SRC_OVERVIEWS
[source]¶ Bases:
object
-
NO
= 'COPY_SRC_OVERVIEWS=NO'¶
-
YES
= 'COPY_SRC_OVERVIEWS=YES'¶
-
-
class
GEOTIFF_KEYS_FLAVOR
[source]¶ Bases:
object
-
ESRI_PE
= 'GEOTIFF_KEYS_FLAVOR=ESRI_PE'¶
-
STANDARD
= 'GEOTIFF_KEYS_FLAVOR=STANDARD'¶
-
-
class
PHOTOMETRIC
[source]¶ Bases:
object
-
CIELAB
= 'PHOTOMETRIC=CIELAB'¶
-
CMYK
= 'PHOTOMETRIC=CMYK'¶
-
ICCLAB
= 'PHOTOMETRIC=ICCLAB'¶
-
ITULAB
= 'PHOTOMETRIC=ITULAB'¶
-
MINISBLACK
= 'PHOTOMETRIC=MINISBLACK'¶
-
MINISWHITE
= 'PHOTOMETRIC=MINISWHITE'¶
-
RGB
= 'PHOTOMETRIC=RGB'¶
-
YCBCR
= 'PHOTOMETRIC=YCBCR'¶
-
-
class
PIXELTYPE
[source]¶ Bases:
object
-
DEFAULT
= 'PIXELTYPE=DEFAULT'¶
-
SIGNEDBYTE
= 'PIXELTYPE=SIGNEDBYTE'¶
-
-
class
PREDICTOR
[source]¶ Bases:
object
-
FloatingPoint
= 'PREDICTOR=3'¶
-
HorizontalDifferencing
= 'PREDICTOR=2'¶
-
NONE
= 'PREDICTOR=1'¶
-
-
class
PROFILE
[source]¶ Bases:
object
-
BASELINE
= 'PROFILE=BASELINE'¶
-
GDALGeoTIFF
= 'PROFILE=GDALGeoTIFF'¶
-
GeoTIFF
= 'PROFILE=GeoTIFF'¶
-
-
class
-
class
-
class
hubdc.core.
GeoPackageDriver
[source]¶ Bases:
hubdc.core.VectorDriver
ESRI Shapefile driver.
-
class
hubdc.core.
Grid
(extent, resolution)[source]¶ Bases:
object
Class for managing raster grids in terms of extent, resolution and projection.
-
__init__
(extent, resolution)[source]¶ Parameters: - extent (hubdc.core.Extent) –
- resolution (hubdc.core.Resolution) –
-
anchor
(point)[source]¶ Returns a new instance that is anchored to the given
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:
-
reproject_OLD
(other)[source]¶ Returns a new instance with: a) extent reprojected into the projection of other, b) resolution of other, and c) anchored to other.
-
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 an
offset
location and a rastersize
. 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.core.
MemDriver
[source]¶ Bases:
hubdc.core.RasterDriver
MEM driver.
-
class
hubdc.core.
MemoryDriver
[source]¶ Bases:
hubdc.core.VectorDriver
Memory driver.
-
class
hubdc.core.
MetadataFormatter
[source]¶ Bases:
object
Class for managing GDAL metadata value formatting.
-
class
hubdc.core.
Point
(x, y, projection)[source]¶ Bases:
hubdc.core.Geometry
Class for managing map locations.
-
class
hubdc.core.
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.core.
PseudoGrid
(size)[source]¶ Bases:
hubdc.core.Grid
-
__init__
(size)[source]¶ Parameters: - extent (hubdc.core.Extent) –
- resolution (hubdc.core.Resolution) –
-
-
class
hubdc.core.
RasterBandDataset
(raster, index)[source]¶ Bases:
object
Class for managing raster band datasets.
-
array
(grid=None, resampleAlg=<Mock name='mock.gdal.GRA_NearestNeighbour' id='139880523761312'>, noDataValue=None, errorThreshold=0.0, warpMemoryLimit=104857600, multithread=False)[source]¶ Returns raster band data as 2d array of shape = (ysize, xsize) for the given
grid
, where zsize is the number of raster bands, and ysize, xsize = grid.shape().Parameters: - grid (hubdc.core.Grid) – if not specified self.grid() is used
- resampleAlg (int) – one of the GDAL resampling algorithms gdal.GRA_*
- noDataValue (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
-
metadataItem
(key, domain='', default=None, required=False, dtype=<class 'str'>)[source]¶ Return the metadata item.
-
noDataValue
(default=None, required=False)[source]¶ Returns band no data value. Returns
default
if no data value is undefined, or raises an error ifrequired
.
-
raster
()[source]¶ Returns the
RasterDataset
.
-
readAsArray
(grid=None, resample_alg=<Mock name='mock.gdal.GRA_NearestNeighbour' id='139880523761312'>)[source]¶ Returns raster band data as 2d array.
Parameters: - grid (hubdc.core.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.core.Grid) – if provided, data is written to the location given by the grid extent
-
-
class
hubdc.core.
RasterDataset
(gdalDataset)[source]¶ Bases:
object
Class for managing raster datasets files.
-
acquisitionTime
()[source]¶ Returns the acquisition time. Restore it from ‘acquisition time’ metadata item inside the ‘ENVI’ domain.
Returns: Return type: datetime.datetime
-
array
(indices=None, grid=None, resampleAlg=<Mock name='mock.gdal.GRA_NearestNeighbour' id='139880523761312'>, noDataValue=None, forceWarp=True, 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: - indices (list) – band indices to read (default is all bands)
- grid (hubdc.core.Grid) – if not specified self.grid() is used
- resampleAlg (int) – one of the GDAL resampling algorithms gdal.GRA_*
- noDataValue (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
-
static
fromArray
(array, grid=None, filename='', driver=None, 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: - array (numpy.ndarray) –
- grid (hubdc.core.Grid) –
- filename (str) – output filename
- driver (hubdc.core.RasterDriver) –
- options (list) – raster creation options
Returns: Return type:
-
metadataItem
(key, domain='', dtype=<class 'str'>, required=False, default=None)[source]¶ Returns the value (casted to a specific
dtype
) of a metadata item.
-
noDataValue
(default=None, required=False)[source]¶ Returns no data value. Returns
default
if all band no data values are undefined, or raises 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, required=False)[source]¶ Returns band no data values. For bands without a no data value,
default
is returned, or ifrequired
is True, an error is raised
-
plotMultibandColor
(rgbindex=(0, 1, 2), rgbvmin=(None, None, None), rgbvmax=(None, None, None), rgbpmin=(None, None, None), rgbpmax=(None, None, None), noPlot=False, showPlot=True)[source]¶
-
plotSinglebandGrey
(index=0, vmin=None, vmax=None, pmin=None, pmax=None, cmap='gray', noPlot=False, showPlot=True)[source]¶ cmap see https://matplotlib.org/examples/color/colormaps_reference.html https://matplotlib.org/api/_as_gen/matplotlib.pyplot.imshow.html
-
readAsArray
(grid=None, resampleAlg=<Mock name='mock.gdal.GRA_NearestNeighbour' id='139880523761312'>)[source]¶ Returns raster data as 3d array.
Parameters: - grid (hubdc.core.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
-
reopen
(eAccess=<Mock name='mock.gdal.GA_ReadOnly' id='139880523761424'>)[source]¶ Returns re-opened version of itself. Useful in cases where flushCache is not sufficient.
-
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=None, options=None, resampleAlg=None, **kwargs)[source]¶ Returns a new instance of self translated into the given
grid
(default is self.grid()).Parameters: - grid (hubdc.core.Grid) –
- filename (str) –
- driver (hubdc.core.RasterDriver) –
- options (list) – raster creation options
- resampleAlg (int) – GDAL resampling algorithm
- kwargs – passed to gdal.TranslateOptions
Returns: Return type:
-
warp
(grid=None, filename='', driver=MemDriver(), options=None, resampleAlg=None, **kwargs)[source]¶ Returns a new instance of self warped into the given
grid
(default is self.grid()).Parameters: - grid (hubdc.core.Grid) –
- filename (str) – output filename
- driver (hubdc.core.RasterDriver) –
- options (list) – creation options
- 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.core.Grid) – if provided, data is written to the location given by the grid extent
-
-
class
hubdc.core.
RasterDriver
(name, options=None)[source]¶ Bases:
object
Class for managing raster drivers
-
__init__
(name, options=None)[source]¶ Create instance from GDAL driver name and (optional) a list of default creation options.
-
create
(grid, bands=1, gdalType=<Mock name='mock.gdal.GDT_Float32' id='139880517999752'>, filename='', options=None)[source]¶ Creates a new raster file with extent, resolution and projection given by
grid
.Parameters: - grid (hubdc.core.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 (list) – raster creation options
Returns: Return type:
-
-
class
hubdc.core.
RasterLayer
(qgsRasterLayer)[source]¶ Bases:
object
-
initMultiBandColorRenderer
(redIndex=0, greenIndex=1, blueIndex=2, redMin=None, redMax=None, greenMin=None, greenMax=None, blueMin=None, blueMax=None, percent=2)[source]¶ Initialize a MultiBandColorRenderer for given band
index
.
-
-
class
hubdc.core.
RasterSize
(x, y)[source]¶ Bases:
object
Class for managing image sizes.
-
class
hubdc.core.
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
-
-
class
hubdc.core.
VectorDataset
(ogrDataSource, layerNameOrIndex=0)[source]¶ Bases:
object
Class for managing vector layer datasets.
-
__init__
(ogrDataSource, layerNameOrIndex=0)[source]¶ Creates new instance from given ogr.DataSource and layer name or index given by
nameOrIndex
.
-
createFidDataset
(filename, fidName='_fid')[source]¶ Create a vector dataset with same features but only one FID attribute.
-
extractPixel
(rasterDataset)[source]¶ Extracts all pixel profiles covert by self, together with all associated attribute.
Returns (rasterValues, vectorValues) tuple.
-
static
fromPoints
(points, attributes=None, filename='', driver=MemoryDriver())[source]¶ Create instance from given
points
. Projection is taken from the first point.
-
metadataItem
(key, domain='', dtype=<class 'str'>, required=False, default=None)[source]¶ Returns the value (casted to a specific
dtype
) of a metadata item.
-
rasterize
(grid, gdalType=<Mock name='mock.gdal.GDT_Float32' id='139880517999752'>, initValue=0, burnValue=1, burnAttribute=None, allTouched=False, filterSQL=None, noDataValue=None, filename='', driver=None, options=None)[source]¶ Returns a
Raster
that is the rasterization of self into the givengrid
as.Parameters: - grid (hubdc.core.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.core.RasterDriver) –
- options (list) – raster creation options
Returns: Return type:
-
reproject
(projection, filename='', driver=MemoryDriver(), **kwargs)[source]¶ Returns a reprojection of self into the given projection. Optional kwargs are passed to gdal.VectorTranslateOptions.
-
setMetadataItem
(key, value, domain='')[source]¶ Set a metadata item.
value
can be a string, a number or a list of strings or numbers.
-
-
class
hubdc.core.
VrtDriver
[source]¶ Bases:
hubdc.core.RasterDriver
VRT driver.
-
hubdc.core.
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.core.
createVRTDataset
(rasterDatasetsOrFilenames, filename='', **kwargs)[source]¶ Creates a virtual raster file (VRT) from raster datasets 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.core.
openRasterDataset
(filename, eAccess=<Mock name='mock.gdal.GA_ReadOnly' id='139880523761424'>)[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.core.
openVectorDataset
(filename, layerNameOrIndex=None, 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: