Skip to content

Commit

Permalink
Merge branch 'OSGeo:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
a0x8o authored Jun 13, 2024
2 parents 6fe3333 + 064ea59 commit 8b6f82a
Show file tree
Hide file tree
Showing 120 changed files with 4,498 additions and 1,897 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/cmake_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,13 @@ jobs:
- name: Build
shell: bash -l {0}
run: cmake --build $GITHUB_WORKSPACE/build --config RelWithDebInfo -j 2

# Works around https://github.com/actions/runner-images/issues/10055
- name: Remove conflicting libraries
shell: bash -l {0}
run: |
find "C:/hostedtoolcache/windows/Java_Temurin-Hotspot_jdk" -name "msvcp140.dll" -exec rm {} \;
- name: test (with ctest)
shell: bash -l {0}
run: |
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/fedora_rawhide/Dockerfile.ci
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
FROM fedora:rawhide

RUN dnf upgrade -y
# FIXME: Exclude update of dnf&rpm themselves as this results in a no longer working dnf
# cf https://github.com/OSGeo/gdal/actions/runs/9448190401/job/26021669415?pr=10173
# Likely a transient issue with Fedora 41 dev cycle
RUN dnf upgrade -y -x dnf -x rpm
RUN dnf install -y --setopt=install_weak_deps=False proj-devel
RUN dnf install -y clang make diffutils ccache cmake \
libxml2-devel libxslt-devel expat-devel xerces-c-devel \
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ubuntu_24.04/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ set -e
LD_LIBRARY_PATH="/opt/instantclient_19_9:/opt/instantclient_19_9/lib:${LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH

# Test development launcher script
gdal_edit --version

export PYTEST="python3 -m pytest -vv -p no:sugar --color=no"

