Tried fixing gdal bullshit in steepnes method

This commit is contained in:
Trygve 2024-05-07 19:38:34 +02:00
parent c47565eabb
commit 97c52ecef3
2 changed files with 7 additions and 15 deletions

View File

@ -33,6 +33,7 @@ HeightMap::HeightMap(const char* filepath)
//https://gdal.org/api/gdaldataset_cpp.html#_CPPv4N11GDALDataset15GetGeoTransformEPd //https://gdal.org/api/gdaldataset_cpp.html#_CPPv4N11GDALDataset15GetGeoTransformEPd
this->geotransform = (double *) CPLMalloc(sizeof(double)*6); this->geotransform = (double *) CPLMalloc(sizeof(double)*6);
this->reference_system = *(file->GetSpatialRef()); this->reference_system = *(file->GetSpatialRef());
this->filepath = filepath;
file->GetGeoTransform(this->geotransform); file->GetGeoTransform(this->geotransform);
@ -175,11 +176,13 @@ void HeightMap::calculate_steepness()
steepness[i] = max - min; steepness[i] = max - min;
} }
} }
GDALAllRegister();
GDALDataset *original_file = (GDALDataset *) GDALOpen( filepath, GA_ReadOnly );
const char * filename = "steepness.tif"; const char * filename = "steepness.tif";
auto driver = GetGDALDriverManager()->GetDriverByName("GeoRaster"); auto driver = GetGDALDriverManager()->GetDriverByName("GeoRaster");
GDALDataset *file; GDALDataset *file;
file = driver->Create("steepness.tif", this->width, this->height, 1, GDT_Float32, NULL); file = driver->CreateCopy("steepness.tif", original_file, FALSE, NULL, NULL, NULL);
GDALRegister_GTiff();
file->AddBand(GDT_Float32, NULL); file->AddBand(GDT_Float32, NULL);
GDALRasterBand *band = file->GetRasterBand(0); GDALRasterBand *band = file->GetRasterBand(0);
@ -188,14 +191,3 @@ void HeightMap::calculate_steepness()
0, 0 ); 0, 0 );
GDALClose(file); GDALClose(file);
} }
//namespace plt = matplotlibcpp;
//matplotlibcpp::plot(x, y);
//plt::loglog(x, y);
/*
int main() {
}*/

View File

@ -16,8 +16,8 @@ class HeightMap
float min; //!< Minimum value in image float min; //!< Minimum value in image
float max; //!< Maximum value in image float max; //!< Maximum value in image
OGRSpatialReference reference_system; OGRSpatialReference reference_system;
HeightMap(const char* filepath); HeightMap(const char* filepath);
const char* filepath;
float get_pixel(int x,int y); float get_pixel(int x,int y);
void blur(float standard_deviation); void blur(float standard_deviation);
void statistics(); void statistics();