Skip to content

Commit 681d389

Browse files
authored
Merge pull request OSGeo#3830 from rouault/fix_3828
Projected CRS identification: fix crash when the base CRS is a non-geographic geodetic CRS (fixes OSGeo#3828)
2 parents f5d206c + b436980 commit 681d389

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/iso19111/factory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9230,7 +9230,7 @@ AuthorityFactory::createProjectedCRSFromExisting(
92309230
const auto &measure = parameterValue->value();
92319231
const auto &unit = measure.unit();
92329232
if (unit == common::UnitOfMeasure::DEGREE &&
9233-
geogCRS->coordinateSystem()->axisList()[0]->unit() == unit) {
9233+
baseCRS->coordinateSystem()->axisList()[0]->unit() == unit) {
92349234
if (methodEPSGCode ==
92359235
EPSG_CODE_METHOD_LAMBERT_CONIC_CONFORMAL_2SP) {
92369236
// Special case for standard parallels of LCC_2SP. See below

test/unit/test_crs.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3305,6 +3305,53 @@ TEST(crs, projectedCRS_identify_db) {
33053305
EXPECT_EQ(res.front().first->getEPSGCode(), 25832);
33063306
EXPECT_EQ(res.front().second, 70);
33073307
}
3308+
{
3309+
// Identify a projected CRS whose base CRS is not a geographic CRS but
3310+
// a geodetic CRS with a spherical -ocentric coordinate system.
3311+
// Cf https://github.com/OSGeo/PROJ/issues/3828
3312+
auto obj = WKTParser().attachDatabaseContext(dbContext).createFromWKT(
3313+
"PROJCRS[\"unknown\",\n"
3314+
" BASEGEODCRS[\"Mercury (2015) / Ocentric\",\n"
3315+
" DATUM[\"Mercury (2015)\",\n"
3316+
" ELLIPSOID[\"Mercury "
3317+
"(2015)\",2440530,1075.12334801762,\n"
3318+
" LENGTHUNIT[\"metre\",1]],\n"
3319+
" ANCHOR[\"Hun Kal: 20 W.0\"]],\n"
3320+
" PRIMEM[\"Reference Meridian\",0,\n"
3321+
" ANGLEUNIT[\"degree\",0.0174532925199433]],\n"
3322+
" ID[\"IAU\",19902,2015]],\n"
3323+
" CONVERSION[\"Equirectangular, clon = 0\",\n"
3324+
" METHOD[\"Equidistant Cylindrical\",\n"
3325+
" ID[\"EPSG\",1028]],\n"
3326+
" PARAMETER[\"Latitude of 1st standard parallel\",0,\n"
3327+
" ANGLEUNIT[\"degree\",0.0174532925199433],\n"
3328+
" ID[\"EPSG\",8823]],\n"
3329+
" PARAMETER[\"Longitude of natural origin\",0,\n"
3330+
" ANGLEUNIT[\"degree\",0.0174532925199433],\n"
3331+
" ID[\"EPSG\",8802]],\n"
3332+
" PARAMETER[\"False easting\",0,\n"
3333+
" LENGTHUNIT[\"metre\",1],\n"
3334+
" ID[\"EPSG\",8806]],\n"
3335+
" PARAMETER[\"False northing\",0,\n"
3336+
" LENGTHUNIT[\"metre\",1],\n"
3337+
" ID[\"EPSG\",8807]]],\n"
3338+
" CS[Cartesian,2],\n"
3339+
" AXIS[\"(E)\",east,\n"
3340+
" ORDER[1],\n"
3341+
" LENGTHUNIT[\"metre\",1]],\n"
3342+
" AXIS[\"(N)\",north,\n"
3343+
" ORDER[2],\n"
3344+
" LENGTHUNIT[\"metre\",1]]]");
3345+
auto crs = nn_dynamic_pointer_cast<ProjectedCRS>(obj);
3346+
ASSERT_TRUE(crs != nullptr);
3347+
auto allFactory = AuthorityFactory::create(dbContext, std::string());
3348+
auto res = crs->identify(allFactory);
3349+
ASSERT_GE(res.size(), 1U);
3350+
EXPECT_EQ(res.front().first->identifiers()[0]->code(), "19912");
3351+
EXPECT_EQ(*(res.front().first->identifiers()[0]->codeSpace()),
3352+
"IAU_2015");
3353+
EXPECT_EQ(res.front().second, 90);
3354+
}
33083355
}
33093356

33103357
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)