diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2022-03-17 22:18:22 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-17 22:18:22 +0100 |
| commit | ab3383a4483f65679ae4a687cc8660572cd6102c (patch) | |
| tree | ab0d528ffa0cda0f0b61f8e26936dc828b24402b /src | |
| parent | 1c1a3c5930229644440a7e41d032cc217cf2f8c0 (diff) | |
| parent | 3e7984f3b26e408e69b960f8e0d03b6ac0576188 (diff) | |
| download | PROJ-ab3383a4483f65679ae4a687cc8660572cd6102c.tar.gz PROJ-ab3383a4483f65679ae4a687cc8660572cd6102c.zip | |
Merge pull request #3119 from rouault/compound_to_2D_crs
Transformation: no longer do vertical trasnformation when doing compound CRS to 2D CRS / add --3d to cs2cs
Diffstat (limited to 'src')
| -rw-r--r-- | src/apps/cs2cs.cpp | 9 | ||||
| -rw-r--r-- | src/iso19111/io.cpp | 10 | ||||
| -rw-r--r-- | src/iso19111/operation/coordinateoperationfactory.cpp | 13 |
3 files changed, 27 insertions, 5 deletions
diff --git a/src/apps/cs2cs.cpp b/src/apps/cs2cs.cpp index a8e152a7..e21ecd8b 100644 --- a/src/apps/cs2cs.cpp +++ b/src/apps/cs2cs.cpp @@ -78,7 +78,7 @@ static const char *oterr = "*\t*"; /* output line for unprojectable input */ static const char *usage = "%s\nusage: %s [-dDeEfIlrstvwW [args]]\n" " [[--area name_or_code] | [--bbox west_long,south_lat,east_long,north_lat]]\n" - " [--authority {name}] [--accuracy {accuracy}] [--no-ballpark]\n" + " [--authority {name}] [--accuracy {accuracy}] [--no-ballpark] [--3d]\n" " [+opt[=arg] ...] [+to +opt[=arg] ...] [file ...]\n"; static double (*informat)(const char *, @@ -384,6 +384,7 @@ int main(int argc, char **argv) { const char* authority = nullptr; double accuracy = -1; bool allowBallpark = true; + bool promoteTo3D = false; /* process run line arguments */ while (--argc > 0) { /* collect run line arguments */ @@ -449,6 +450,9 @@ int main(int argc, char **argv) { else if (strcmp(*argv, "--no-ballpark") == 0 ) { allowBallpark = false; } + else if (strcmp(*argv, "--3d") == 0 ) { + promoteTo3D = true; + } else if (**argv == '-') { for (arg = *argv;;) { switch (*++arg) { @@ -785,8 +789,7 @@ int main(int argc, char **argv) { src = proj_create(nullptr, pj_add_type_crs_if_needed(fromStr).c_str()); dst = proj_create(nullptr, pj_add_type_crs_if_needed(toStr).c_str()); - if( proj_get_type(src) == PJ_TYPE_COMPOUND_CRS || - proj_get_type(dst) == PJ_TYPE_COMPOUND_CRS ) { + if( promoteTo3D ) { auto src3D = proj_crs_promote_to_3D(nullptr, nullptr, src); if( src3D ) { proj_destroy(src); diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp index d4c6aec1..e09aee93 100644 --- a/src/iso19111/io.cpp +++ b/src/iso19111/io.cpp @@ -10525,12 +10525,18 @@ PROJStringParser::createFromPROJString(const std::string &projString) { } auto geogCRS = dynamic_cast<GeographicCRS *>(crs); if (geogCRS) { + const auto &cs = geogCRS->coordinateSystem(); // Override with longitude latitude in degrees return GeographicCRS::create( properties, geogCRS->datum(), geogCRS->datumEnsemble(), - EllipsoidalCS::createLongitudeLatitude( - UnitOfMeasure::DEGREE)); + cs->axisList().size() == 2 + ? EllipsoidalCS::createLongitudeLatitude( + UnitOfMeasure::DEGREE) + : EllipsoidalCS:: + createLongitudeLatitudeEllipsoidalHeight( + UnitOfMeasure::DEGREE, + cs->axisList()[2]->unit())); } auto projCRS = dynamic_cast<ProjectedCRS *>(crs); if (projCRS) { diff --git a/src/iso19111/operation/coordinateoperationfactory.cpp b/src/iso19111/operation/coordinateoperationfactory.cpp index 20042f22..a6a2c986 100644 --- a/src/iso19111/operation/coordinateoperationfactory.cpp +++ b/src/iso19111/operation/coordinateoperationfactory.cpp @@ -4926,6 +4926,19 @@ void CoordinateOperationFactory::Private::createOperationsCompoundToGeog( } } + // Only do a vertical transformation if the target CRS is 3D. + const auto dstSingle = dynamic_cast<crs::SingleCRS *>(targetCRS.get()); + if (dstSingle && + dstSingle->coordinateSystem()->axisList().size() == 2) { + auto tmp = createOperations(componentsSrc[0], targetCRS, context); + for (const auto &op : tmp) { + auto opClone = op->shallowClone(); + setCRSs(opClone.get(), sourceCRS, targetCRS); + res.emplace_back(opClone); + } + return; + } + std::vector<CoordinateOperationNNPtr> horizTransforms; auto srcGeogCRS = componentsSrc[0]->extractGeographicCRS(); if (srcGeogCRS) { |
