Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kordejong committed Feb 6, 2024
1 parent c6e48a5 commit a1154d7
Show file tree
Hide file tree
Showing 28 changed files with 631 additions and 317 deletions.
3 changes: 3 additions & 0 deletions source/data_model/gdal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add_library(lue_gdal STATIC
src/blocks.cpp
src/dataset.cpp
src/driver.cpp
src/error.cpp
src/raster.cpp
src/raster_band.cpp
${CMAKE_CURRENT_BINARY_DIR}/src/version.cpp
Expand Down Expand Up @@ -43,6 +44,8 @@ target_sources(lue_gdal
${CMAKE_CURRENT_BINARY_DIR}/include/lue/gdal/configure.hpp
)

# NOTE: Think twice before adding libraries here. lue::gdal is a simple, thin API around the
# GDAL API.
target_link_libraries(lue_gdal
PUBLIC
GDAL::GDAL
Expand Down
3 changes: 3 additions & 0 deletions source/data_model/gdal/doc/namespace.dox
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ namespace lue {
@brief Namespace containing a nicer API around the GDAL C++-API and additional
code that makes working with the GDAL library a nicer experience

The API tries to be as close to the original GDAL API as possible. There are only a
few utility classes, e.g.: gdal::Blocks and gdal::Raster.

The code is useful in other contexts than LUE: lue::gdal doesn't depend on
anything specific to LUE.

Expand Down
1 change: 1 addition & 0 deletions source/data_model/gdal/include/lue/gdal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "lue/gdal/configure.hpp"
#include "lue/gdal/dataset.hpp"
#include "lue/gdal/driver.hpp"
#include "lue/gdal/error.hpp"
#include "lue/gdal/raster.hpp"
#include "lue/gdal/raster_band.hpp"
#include "lue/gdal/type_traits.hpp"
Expand Down
7 changes: 7 additions & 0 deletions source/data_model/gdal/include/lue/gdal/dataset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ namespace lue::gdal {

auto try_open_dataset(std::string const& name, GDALAccess open_mode) -> DatasetPtr;

auto create_dataset(
GDALDriver& driver,
std::string const& dataset_name,
Shape const& shape,
Count nr_bands,
GDALDataType data_type) -> DatasetPtr;

auto create_dataset(
std::string const& driver_name,
std::string const& dataset_name,
Expand Down
34 changes: 33 additions & 1 deletion source/data_model/gdal/include/lue/gdal/define.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ namespace lue::gdal {
*/
using Count = int;

/*!
@brief Type for offsets
First coordinate is the y-coordinate, second coordinate is the x-coordinate. The
coordinates are relative to the upper left corner of the raster band. In case of a cell
offset, the upper left cell has offset (0, 0).
*/
using Offset = std::array<Count, 2>;

/*!
Expand All @@ -19,12 +26,37 @@ namespace lue::gdal {
using Shape = std::array<Count, 2>;


/*!
@brief Return the number of elements in a shape of a raster (for example)
*/
inline auto nr_elements(Shape const& shape) -> Count
{
return shape[0] * shape[1];
}


using GeoTransform = std::array<double, 6>;
/*!
@brief Type used by GDAL for no-data values
*/
using NoDataValue = double;


/*!
@brief Type used by GDAL for coordinates
*/
using Coordinate = double;


/*!
@brief Type used by GDAL for extents, e.g. for cell width, cell height
*/
using Extent = double;


/*!
@brief Type for representing transformation information
@sa gdal::geo_transform
*/
using GeoTransform = std::array<Coordinate, 6>;

} // namespace lue::gdal
2 changes: 2 additions & 0 deletions source/data_model/gdal/include/lue/gdal/driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ namespace lue::gdal {

auto driver(std::string const& name) -> DriverPtr;

auto delete_dataset(GDALDriver& driver, std::string const& dataset_name) -> void;

} // namespace lue::gdal
21 changes: 21 additions & 0 deletions source/data_model/gdal/include/lue/gdal/error.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once


namespace lue::gdal {


class QuietErrorHandler
{

public:

QuietErrorHandler();

QuietErrorHandler(QuietErrorHandler const& other) = delete;

~QuietErrorHandler();

auto operator=(QuietErrorHandler const& other) -> QuietErrorHandler = delete;
};

} // namespace lue::gdal
49 changes: 35 additions & 14 deletions source/data_model/gdal/include/lue/gdal/raster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@

namespace lue::gdal {

/*!
@brief Utility class for performing I/O to a raster and its bands
*/
class Raster
{

public:

/*!
@brief Utility class for performing I/O to a raster band
*/
class Band
{

Expand All @@ -30,35 +36,50 @@ namespace lue::gdal {

[[nodiscard]] auto data_type() const -> GDALDataType;

[[nodiscard]] auto block_size() const -> Shape;

[[nodiscard]] auto size() const -> Shape;


/*!
@sa gdal::no_data_value
*/
template<typename Element>
[[nodiscard]] auto no_data_value() const -> std::tuple<Element, bool>
{
return gdal::no_data_value<Element>(*_band);
return gdal::no_data_value<Element>(*_band_ptr);
}

[[nodiscard]] auto blocks() const -> Blocks;

auto read_block(Offset const& block_offset, void* buffer) const -> void;
/*!
@sa gdal::set_no_data_value
*/
template<typename Element>
auto set_no_data_value(Element const value) -> void
{
gdal::set_no_data_value<Element>(*_band_ptr, value);
}


auto read(void* buffer) const -> void;
auto read_block(Offset const& block_offset, void* buffer) -> void;

auto write_block(Offset const& block_offset, void* buffer) -> void;

// void write (hl::Raster::Band& raster_band,
// ProgressIndicator& progress_indicator);
auto read(void* buffer) -> void;

private:
auto write(void* buffer) -> void;

// template<
// typename T>
// void write (hl::Raster::Band& raster_band,
// ProgressIndicator& progress_indicator);
auto write(Offset const& offset, Shape const& shape, GDALDataType data_type, void* buffer)
-> void;

auto write(Shape const& shape, GDALDataType data_type, void* buffer) -> void;

RasterBandPtr _band;
};

private:

RasterBandPtr _band_ptr;
};

explicit Raster(std::string const& dataset_name);

explicit Raster(DatasetPtr dataset_ptr);

Expand Down
24 changes: 23 additions & 1 deletion source/data_model/gdal/include/lue/gdal/raster_band.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,28 @@ namespace lue::gdal {

auto band_size(GDALRasterBand& band) -> Shape;

auto read_block(GDALRasterBand& band, Offset const& block_offset, void* buffer) -> void;

auto write_block(GDALRasterBand& band, Offset const& block_offset, void* buffer) -> void;

auto read(
GDALRasterBand& band,
Offset const& offset,
Shape const& raster_shape,
GDALDataType data_type,
void* buffer) -> void;

auto read(GDALRasterBand& band, Shape const& shape, GDALDataType data_type, void* buffer) -> void;

auto write(
GDALRasterBand& band,
Offset const& offset,
Shape const& raster_shape,
GDALDataType data_type,
void* buffer) -> void;

auto write(GDALRasterBand& band, Shape const& shape, GDALDataType data_type, void* buffer) -> void;


namespace detail {

Expand Down Expand Up @@ -52,7 +74,7 @@ namespace lue::gdal {
template<typename Element>
auto set_no_data_value(GDALRasterBand& band, Element const value) -> CPLErr
{
return band.SetNoDataValue(static_cast<double>(value));
return band.SetNoDataValue(static_cast<NoDataValue>(value));
}


Expand Down
3 changes: 0 additions & 3 deletions source/data_model/gdal/include/lue/gdal/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace lue::gdal {

/*!
@brief Return the version of the GDAL library
*/
auto version() -> std::string;

} // namespace lue::gdal
Loading

0 comments on commit a1154d7

Please sign in to comment.