Skip to content

Commit

Permalink
fixes #1100
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Apr 6, 2023
1 parent ebbbe63 commit 48264db
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/gdal_algs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,28 +1128,27 @@ SpatRaster SpatRaster::viewshed(const std::vector<double> obs, const std::vector
x = replaceValues({NAN}, {minval}, 0, false, NAN, false, topt);
}

std::string filename = opt.get_filename();
std::string fname = opt.get_filename();
std::string driver;
if (filename.empty()) {
filename = tempFile(opt.get_tempdir(), opt.pid, ".tif");
driver = "GTiff";
} else {
if (!fname.empty()) {
driver = opt.get_filetype();
getGDALdriver(filename, driver);
getGDALdriver(fname, driver);
if (driver.empty()) {
setError("cannot guess file type from filename");
return out;
}
std::string errmsg;
if (!can_write({filename}, filenames(), opt.get_overwrite(), errmsg)) {
if (!can_write({fname}, filenames(), opt.get_overwrite(), errmsg)) {
out.setError(errmsg);
return out;
}
}

std::string filename = tempFile(topt.get_tempdir(), topt.pid, ".tif");
driver = "GTiff";

GDALDatasetH hSrcDS;
SpatOptions ops(opt);
if (!x.open_gdal(hSrcDS, 0, false, ops)) {
if (!x.open_gdal(hSrcDS, 0, false, topt)) {
out.setError("cannot open input dataset");
return out;
}
Expand All @@ -1161,7 +1160,7 @@ SpatRaster SpatRaster::viewshed(const std::vector<double> obs, const std::vector
}

GIntBig diskNeeded = ncell() * 4;
char **papszOptions = set_GDAL_options(driver, diskNeeded, false, opt.gdal_options);
char **papszOptions = set_GDAL_options(driver, diskNeeded, false, topt.gdal_options);

GDALRasterBandH hSrcBand = GDALGetRasterBand(hSrcDS, 1);

Expand Down

0 comments on commit 48264db

Please sign in to comment.