From 97c52ecef3519fa22e1eeacb20596da8e5f5325e Mon Sep 17 00:00:00 2001 From: Trygve Date: Tue, 7 May 2024 19:38:34 +0200 Subject: [PATCH] Tried fixing gdal bullshit in steepnes method --- src/HeightMap.cpp | 20 ++++++-------------- src/contour_creator.hh | 2 +- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/HeightMap.cpp b/src/HeightMap.cpp index 406e4cb..f3db3d3 100644 --- a/src/HeightMap.cpp +++ b/src/HeightMap.cpp @@ -33,6 +33,7 @@ HeightMap::HeightMap(const char* filepath) //https://gdal.org/api/gdaldataset_cpp.html#_CPPv4N11GDALDataset15GetGeoTransformEPd this->geotransform = (double *) CPLMalloc(sizeof(double)*6); this->reference_system = *(file->GetSpatialRef()); + this->filepath = filepath; file->GetGeoTransform(this->geotransform); @@ -175,11 +176,13 @@ void HeightMap::calculate_steepness() steepness[i] = max - min; } } + GDALAllRegister(); + GDALDataset *original_file = (GDALDataset *) GDALOpen( filepath, GA_ReadOnly ); + const char * filename = "steepness.tif"; auto driver = GetGDALDriverManager()->GetDriverByName("GeoRaster"); GDALDataset *file; - file = driver->Create("steepness.tif", this->width, this->height, 1, GDT_Float32, NULL); - GDALRegister_GTiff(); + file = driver->CreateCopy("steepness.tif", original_file, FALSE, NULL, NULL, NULL); file->AddBand(GDT_Float32, NULL); GDALRasterBand *band = file->GetRasterBand(0); @@ -187,15 +190,4 @@ void HeightMap::calculate_steepness() steepness, this->width, this->height, GDT_Float32, 0, 0 ); GDALClose(file); -} - - -//namespace plt = matplotlibcpp; - -//matplotlibcpp::plot(x, y); -//plt::loglog(x, y); -/* -int main() { - - -}*/ \ No newline at end of file +} \ No newline at end of file diff --git a/src/contour_creator.hh b/src/contour_creator.hh index 2fe808a..841ec0b 100644 --- a/src/contour_creator.hh +++ b/src/contour_creator.hh @@ -16,8 +16,8 @@ class HeightMap float min; //!< Minimum value in image float max; //!< Maximum value in image OGRSpatialReference reference_system; - HeightMap(const char* filepath); + const char* filepath; float get_pixel(int x,int y); void blur(float standard_deviation); void statistics();