From 5a27d243c00119ac6ac1637791405e10704b0056 Mon Sep 17 00:00:00 2001 From: LandscapeLab Office Date: Mon, 31 Jul 2023 13:33:21 +0200 Subject: [PATCH] Move band count and descriptions to GeoRasterLayer --- src/geodata.cpp | 26 ++++++++++++++++++-------- src/geodata.h | 13 ++++++++----- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/geodata.cpp b/src/geodata.cpp index 6717be2..9f066ba 100644 --- a/src/geodata.cpp +++ b/src/geodata.cpp @@ -25,7 +25,6 @@ void GeoDataset::_bind_methods() { ClassDB::bind_method(D_METHOD("get_feature_layers"), &GeoDataset::get_feature_layers); ClassDB::bind_method(D_METHOD("get_raster_layer", "name"), &GeoDataset::get_raster_layer); ClassDB::bind_method(D_METHOD("get_feature_layer", "name"), &GeoDataset::get_feature_layer); - ClassDB::bind_method(D_METHOD("get_raster_count"), &GeoDataset::get_raster_count); ClassDB::bind_method(D_METHOD("load_from_file", "file_path", "write_access"), &GeoDataset::load_from_file); } @@ -105,13 +104,6 @@ void GeoDataset::set_native_dataset(std::shared_ptr new_dataset) dataset = new_dataset; } -int GeoDataset::get_raster_count() { - if (dataset == nullptr || !this->is_valid()) { - return 0; - } - return dataset->dataset->GetRasterCount(); -} - void GeoFeatureLayer::_bind_methods() { ClassDB::bind_method(D_METHOD("is_valid"), &GeoFeatureLayer::is_valid); ClassDB::bind_method(D_METHOD("get_file_info"), &GeoFeatureLayer::get_file_info); @@ -286,6 +278,8 @@ void GeoRasterLayer::_bind_methods() { ClassDB::bind_method(D_METHOD("has_write_access"), &GeoRasterLayer::has_write_access); ClassDB::bind_method(D_METHOD("get_file_info"), &GeoRasterLayer::get_file_info); ClassDB::bind_method(D_METHOD("get_format"), &GeoRasterLayer::get_format); + ClassDB::bind_method(D_METHOD("get_band_count"), &GeoRasterLayer::get_band_count); + ClassDB::bind_method(D_METHOD("get_band_descriptions"), &GeoRasterLayer::get_band_descriptions); ClassDB::bind_method(D_METHOD("get_dataset"), &GeoRasterLayer::get_dataset); ClassDB::bind_method(D_METHOD("get_image", "top_left_x", "top_left_y", "size_meters", "img_size", "interpolation_type"), @@ -322,6 +316,18 @@ bool GeoRasterLayer::has_write_access() { return write_access; } +Array GeoRasterLayer::get_band_descriptions() { + Array result = Array(); + + std::vector descriptions = dataset->get_raster_band_descriptions(); + for (int i = 0; i < descriptions.size(); i++) { + std::string description = descriptions[i]; + result.append(description.c_str()); + } + + return result; +} + Dictionary GeoRasterLayer::get_file_info() { Dictionary info; @@ -358,6 +364,10 @@ Image::Format GeoRasterLayer::get_format() { } } +int GeoRasterLayer::get_band_count() { + return dataset->dataset->GetRasterCount(); +} + Ref GeoRasterLayer::get_dataset() { return origin_dataset; } diff --git a/src/geodata.h b/src/geodata.h index 8aadc16..5237ea8 100644 --- a/src/geodata.h +++ b/src/geodata.h @@ -114,6 +114,14 @@ class EXPORT GeoRasterLayer : public Resource { /// Returns the Image format which corresponds to the data within this raster layer. Image::Format get_format(); + /// @brief Get the total amount of raster bands contained in the layer. + /// Returns 0 if layer is not valid + /// @return the total amount of raster bands in the layer. + int get_band_count(); + + /// Returns the descriptions of the individual raster bands as strings in an array. + Array get_band_descriptions(); + /// Returns the dataset which this layer was opened from or null if it was opened directly, e.g. /// from a GeoTIFF. Ref get_dataset(); @@ -251,11 +259,6 @@ class EXPORT GeoDataset : public Resource { /// is only for internal use. void set_native_dataset(std::shared_ptr new_dataset); - /// @brief Get the total amount of raster bands contained in the dataset. - /// Returns 0 if dataset is not valid - /// @return the total amount of raster bands in the dataset. - int get_raster_count(); - bool write_access; std::shared_ptr dataset;