# Run C++ tests
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
autotest/ogr/data/
)
- repo: https://github.com/pycqa/flake8
rev: 3.9.2
rev: 7.0.0
hooks:
- id: flake8
exclude: >
Expand Down
8 changes: 8 additions & 0 deletions alg/contour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,14 @@ CPLErr GDALContourGenerateEx(GDALRasterBandH hBand, void *hLayer,
if (opt)
{
contourInterval = CPLAtof(opt);
// Written this way to catch NaN as well.
if (!(contourInterval > 0))
{
CPLError(CE_Failure, CPLE_AppDefined,
"Invalid value for LEVEL_INTERVAL. Should be strictly "
"positive.");
return CE_Failure;
}
}

double contourBase = 0.0;
Expand Down
16 changes: 16 additions & 0 deletions alg/gdal_crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,22 @@ static void *GDALCreateGCPTransformerEx(int nGCPCount,
psInfo->nRefCount = 1;

psInfo->asGCPs = gdal::GCP::fromC(pasGCPList, nGCPCount);
if (nGCPCount == 2 && nReqOrder == 1 &&
psInfo->asGCPs[0].X() != psInfo->asGCPs[1].X() &&
psInfo->asGCPs[0].Y() != psInfo->asGCPs[1].Y())
{
// Assumes that the 2 GCPs form opposite corners of a rectangle,
// and synthetize a 3rd corner
gdal::GCP newGCP;
newGCP.X() = psInfo->asGCPs[1].X();
newGCP.Y() = psInfo->asGCPs[0].Y();
newGCP.Pixel() = psInfo->asGCPs[1].Pixel();
newGCP.Line() = psInfo->asGCPs[0].Line();
psInfo->asGCPs.emplace_back(std::move(newGCP));

nGCPCount = 3;
pasGCPList = gdal::GCP::c_ptr(psInfo->asGCPs);
}

memcpy(psInfo->sTI.abySignature, GDAL_GTI2_SIGNATURE,
strlen(GDAL_GTI2_SIGNATURE));
Expand Down
20 changes: 11 additions & 9 deletions alg/viewshed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,9 @@ bool Viewshed::writeLine(int nLine, std::vector<double> &vResult)
/// @return True on success, false otherwise.
bool Viewshed::lineProgress()
{
if (nLineCount < oOutExtent.ySize())
if (nLineCount < oCurExtent.ySize())
nLineCount++;
return emitProgress(nLineCount / static_cast<double>(oOutExtent.ySize()));
return emitProgress(nLineCount / static_cast<double>(oCurExtent.ySize()));
}

/// Emit progress information saying that a fraction of work has been completed.
Expand Down Expand Up @@ -404,7 +404,7 @@ std::pair<int, int> Viewshed::adjustHeight(int nYOffset, int nX,
double *const pdfNx)
{
int nLeft = 0;
int nRight = oOutExtent.xSize();
int nRight = oCurExtent.xSize();

// If there is a height adjustment factor other than zero or a max distance,
// calculate the adjusted height of the cell, stopping if we've exceeded the max
Expand All @@ -430,7 +430,7 @@ std::pair<int, int> Viewshed::adjustHeight(int nYOffset, int nX,
}

pdfHeight = pdfNx + 1;
for (int nXOffset = 1; nXOffset < oOutExtent.xSize() - nX;
for (int nXOffset = 1; nXOffset < oCurExtent.xSize() - nX;
nXOffset++, pdfHeight++)
{
double dfX = adfTransform[1] * nXOffset + dfLineX;
Expand All @@ -447,7 +447,7 @@ std::pair<int, int> Viewshed::adjustHeight(int nYOffset, int nX,
else
{
double *pdfHeight = pdfNx - nX;
for (int i = 0; i < oOutExtent.xSize(); ++i)
for (int i = 0; i < oCurExtent.xSize(); ++i)
{
*pdfHeight -= dfZObserver;
pdfHeight++;
Expand Down Expand Up @@ -664,7 +664,7 @@ bool Viewshed::processFirstLine(int nX, int nY, int nLine,
vResult[nX] = oOpts.visibleVal;
if (nX - 1 >= 0)
vResult[nX - 1] = oOpts.visibleVal;
if (nX + 1 < oOutExtent.xSize())
if (nX + 1 < oCurExtent.xSize())
vResult[nX + 1] = oOpts.visibleVal;
}

Expand Down Expand Up @@ -816,6 +816,8 @@ bool Viewshed::run(GDALRasterBandH band, GDALProgressFunc pfnProgress,
return false;

// normalize horizontal index to [ 0, oOutExtent.xSize() )
oCurExtent = oOutExtent;
oCurExtent.shiftX(-oOutExtent.xStart);
nX -= oOutExtent.xStart;

// create the output dataset
Expand All @@ -824,7 +826,7 @@ bool Viewshed::run(GDALRasterBandH band, GDALProgressFunc pfnProgress,

oZcalc = doLine;

std::vector<double> vFirstLineVal(oOutExtent.xSize());
std::vector<double> vFirstLineVal(oCurExtent.xSize());

if (!processFirstLine(nX, nY, nY, vFirstLineVal))
return false;
Expand All @@ -846,7 +848,7 @@ bool Viewshed::run(GDALRasterBandH band, GDALProgressFunc pfnProgress,
std::vector<double> vLastLineVal = vFirstLineVal;

for (int nLine = nY - 1;
nLine >= oOutExtent.yStart && !err; nLine--)
nLine >= oCurExtent.yStart && !err; nLine--)
if (!processLine(nX, nY, nLine, vLastLineVal))
err = true;
});
Expand All @@ -858,7 +860,7 @@ bool Viewshed::run(GDALRasterBandH band, GDALProgressFunc pfnProgress,
{
std::vector<double> vLastLineVal = vFirstLineVal;

for (int nLine = nY + 1; nLine < oOutExtent.yStop && !err; nLine++)
for (int nLine = nY + 1; nLine < oCurExtent.yStop && !err; nLine++)
if (!processLine(nX, nY, nLine, vLastLineVal))
err = true;
});
Expand Down
12 changes: 10 additions & 2 deletions alg/viewshed.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ class Viewshed
{
return yStop - yStart;
}

/// \brief Shift the X dimension by nShift
void shiftX(int nShift)
{
xStart += nShift;
xStop += nShift;
}
};

/**
Expand Down Expand Up @@ -130,8 +137,8 @@ class Viewshed
* @param opts Options to use when calculating viewshed.
*/
CPL_DLL explicit Viewshed(const Options &opts)
: oOpts{opts}, oOutExtent{}, dfMaxDistance2{opts.maxDistance *
opts.maxDistance},
: oOpts{opts}, oOutExtent{}, oCurExtent{},
dfMaxDistance2{opts.maxDistance * opts.maxDistance},
dfZObserver{0}, poDstDS{}, pSrcBand{}, pDstBand{},
dfHeightAdjFactor{0}, nLineCount{0}, adfTransform{0, 1, 0, 0, 0, 1},
adfInvTransform{}, oProgress{}, oZcalc{}, oMutex{}, iMutex{}
Expand Down Expand Up @@ -159,6 +166,7 @@ class Viewshed
private:
Options oOpts;
Window oOutExtent;
Window oCurExtent;
double dfMaxDistance2;
double dfZObserver;
std::unique_ptr<GDALDataset> poDstDS;
Expand Down
2 changes: 2 additions & 0 deletions apps/argparse/README.TXT
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Provenance: https://github.com/p-ranav/argparse

Retrieved: https://github.com/p-ranav/argparse/blob/8dead89026466b3818e9c6b6b1d938600db39d8f/include/argparse/argparse.hpp
+ patch of https://github.com/p-ranav/argparse/pull/356 (FEATURE: multiple actions)
+ patch of https://github.com/p-ranav/argparse/pull/363 (Accept integer literals in store_into)

18 changes: 16 additions & 2 deletions apps/argparse/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,14 @@ class Argument {
template <typename T, typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
auto &store_into(T &var) {
if (m_default_value.has_value()) {
var = std::any_cast<T>(m_default_value);
try
{
var = std::any_cast<T>(m_default_value);
}
catch (...)
{
var = static_cast<T>(std::any_cast<int>(m_default_value));
}
}
action([&var](const auto &s) {
var = details::parse_number<T, details::radix_10>()(s);
Expand All @@ -712,7 +719,14 @@ class Argument {

auto &store_into(double &var) {
if (m_default_value.has_value()) {
var = std::any_cast<double>(m_default_value);
try
{
var = std::any_cast<double>(m_default_value);
}
catch (...)
{
var = std::any_cast<int>(m_default_value);
}
}
action([&var](const auto &s) {
var = details::parse_number<double, details::chars_format::general>()(s);
Expand Down
86 changes: 59 additions & 27 deletions apps/gdal_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,30 +123,9 @@ GDALCreateAppOptionsGetParser(GDALCreateOptions *psOptions)
.store_into(psOptions->nBandCount)
.help(_("Set the number of bands in the output file."));

argParser->add_argument("-burn")
.metavar("<value>")
.nargs(nargs_pattern::at_least_one)
.append()
.action(
[psOptions](const std::string &s)
{
if (s.find(' ') != std::string::npos)
{
const CPLStringList aosTokens(CSLTokenizeString(s.c_str()));
for (int i = 0; i < aosTokens.size(); i++)
{
psOptions->adfBurnValues.push_back(
CPLAtof(aosTokens[i]));
}
}
else
{
psOptions->adfBurnValues.push_back(CPLAtof(s.c_str()));
}
})
.help(
_("A fixed value to burn into a band for all objects. A list of "
"-burn options can be supplied, one per band being written to."));
argParser->add_argument("-burn").metavar("<value>").append().help(
_("A fixed value to burn into a band. A list of "
"-burn options can be supplied, one per band being written to."));

argParser->add_argument("-a_srs")
.metavar("<srs_def>")
Expand Down Expand Up @@ -253,16 +232,69 @@ MAIN_START(argc, argv)

GDALCreateOptions sOptions;

CPLStringList aosArgv;
for (int iArg = 1; iArg < argc; iArg++)
{
if (iArg + 1 < argc && EQUAL(argv[iArg], "-burn"))
{
++iArg;
while (true)
{
if (strchr(argv[iArg], ' '))
{
const CPLStringList aosTokens(
CSLTokenizeString(argv[iArg]));
for (int i = 0; i < aosTokens.size(); i++)
{
char *endptr = nullptr;
sOptions.adfBurnValues.push_back(
CPLStrtodM(aosTokens[i], &endptr));
if (endptr != aosTokens[i] + strlen(aosTokens[i]))
{
fprintf(stderr, "Invalid value for -burn\n");
CSLDestroy(argv);
GDALExit(1);
}
}
}
else
{
char *endptr = nullptr;
sOptions.adfBurnValues.push_back(
CPLStrtodM(argv[iArg], &endptr));
if (endptr != argv[iArg] + strlen(argv[iArg]))
{
fprintf(stderr, "Invalid value for -burn\n");
CSLDestroy(argv);
GDALExit(1);
}
}
if (iArg + 1 < argc &&
CPLGetValueType(argv[iArg + 1]) != CPL_VALUE_STRING)
{
++iArg;
}
else
{
break;
}
}
}
else
{
aosArgv.AddString(argv[iArg]);
}
}
CSLDestroy(argv);

try
{

auto argParser = GDALCreateAppOptionsGetParser(&sOptions);
argParser->parse_args_without_binary_name(argv + 1);
CSLDestroy(argv);
argParser->parse_args_without_binary_name(aosArgv.List());
}
catch (const std::exception &error)
{
CSLDestroy(argv);
CPLError(CE_Failure, CPLE_AppDefined, "%s", error.what());
GDALExit(1);
}
Expand Down
10 changes: 10 additions & 0 deletions apps/gdalargumentparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,18 @@
// Use our locale-unaware strtod()
#define ARGPARSE_CUSTOM_STRTOD CPLStrtodM

#ifdef _MSC_VER
#pragma warning(push)
// unreachable code
#pragma warning(disable : 4702)
#endif

#include "argparse/argparse.hpp"

#ifdef _MSC_VER
#pragma warning(pop)
#endif

using namespace argparse;

// Place-holder macro using gettext() convention to indicate (future) translatable strings
Expand Down
8 changes: 5 additions & 3 deletions apps/gdalinfo_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,10 +639,12 @@ char *GDALInfo(GDALDatasetH hDataset, const GDALInfoOptions *psOptions)
{
std::string osCoordinateEpoch =
CPLSPrintf("%f", dfCoordinateEpoch);
if (osCoordinateEpoch.find('.') != std::string::npos)
const size_t nDotPos = osCoordinateEpoch.find('.');
if (nDotPos != std::string::npos)
{
while (osCoordinateEpoch.back() == '0')
osCoordinateEpoch.resize(osCoordinateEpoch.size() - 1);
while (osCoordinateEpoch.size() > nDotPos + 2 &&
osCoordinateEpoch.back() == '0')
osCoordinateEpoch.pop_back();
}
Concat(osStr, psOptions->bStdoutOutput,
"Coordinate epoch: %s\n", osCoordinateEpoch.c_str());
Expand Down
Loading

0 comments on commit 8b6f82a

Please sign in to comment.