Skip to content

Commit

Permalink
cs2cs and projinfo: emit warning when it looks like longitude and lat…
Browse files Browse the repository at this point in the history
…itudes have been switched in --bbox
  • Loading branch information
rouault committed Aug 27, 2024
1 parent 85c6a0e commit 903cfff
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
21 changes: 18 additions & 3 deletions src/apps/cs2cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <string.h>

#include <cassert>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <string>
Expand Down Expand Up @@ -448,9 +449,23 @@ int main(int argc, char **argv) {
std::exit(1);
}
try {
bboxFilter = Extent::createFromBBOX(
c_locale_stod(bbox[0]), c_locale_stod(bbox[1]),
c_locale_stod(bbox[2]), c_locale_stod(bbox[3]))
std::vector<double> bboxValues = {
c_locale_stod(bbox[0]), c_locale_stod(bbox[1]),
c_locale_stod(bbox[2]), c_locale_stod(bbox[3])};
const double west = bboxValues[0];
const double south = bboxValues[1];
const double east = bboxValues[2];
const double north = bboxValues[3];
constexpr double SOME_MARGIN = 10;
if (south < -90 - SOME_MARGIN && std::fabs(west) <= 90 &&
std::fabs(east) <= 90)
std::cerr << "Warning: suspicious south latitude: " << south
<< std::endl;
if (north > 90 + SOME_MARGIN && std::fabs(west) <= 90 &&
std::fabs(east) <= 90)
std::cerr << "Warning: suspicious north latitude: " << north
<< std::endl;
bboxFilter = Extent::createFromBBOX(west, south, east, north)
.as_nullable();
} catch (const std::exception &e) {
std::cerr << "Invalid value for option --bbox: " << bboxStr
Expand Down
19 changes: 16 additions & 3 deletions src/apps/projinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#define FROM_PROJ_CPP

#include <cmath>
#include <cstdlib>
#include <fstream> // std::ifstream
#include <iostream>
Expand Down Expand Up @@ -187,9 +188,21 @@ static ExtentPtr makeBboxFilter(DatabaseContextPtr dbContext,
std::vector<double> bboxValues = {
c_locale_stod(bbox[0]), c_locale_stod(bbox[1]),
c_locale_stod(bbox[2]), c_locale_stod(bbox[3])};
bboxFilter = Extent::createFromBBOX(bboxValues[0], bboxValues[1],
bboxValues[2], bboxValues[3])
.as_nullable();
const double west = bboxValues[0];
const double south = bboxValues[1];
const double east = bboxValues[2];
const double north = bboxValues[3];
constexpr double SOME_MARGIN = 10;
if (south < -90 - SOME_MARGIN && std::fabs(west) <= 90 &&
std::fabs(east) <= 90)
std::cerr << "Warning: suspicious south latitude: " << south
<< std::endl;
if (north > 90 + SOME_MARGIN && std::fabs(west) <= 90 &&
std::fabs(east) <= 90)
std::cerr << "Warning: suspicious north latitude: " << north
<< std::endl;
bboxFilter =
Extent::createFromBBOX(west, south, east, north).as_nullable();
} catch (const std::exception &e) {
std::cerr << "Invalid value for option --bbox: " << bboxStr << ", "
<< e.what() << std::endl;
Expand Down

0 comments on commit 903cfff

Please sign in to comment.