|
sgsPy
structurally guided sampling
|
#include <raster.h>
Public Member Functions | |
| GDALRasterWrapper (std::string filename, std::string projDBPath) | |
| GDALRasterWrapper (GDALDataset *p_dataset, std::vector< void * > bands) | |
| GDALRasterWrapper (GDALDataset *p_dataset) | |
| GDALRasterWrapper (py::buffer buffer, std::vector< double > geotransform, std::string projection, std::vector< double > nanVals, std::vector< std::string > names, std::string projDBPath) | |
| ~GDALRasterWrapper () | |
| void | close (void) |
| GDALDataset * | getDataset () |
| std::string | getDriver () |
| std::string | getFullProjectionInfo () |
| std::string | getCRS () |
| int | getWidth () |
| int | getHeight () |
| int | getBandCount () |
| double | getXMax () |
| double | getXMin () |
| double | getYMax () |
| double | getYMin () |
| double | getPixelWidth () |
| double | getPixelHeight () |
| std::vector< std::string > | getBands () |
| double * | getGeotransform () |
| double | getBandNoDataValue (int band) |
| py::buffer | getRasterBandAsMemView (int width, int height, int band) |
| void | releaseBandBuffers (void) |
| GDALRasterBand * | getRasterBand (int band) |
| void * | getRasterBandBuffer (int band) |
| GDALDataType | getRasterBandType (int band) |
| size_t | getRasterBandTypeSize (int band) |
| void | write (std::string filename) |
| void | setTempDir (std::string tempDir) |
| std::string | getTempDir () |
| std::vector< double > | getGeotransformArray () |
| std::string | getDataType () |
Wrapper class for a GDAL dataset containing a raster image.
This class provides getter methods for important raster data and metadata, as well as a way to access the raster as an array.
Memory is controlled using either a smart pointer (in the case of the dataset) or CPLMalloc and CPLFree (in the case of the raster image). The function GDALDataset::RasterIO() function should do the windowing for us behind the scenes, meaning we don't have to worry about physical memory size when allocating for large raster images.
The raster buffer contains all of the raster bands and can be indexed in Python with: [band][y][x] and in C++ with: [band * size * width * height + y * size * width + x * size]
The buffer is exposed to the Python side of the application using a py::buffer, and it's exposed to the C++ side of the application using a void *. The expectation is that this void pointer will be cast to another data type pointer as required.
|
inline |
Constructor for GDALRasterWrapper class. Creates GDALDataset using drivers and given file, then calls createFromDataset() passing the created object. Set the search path for the proj.db file, because this function may be the first called from the Python side of the application, meaning this instance of GDAL may not have found a proj.db file yet.
| std::string | filename |
| std::string | projDBPath |
|
inline |
Constructor for GDALRasterWrapper class if an in-memory dataset has already been created. The bands (already read and allocated) are passed as the second parameter. Calls createFromDataset() passing p_dataset parameter, and sets internal raster band parameters accordingly.
| GDALDataset | *p_dataset GDAL raster dataset |
| std::vector<void | *> raster bands |
|
inline |
Constructor for GDALRasterWrapper class using just a GDAL dataset pointer, by calling createFromDataset().
| GDALDataset | *p_dataset GDAL raster dataset |
|
inline |
Constructor for generating a GDALRasterWrapper from a numpy array and metadata. The numpy array is passed in the form of a py::buffer. Set the search path for the proj.db file, because this function may be the first called from the Python side of the application, meaning this instance of GDAL may not have found a proj.db file yet.
| py::buffer | buffer |
| std::vector<double> | geotransform |
| std::string | projection |
| std::vector<double> | nanVals |
| std::vector<std::string> | names |
| std::string | projDBPath |
|
inline |
Deconstructor for GDALRasterWrapper class. This method calls CPLFree() on any allocated raster buffers.
|
inline |
This is a copy of the deconstructor, it cleans up the all of the heap allocations which the class has made. This is meant to be called by the Python side of the application.
In the case where the used tries to continue to use the object after it has been cleaned up, there will be undefined behavior.
For this reason, there is a check to ensure no members of this object are accessed after it has been deleted from within the Pyhton code.
|
inline |
Getter method for the number of raster bands.
|
inline |
Getter method for a specific (0-indexed) bands nodata value.
|
inline |
Getter method for raster band names. Bands occur in order, meaning bands[0] corresponds to band 1, bands[1] to band 2, etc.
|
inline |
Get the CRS name from the OGRSpatialReference object
|
inline |
Getter method for wrapped dataset.
|
inline |
Gets the data type of the whole raster. If different bands have different types, returns "".
This is meant to be used by the Python side of the applications, specifically when converting from an sgs object to another Python geospatial library object.
|
inline |
Getter method for the raster driver.
|
inline |
Getter method for the full projection information as wkt.
|
inline |
Getter method for geotransform.
|
inline |
Getter method for the geotransform. Meant to be used by the python side of the application. Specifically, used when converting from an sgs object to another Python geospatial library object.
|
inline |
Getter method for the raster height.
|
inline |
Getter method for the pixel height. Scalar (absolute) value is given. see https://gdal.org/en/stable/tutorials/geotransforms_tut.html
|
inline |
Getter method for the pixel width. Scalar (absolute) value is given. see https://gdal.org/en/stable/tutorials/geotransforms_tut.html
|
inline |
Getter method for a GDALRasterBand in the raster, used by the C++ side of the application.
| int | band |
|
inline |
Getter method for the raster image, used by the Python side of the application. This function allocates and reads a raster band if necessary, and uses py::memoryview::from_buffer() to create the buffer of the correct size/dimensions without copying data unecessarily.
This function requires that width and height be defined according to GDAL target_downscaling_factor rules. Otherwise, the incorrect amount of memory will be allocated. Information on target_downsampling_factor can be found here: https://gdal.org/en/stable/api/gdaldataset_cpp.html#classGDALDataset_1ae66e21b09000133a0f4d99baabf7a0ec
for py::memoryview::from_buffer() information see: https://pybind11.readthedocs.io/en/stable/advanced/pycpp/numpy.html#memory-view
| int | width |
| int | height |
| int | band |
|
inline |
Getter method for the whole GDALRasterBand data buffer.
| int |
|
inline |
Getter method for the pixel / raster data type.
| int | band |
|
inline |
Getter method for the pixel /raster data type size.
| int | band |
|
inline |
Getter function for the rasters temporary directory.
|
inline |
Getter method for the raster width.
|
inline |
Getter method for the maximum x value in georeferenced coordinate space. see https://gdal.org/en/stable/tutorials/geotransforms_tut.html
|
inline |
Getter method for the minimum x value in georeferenced coordinate space. see https://gdal.org/en/stable/tutorials/geotransforms_tut.html
|
inline |
Getter method for the maximum y value in georeferenced coordinate space. see https://gdal.org/en/stable/tutorials/geotransforms_tut.html
|
inline |
Getter method for the minimum y value in georeferenced coordinate space. see https://gdal.org/en/stable/tutorials/geotransforms_tut.html
|
inline |
This function is used when converting the sgs SpatialRaster Python class (which wraps this GDALRasterWrapper class) to a different data type, typically for a different geospatial package.
If the user desires the array as a numpy array, then the data must be passed as a buffer AND the ownership of the data must be released from the C++ object, so it is not cleaned up by the deconstructor when the C++ object is freed.
This is essentially a memory leak as far as the C++ code is concerned, however the numpy array will retain ownership and delete when required.
|
inline |
Give the GDALRasterWrapper ownership of a temporary directory, for it to remove when deconstructed.
| std::string | tempDir |
|
inline |
Writes the raster to a specific file given by filename, by creating a copy of the GDALDatset.
| std::string | filename |