Skip to content

Commit 5ae4663

Browse files
Andrew BellAndrew Bell
authored andcommitted
Verification.
1 parent 589feaf commit 5ae4663

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

alg/viewshed/viewshed.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,13 @@ bool Viewshed::calcExtents(int nX, int nY, const GDALGeoTransform &invGT)
373373
bool Viewshed::run(GDALRasterBandH band, GDALProgressFunc pfnProgress,
374374
void *pProgressArg)
375375
{
376+
DatasetPtr sdDataset;
377+
if (oOpts.sdFilename.size())
378+
{
379+
GDALDatasetH ds = GDALOpen(oOpts.sdFilename.c_str(), GA_ReadOnly);
380+
sdDataset.reset(GDALDataset::FromHandle(ds));
381+
pSdBand = sdDataset->GetRasterBand(1);
382+
}
376383
pSrcBand = static_cast<GDALRasterBand *>(band);
377384

378385
GDALGeoTransform fwdTransform, invTransform;
@@ -443,10 +450,20 @@ bool Viewshed::run(GDALRasterBandH band, GDALProgressFunc pfnProgress,
443450

444451
// Execute the viewshed algorithm.
445452
GDALRasterBand *pDstBand = poDstDS->GetRasterBand(1);
446-
ViewshedExecutor executor(*pSrcBand, *pDstBand, nX, nY, oOutExtent,
453+
if (pSdBand)
454+
{
455+
ViewshedExecutor executor(*pSrcBand, *pSdBand, *pDstBand, nX, nY,
456+
oOutExtent, oCurExtent, oOpts, oProgress,
457+
/* emitWarningIfNoData = */ true);
458+
executor.run();
459+
}
460+
else
461+
{
462+
ViewshedExecutor executor(*pSrcBand, *pDstBand, nX, nY, oOutExtent,
447463
oCurExtent, oOpts, oProgress,
448464
/* emitWarningIfNoData = */ true);
449-
executor.run();
465+
executor.run();
466+
}
450467
oProgress.emit(1);
451468
return static_cast<bool>(poDstDS);
452469
}

alg/viewshed/viewshed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class Viewshed
6969
Window oCurExtent{};
7070
DatasetPtr poDstDS{};
7171
GDALRasterBand *pSrcBand = nullptr;
72+
GDALRasterBand *pSdBand = nullptr;
7273

7374
DatasetPtr execute(int nX, int nY, const std::string &outFilename);
7475
void setOutput(double &dfResult, double &dfCellVal, double dfZ);

alg/viewshed/viewshed_executor.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
* SPDX-License-Identifier: MIT
1212
****************************************************************************/
1313

14+
//ABELL
15+
#include <iostream>
16+
1417
#include <algorithm>
1518
#include <atomic>
1619
#include <cassert>
@@ -295,7 +298,6 @@ bool ViewshedExecutor::readLine(int nLine, Lines &lines)
295298

296299
if (sdMode())
297300
{
298-
lines.input = lines.cur;
299301
double nodata = m_sdBand.GetNoDataValue();
300302
int sdStatus = m_sdBand.RasterIO(
301303
GF_Read, oOutExtent.xStart, nLine, oOutExtent.xSize(), 1,
@@ -497,6 +499,9 @@ bool ViewshedExecutor::processFirstLine(Lines &lines)
497499
m_dfZObserver += lines.cur[m_nX];
498500

499501
LineLimits ll = adjustHeight(nYOffset, lines);
502+
if (sdMode())
503+
lines.input = lines.cur;
504+
500505
if (oCurExtent.containsX(m_nX))
501506
{
502507
if (ll.leftMin != ll.rightMin)
@@ -513,9 +518,13 @@ bool ViewshedExecutor::processFirstLine(Lines &lines)
513518
else
514519
{
515520
CPLJobQueuePtr pQueue = m_pool.CreateJobQueue();
521+
/**
516522
pQueue->SubmitJob([&]() { processFirstLineLeft(ll, lines); });
517523
pQueue->SubmitJob([&]() { processFirstLineRight(ll, lines); });
518524
pQueue->WaitCompletion();
525+
**/
526+
processFirstLineLeft(ll, lines);
527+
processFirstLineRight(ll, lines);
519528
}
520529
sdCalc = false;
521530
};
@@ -871,6 +880,11 @@ void ViewshedExecutor::processLineLeft(int nYOffset, LineLimits &ll,
871880
else
872881
dfZ = oZcalc(nXOffset, nYOffset, lines.cur[iPixel + 1],
873882
lines.prev[iPixel], lines.prev[iPixel + 1]);
883+
if (nLine == 2424 && iPixel == 530)
884+
{
885+
std::cerr << "Val/SD val/dfZ = " << lines.cur[iPixel] << "/" <<
886+
lines.sd[iPixel] << "/" << dfZ << "!\n";
887+
}
874888
setOutput(lines, iPixel, dfZ);
875889
}
876890

@@ -961,6 +975,8 @@ bool ViewshedExecutor::processLine(int nLine, Lines &lines)
961975

962976
// Adjust height of the read line.
963977
LineLimits ll = adjustHeight(nYOffset, lines);
978+
if (sdMode())
979+
lines.input = lines.cur;
964980

965981
// Handle the initial position on the line.
966982
if (oCurExtent.containsX(m_nX))
@@ -991,6 +1007,8 @@ bool ViewshedExecutor::processLine(int nLine, Lines &lines)
9911007
if (sdMode())
9921008
{
9931009
lines.cur = std::move(lines.input);
1010+
if (nLine == 2424)
1011+
std::cerr << "Cur[530] = " << lines.cur[530] << "!\n";
9941012
process(true);
9951013
}
9961014

alg/viewshed/viewshed_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct Options
7979
double curveCoeff{.85714}; //!< coefficient for atmospheric refraction
8080
OutputMode outputMode{OutputMode::Normal}; //!< Output information.
8181
//!< Normal, Height from DEM or Height from ground
82+
std::string sdFilename{}; //!< sd raster filename
8283
std::string outputFormat{}; //!< output raster format
8384
std::string outputFilename{}; //!< output raster filename
8485
CPLStringList creationOpts{}; //!< options for output raster creation

apps/gdalalg_raster_viewshed.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ GDALRasterViewshedAlgorithm::GDALRasterViewshedAlgorithm(bool standaloneStep)
4545
.SetRepeatedArgAllowed(false);
4646
AddArg("height", 'z', _("Observer height"), &m_opts.observer.z);
4747

48+
AddArg("sd-filename", 0, _("Filename of standard-deviation raster"),
49+
&m_opts.sdFilename);
50+
4851
AddArg("target-height", 0,
4952
_("Height of the target above the DEM surface in the height unit of "
5053
"the DEM."),

0 commit comments

Comments
 (0)