Skip to content

Commit

Permalink
Move band count and descriptions to GeoRasterLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
LandscapeLab Office committed Jul 31, 2023
1 parent 50c6c29 commit 5a27d24
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
26 changes: 18 additions & 8 deletions src/geodata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -105,13 +104,6 @@ void GeoDataset::set_native_dataset(std::shared_ptr<NativeDataset> 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);
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -322,6 +316,18 @@ bool GeoRasterLayer::has_write_access() {
return write_access;
}

Array GeoRasterLayer::get_band_descriptions() {
Array result = Array();

std::vector<std::string> 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;

Expand Down Expand Up @@ -358,6 +364,10 @@ Image::Format GeoRasterLayer::get_format() {
}
}

int GeoRasterLayer::get_band_count() {
return dataset->dataset->GetRasterCount();
}

Ref<GeoDataset> GeoRasterLayer::get_dataset() {
return origin_dataset;
}
Expand Down
13 changes: 8 additions & 5 deletions src/geodata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<GeoDataset> get_dataset();
Expand Down Expand Up @@ -251,11 +259,6 @@ class EXPORT GeoDataset : public Resource {
/// is only for internal use.
void set_native_dataset(std::shared_ptr<NativeDataset> 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<NativeDataset> dataset;
Expand Down

0 comments on commit 5a27d24

Please sign in to comment.