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

add PJ_TYPE_DERIVED_PROJECTED_CRS #3488

Merged
merged 1 commit into from
Nov 25, 2022
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
3 changes: 2 additions & 1 deletion src/apps/cs2cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ static bool is3DCRS(const PJ* crs) {
return true;
if( type == PJ_TYPE_GEOGRAPHIC_3D_CRS )
return true;
if( type == PJ_TYPE_GEODETIC_CRS || type == PJ_TYPE_PROJECTED_CRS )
if( type == PJ_TYPE_GEODETIC_CRS || type == PJ_TYPE_PROJECTED_CRS ||
type == PJ_TYPE_DERIVED_PROJECTED_CRS)
{
auto cs = proj_crs_get_coordinate_system(nullptr, crs);
assert(cs);
Expand Down
33 changes: 17 additions & 16 deletions src/iso19111/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,10 @@ convertPJObjectTypeToObjectType(PJ_TYPE type, bool &valid) {
cppType = AuthorityFactory::ObjectType::PROJECTED_CRS;
break;

case PJ_TYPE_DERIVED_PROJECTED_CRS:
valid = false;
break;

case PJ_TYPE_COMPOUND_CRS:
cppType = AuthorityFactory::ObjectType::COMPOUND_CRS;
break;
Expand Down Expand Up @@ -1201,25 +1205,19 @@ PJ_TYPE proj_get_type(const PJ *obj) {
return PJ_TYPE_PARAMETRIC_DATUM;
}

{
auto crs = dynamic_cast<GeographicCRS *>(ptr);
if (crs) {
if (crs->coordinateSystem()->axisList().size() == 2) {
return PJ_TYPE_GEOGRAPHIC_2D_CRS;
} else {
return PJ_TYPE_GEOGRAPHIC_3D_CRS;
}
if (auto crs = dynamic_cast<GeographicCRS *>(ptr)) {
if (crs->coordinateSystem()->axisList().size() == 2) {
return PJ_TYPE_GEOGRAPHIC_2D_CRS;
} else {
return PJ_TYPE_GEOGRAPHIC_3D_CRS;
}
}

{
auto crs = dynamic_cast<GeodeticCRS *>(ptr);
if (crs) {
if (crs->isGeocentric()) {
return PJ_TYPE_GEOCENTRIC_CRS;
} else {
return PJ_TYPE_GEODETIC_CRS;
}
if (auto crs = dynamic_cast<GeodeticCRS *>(ptr)) {
if (crs->isGeocentric()) {
return PJ_TYPE_GEOCENTRIC_CRS;
} else {
return PJ_TYPE_GEODETIC_CRS;
}
}

Expand All @@ -1229,6 +1227,9 @@ PJ_TYPE proj_get_type(const PJ *obj) {
if (dynamic_cast<ProjectedCRS *>(ptr)) {
return PJ_TYPE_PROJECTED_CRS;
}
if (dynamic_cast<DerivedProjectedCRS *>(ptr)) {
return PJ_TYPE_DERIVED_PROJECTED_CRS;
}
if (dynamic_cast<CompoundCRS *>(ptr)) {
return PJ_TYPE_COMPOUND_CRS;
}
Expand Down
2 changes: 2 additions & 0 deletions src/proj.h
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,8 @@ typedef enum
PJ_TYPE_TEMPORAL_DATUM,
PJ_TYPE_ENGINEERING_DATUM,
PJ_TYPE_PARAMETRIC_DATUM,

PJ_TYPE_DERIVED_PROJECTED_CRS,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it at the end of the enum for backward compatibility. If it is better anywhere else, let me know.

} PJ_TYPE;

/** Comparison criterion. */
Expand Down
27 changes: 27 additions & 0 deletions test/unit/test_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ class CApi : public ::testing::Test {
CartesianCS::createEastingNorthing(UnitOfMeasure::METRE));
}

static DerivedProjectedCRSNNPtr createDerivedProjectedCRS() {
auto derivingConversion = Conversion::create(
PropertyMap().set(IdentifiedObject::NAME_KEY, "unnamed"),
PropertyMap().set(IdentifiedObject::NAME_KEY, "PROJ unimplemented"),
std::vector<OperationParameterNNPtr>{},
std::vector<ParameterValueNNPtr>{});

return DerivedProjectedCRS::create(
PropertyMap().set(IdentifiedObject::NAME_KEY,
"derived projectedCRS"),
createProjectedCRS(), derivingConversion,
CartesianCS::createEastingNorthing(UnitOfMeasure::METRE));
}

static VerticalCRSNNPtr createVerticalCRS() {
PropertyMap propertiesVDatum;
propertiesVDatum.set(Identifier::CODESPACE_KEY, "EPSG")
Expand Down Expand Up @@ -820,6 +834,19 @@ TEST_F(CApi, proj_get_type) {
ASSERT_NE(obj, nullptr);
EXPECT_EQ(proj_get_type(obj), PJ_TYPE_PROJECTED_CRS);
}
{
auto obj = proj_create_from_wkt(
m_ctxt,
createDerivedProjectedCRS()
->exportToWKT(
WKTFormatter::create(WKTFormatter::Convention::WKT2_2019)
.get())
.c_str(),
nullptr, nullptr, nullptr);
ObjectKeeper keeper(obj);
ASSERT_NE(obj, nullptr);
EXPECT_EQ(proj_get_type(obj), PJ_TYPE_DERIVED_PROJECTED_CRS);
}
{
auto obj =
proj_create_from_wkt(m_ctxt,
Expand Down