Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix importing '+proj=topocentric ... +type=crs' by using a geocentric CRS as the base CRS #3924

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/iso19111/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10297,6 +10297,12 @@ static bool isGeocentricStep(const std::string &name) {

// ---------------------------------------------------------------------------

static bool isTopocentricStep(const std::string &name) {
return name == "topocentric";
}

// ---------------------------------------------------------------------------

static bool isProjectedStep(const std::string &name) {
if (name == "etmerc" || name == "utm" ||
!getMappingsFromPROJName(name).empty()) {
Expand Down Expand Up @@ -10973,7 +10979,7 @@ GeodeticCRSNNPtr
PROJStringParser::Private::buildGeocentricCRS(int iStep, int iUnitConvert) {
auto &step = steps_[iStep];

assert(isGeocentricStep(step.name));
assert(isGeocentricStep(step.name) || isTopocentricStep(step.name));
assert(iUnitConvert < 0 ||
ci_equal(steps_[iUnitConvert].name, "unitconvert"));

Expand Down Expand Up @@ -11625,6 +11631,13 @@ PROJStringParser::Private::buildProjectedCRS(int iStep,
? CartesianCS::create(emptyPropertyMap, axis[0], axis[1])
: CartesianCS::create(emptyPropertyMap, axis[0], axis[1],
csGeodCRS->axisList()[2]);
if (isTopocentricStep(step.name)) {
cs = CartesianCS::create(
emptyPropertyMap,
createAxis("topocentric East", "U", AxisDirection::EAST, unit),
createAxis("topocentric North", "V", AxisDirection::NORTH, unit),
createAxis("topocentric Up", "W", AxisDirection::UP, unit));
}

auto props = PropertyMap().set(IdentifiedObject::NAME_KEY,
title.empty() ? "unknown" : title);
Expand Down Expand Up @@ -11731,6 +11744,10 @@ PROJStringParser::createFromPROJString(const std::string &projString) {
(d->steps_.size() == 2 && d->steps_[1].name == "unitconvert")) &&
!d->steps_[0].inverted && isGeocentricStep(d->steps_[0].name);

const bool isTopocentricCRS =
(d->steps_.size() == 1 && isTopocentricStep(d->steps_[0].name) &&
d->getParamValue(d->steps_[0], "type") == "crs");

// +init=xxxx:yyyy syntax
if (d->steps_.size() == 1 && d->steps_[0].isInit &&
!d->steps_[0].inverted) {
Expand Down Expand Up @@ -12123,6 +12140,18 @@ PROJStringParser::createFromPROJString(const std::string &projString) {
}
}

if (isTopocentricCRS) {
// First run is dry run to mark all recognized/unrecognized tokens
for (int iter = 0; iter < 2; iter++) {
auto obj = d->buildBoundOrCompoundCRSIfNeeded(
0,
d->buildProjectedCRS(0, d->buildGeocentricCRS(0, -1), -1, -1));
if (iter == 1) {
return nn_static_pointer_cast<BaseObject>(obj);
}
}
}

if (!unexpectedStructure) {
if (iFirstGeogStep == 0 && !d->steps_[iFirstGeogStep].inverted &&
iSecondGeogStep < 0 && iProjStep < 0 &&
Expand Down
7 changes: 7 additions & 0 deletions test/cli/testvarious
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,13 @@ $EXE -d 8 --t_epoch 2022 "GDA2020" "ITRF2014" -E >>${OUT} 2>&1 <<EOF
-30 150
EOF

echo "##############################################################" >> ${OUT}
echo "Test +proj=topocentric +datum=WGS84 +X_0=-3982059.42 +Y_0=3331314.88 +Z_0=3692463.58 +no_defs +type=crs +to EPSG:4978" >> ${OUT}
#
$EXE -d 3 +proj=topocentric +datum=WGS84 +X_0=-3982059.42 +Y_0=3331314.88 +Z_0=3692463.58 +no_defs +type=crs +to EPSG:4978 -E >>${OUT} 2>&1 <<EOF
0 0 0
EOF


# Done!
# do 'diff' with distribution results
Expand Down
3 changes: 3 additions & 0 deletions test/cli/tv_out.dist
Original file line number Diff line number Diff line change
Expand Up @@ -646,3 +646,6 @@ Test --s_epoch
##############################################################
Test --t_epoch
-30 150 -29.99999901 150.00000044 -0.00031879
##############################################################
Test +proj=topocentric +datum=WGS84 +X_0=-3982059.42 +Y_0=3331314.88 +Z_0=3692463.58 +no_defs +type=crs +to EPSG:4978
0 0 0 -3982059.420 3331314.880 3692463.580
50 changes: 50 additions & 0 deletions test/unit/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11860,6 +11860,56 @@ TEST(io, projparse_geoc) {

// ---------------------------------------------------------------------------

TEST(io, projparse_topocentric) {
auto obj = PROJStringParser().createFromPROJString(
"+proj=topocentric +datum=WGS84 +X_0=-3982059.42 +Y_0=3331314.88 "
"+Z_0=3692463.58 +no_defs +type=crs");
auto crs = nn_dynamic_pointer_cast<ProjectedCRS>(obj);
ASSERT_TRUE(crs != nullptr);
auto expected =
"PROJCRS[\"unknown\",\n"
" BASEGEODCRS[\"unknown\",\n"
" DATUM[\"World Geodetic System 1984\",\n"
" ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n"
" LENGTHUNIT[\"metre\",1]],\n"
" ID[\"EPSG\",6326]],\n"
" PRIMEM[\"Greenwich\",0,\n"
" ANGLEUNIT[\"degree\",0.0174532925199433],\n"
" ID[\"EPSG\",8901]]],\n"
" CONVERSION[\"unknown\",\n"
" METHOD[\"Geocentric/topocentric conversions\",\n"
" ID[\"EPSG\",9836]],\n"
" PARAMETER[\"Geocentric X of topocentric "
"origin\",-3982059.42,\n"
" LENGTHUNIT[\"metre\",1],\n"
" ID[\"EPSG\",8837]],\n"
" PARAMETER[\"Geocentric Y of topocentric origin\",3331314.88,\n"
" LENGTHUNIT[\"metre\",1],\n"
" ID[\"EPSG\",8838]],\n"
" PARAMETER[\"Geocentric Z of topocentric origin\",3692463.58,\n"
" LENGTHUNIT[\"metre\",1],\n"
" ID[\"EPSG\",8839]]],\n"
" CS[Cartesian,3],\n"
" AXIS[\"topocentric East (U)\",east,\n"
" ORDER[1],\n"
" LENGTHUNIT[\"metre\",1,\n"
" ID[\"EPSG\",9001]]],\n"
" AXIS[\"topocentric North (V)\",north,\n"
" ORDER[2],\n"
" LENGTHUNIT[\"metre\",1,\n"
" ID[\"EPSG\",9001]]],\n"
" AXIS[\"topocentric Up (W)\",up,\n"
" ORDER[3],\n"
" LENGTHUNIT[\"metre\",1,\n"
" ID[\"EPSG\",9001]]]]";
EXPECT_EQ(
crs->exportToWKT(
WKTFormatter::create(WKTFormatter::Convention::WKT2_2019).get()),
expected);
}

// ---------------------------------------------------------------------------

TEST(io, projparse_projected_wktext) {
std::string input("+proj=merc +foo +wktext +type=crs");
auto obj = PROJStringParser().createFromPROJString(input);
Expand Down
Loading