aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2021-04-11 22:38:03 +0200
committerEven Rouault <even.rouault@spatialys.com>2021-04-11 22:50:12 +0200
commit2ac8170863c56de3f7995ac25e74c6fab8aaacad (patch)
treee98b0cf4f20bde2413f4dfd729360a3523159ae6
parentf683aa04d6f83a6da8e23def22ac8480ccf7d325 (diff)
downloadPROJ-2ac8170863c56de3f7995ac25e74c6fab8aaacad.tar.gz
PROJ-2ac8170863c56de3f7995ac25e74c6fab8aaacad.zip
projinfo --list-crs --area: make it work when multiple areas matches the specified name
-rw-r--r--src/apps/projinfo.cpp20
-rwxr-xr-xtest/cli/testprojinfo5
-rw-r--r--test/cli/testprojinfo_out.dist3
3 files changed, 22 insertions, 6 deletions
diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp
index 0f11cd58..deb8b190 100644
--- a/src/apps/projinfo.cpp
+++ b/src/apps/projinfo.cpp
@@ -168,7 +168,8 @@ static std::string c_ify_string(const std::string &str) {
static ExtentPtr makeBboxFilter(DatabaseContextPtr dbContext,
const std::string &bboxStr,
- const std::string &area) {
+ const std::string &area,
+ bool errorIfSeveralAreaMatches) {
ExtentPtr bboxFilter = nullptr;
if (!bboxStr.empty()) {
auto bbox(split(bboxStr, ','));
@@ -225,7 +226,7 @@ static ExtentPtr makeBboxFilter(DatabaseContextPtr dbContext,
std::cerr << "No area of use matching provided name"
<< std::endl;
std::exit(1);
- } else {
+ } else if (errorIfSeveralAreaMatches) {
std::cerr << "Several candidates area of use "
"matching provided name :"
<< std::endl;
@@ -1369,16 +1370,19 @@ int main(int argc, char **argv) {
}
}
- auto bboxFilter = makeBboxFilter(dbContext, bboxStr, area);
+ const std::string areaLower = tolower(area);
+ // If the area name has more than a single match, we
+ // will do filtering on info.areaName
+ auto bboxFilter = makeBboxFilter(dbContext, bboxStr, area, false);
auto allowedAuthorities(outputOpt.allowedAuthorities);
if (allowedAuthorities.empty()) {
allowedAuthorities.emplace_back(std::string());
}
- for (auto auth_name : allowedAuthorities) {
+ for (const auto &auth_name : allowedAuthorities) {
try {
auto factory =
AuthorityFactory::create(NN_NO_CHECK(dbContext), auth_name);
- auto list = factory->getCRSInfoList();
+ const auto list = factory->getCRSInfoList();
for (const auto &info : list) {
if (!allow_deprecated && info.deprecated) {
continue;
@@ -1405,6 +1409,10 @@ int main(int argc, char **argv) {
continue;
}
}
+ } else if (!area.empty() &&
+ tolower(info.areaName).find(areaLower) ==
+ std::string::npos) {
+ continue;
}
std::cout << info.authName << ":" << info.code << " \""
<< info.name << "\""
@@ -1552,7 +1560,7 @@ int main(int argc, char **argv) {
std::exit(1);
}
} else {
- auto bboxFilter = makeBboxFilter(dbContext, bboxStr, area);
+ auto bboxFilter = makeBboxFilter(dbContext, bboxStr, area, true);
try {
outputOperations(
dbContext, sourceCRSStr, targetCRSStr, bboxFilter,
diff --git a/test/cli/testprojinfo b/test/cli/testprojinfo
index 0ee256a2..ce8cd762 100755
--- a/test/cli/testprojinfo
+++ b/test/cli/testprojinfo
@@ -362,6 +362,11 @@ echo 'Testing --list-crs projected --bbox -100,40,-90,41 --spatial-test intersec
$EXE --list-crs projected --bbox -100,40,-90,41 --spatial-test intersects | grep "(2011).*Missouri East\|York" | sort >> ${OUT}
echo "" >>${OUT}
+# Test case where --area has several matches
+echo 'Testing --list-crs projected --area France | grep "RGF93 / Lambert-93\|UTM zone 11N" | sort' >> ${OUT}
+$EXE --list-crs projected --area France | grep "RGF93 / Lambert-93\|UTM zone 11N" | sort >> ${OUT}
+echo "" >>${OUT}
+
# do 'diff' with distribution results
echo "diff ${OUT} with testprojinfo_out.dist"
diff -u ${OUT} ${TEST_CLI_DIR}/testprojinfo_out.dist
diff --git a/test/cli/testprojinfo_out.dist b/test/cli/testprojinfo_out.dist
index 3f549fd9..4f48b222 100644
--- a/test/cli/testprojinfo_out.dist
+++ b/test/cli/testprojinfo_out.dist
@@ -1654,3 +1654,6 @@ ESRI:104010 "GCS_IGS08" [deprecated]
Testing --list-crs projected --bbox -100,40,-90,41 --spatial-test intersects | grep "(2011).*Missouri East\|York" | sort
EPSG:6512 "NAD83(2011) / Missouri East"
+Testing --list-crs projected --area France | grep "RGF93 / Lambert-93\|UTM zone 11N" | sort
+EPSG:2154 "RGF93 / Lambert-93"
+