Skip to content

Commit

Permalink
Cleanup: use constants for strings of WKT coordinate system types
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Oct 15, 2023
1 parent 3920d63 commit ab58764
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 62 deletions.
48 changes: 41 additions & 7 deletions include/proj/coordinatesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,16 @@ class PROJ_GCC_DLL SphericalCS final : public CoordinateSystem {
const CoordinateSystemAxisNNPtr &axis1,
const CoordinateSystemAxisNNPtr &axis2);

/** Value of getWKT2Type() */
static constexpr const char *WKT2_TYPE = "spherical";

protected:
PROJ_INTERNAL explicit SphericalCS(
const std::vector<CoordinateSystemAxisNNPtr> &axisIn);
INLINED_MAKE_SHARED

PROJ_INTERNAL std::string getWKT2Type(bool) const override {
return "spherical";
return WKT2_TYPE;
}

private:
Expand Down Expand Up @@ -422,6 +425,9 @@ class PROJ_GCC_DLL EllipsoidalCS final : public CoordinateSystem {
const common::UnitOfMeasure &angularUnit,
const common::UnitOfMeasure &linearUnit);

/** Value of getWKT2Type() */
static constexpr const char *WKT2_TYPE = "ellipsoidal";

//! @cond Doxygen_Suppress

/** \brief Typical axis order. */
Expand Down Expand Up @@ -454,7 +460,7 @@ class PROJ_GCC_DLL EllipsoidalCS final : public CoordinateSystem {
INLINED_MAKE_SHARED

PROJ_INTERNAL std::string getWKT2Type(bool) const override {
return "ellipsoidal";
return WKT2_TYPE;
}

protected:
Expand Down Expand Up @@ -490,6 +496,9 @@ class PROJ_GCC_DLL VerticalCS final : public CoordinateSystem {
PROJ_DLL static VerticalCSNNPtr
createGravityRelatedHeight(const common::UnitOfMeasure &unit);

/** Value of getWKT2Type() */
static constexpr const char *WKT2_TYPE = "vertical";

PROJ_PRIVATE :
//! @cond Doxygen_Suppress
PROJ_INTERNAL VerticalCSNNPtr
Expand All @@ -502,7 +511,7 @@ class PROJ_GCC_DLL VerticalCS final : public CoordinateSystem {
INLINED_MAKE_SHARED

PROJ_INTERNAL std::string getWKT2Type(bool) const override {
return "vertical";
return WKT2_TYPE;
}

private:
Expand Down Expand Up @@ -560,6 +569,10 @@ class PROJ_GCC_DLL CartesianCS final : public CoordinateSystem {
PROJ_DLL static CartesianCSNNPtr
createGeocentric(const common::UnitOfMeasure &unit);

/** Value of getWKT2Type() */
static constexpr const char *WKT2_TYPE =
"Cartesian"; // uppercase is intended

PROJ_PRIVATE :
//! @cond Doxygen_Suppress
PROJ_INTERNAL CartesianCSNNPtr
Expand All @@ -573,7 +586,7 @@ class PROJ_GCC_DLL CartesianCS final : public CoordinateSystem {
INLINED_MAKE_SHARED

PROJ_INTERNAL std::string getWKT2Type(bool) const override {
return "Cartesian"; // uppercase is intended
return WKT2_TYPE;
}

private:
Expand All @@ -600,6 +613,9 @@ class PROJ_GCC_DLL AffineCS final : public CoordinateSystem {
PROJ_DLL ~AffineCS() override;
//! @endcond

/** Value of getWKT2Type() */
static constexpr const char *WKT2_TYPE = "affine";

PROJ_DLL static AffineCSNNPtr
create(const util::PropertyMap &properties,
const CoordinateSystemAxisNNPtr &axis1,
Expand All @@ -623,7 +639,7 @@ class PROJ_GCC_DLL AffineCS final : public CoordinateSystem {
INLINED_MAKE_SHARED

PROJ_INTERNAL std::string getWKT2Type(bool) const override {
return "affine";
return WKT2_TYPE;
}

private:
Expand Down Expand Up @@ -655,13 +671,16 @@ class PROJ_GCC_DLL OrdinalCS final : public CoordinateSystem {
create(const util::PropertyMap &properties,
const std::vector<CoordinateSystemAxisNNPtr> &axisIn);

/** Value of getWKT2Type() */
static constexpr const char *WKT2_TYPE = "ordinal";

protected:
PROJ_INTERNAL explicit OrdinalCS(
const std::vector<CoordinateSystemAxisNNPtr> &axisIn);
INLINED_MAKE_SHARED

PROJ_INTERNAL std::string getWKT2Type(bool) const override {
return "ordinal";
return WKT2_TYPE;
}

private:
Expand Down Expand Up @@ -691,13 +710,16 @@ class PROJ_GCC_DLL ParametricCS final : public CoordinateSystem {
create(const util::PropertyMap &properties,
const CoordinateSystemAxisNNPtr &axisIn);

/** Value of getWKT2Type() */
static constexpr const char *WKT2_TYPE = "parametric";

protected:
PROJ_INTERNAL explicit ParametricCS(
const std::vector<CoordinateSystemAxisNNPtr> &axisIn);
INLINED_MAKE_SHARED

PROJ_INTERNAL std::string getWKT2Type(bool) const override {
return "parametric";
return WKT2_TYPE;
}

private:
Expand Down Expand Up @@ -725,6 +747,9 @@ class PROJ_GCC_DLL TemporalCS : public CoordinateSystem {
PROJ_DLL ~TemporalCS() override;
//! @endcond

/** WKT2:2015 type */
static constexpr const char *WKT2_2015_TYPE = "temporal";

protected:
PROJ_INTERNAL explicit TemporalCS(const CoordinateSystemAxisNNPtr &axis);
INLINED_MAKE_SHARED
Expand Down Expand Up @@ -763,6 +788,9 @@ class PROJ_GCC_DLL DateTimeTemporalCS final : public TemporalCS {
create(const util::PropertyMap &properties,
const CoordinateSystemAxisNNPtr &axis);

/** WKT2:2019 type */
static constexpr const char *WKT2_2019_TYPE = "TemporalDateTime";

protected:
PROJ_INTERNAL explicit DateTimeTemporalCS(
const CoordinateSystemAxisNNPtr &axis);
Expand Down Expand Up @@ -799,6 +827,9 @@ class PROJ_GCC_DLL TemporalCountCS final : public TemporalCS {
create(const util::PropertyMap &properties,
const CoordinateSystemAxisNNPtr &axis);

/** WKT2:2019 type */
static constexpr const char *WKT2_2019_TYPE = "TemporalCount";

protected:
PROJ_INTERNAL explicit TemporalCountCS(
const CoordinateSystemAxisNNPtr &axis);
Expand Down Expand Up @@ -835,6 +866,9 @@ class PROJ_GCC_DLL TemporalMeasureCS final : public TemporalCS {
create(const util::PropertyMap &properties,
const CoordinateSystemAxisNNPtr &axis);

/** WKT2:2019 type */
static constexpr const char *WKT2_2019_TYPE = "TemporalMeasure";

protected:
PROJ_INTERNAL explicit TemporalMeasureCS(
const CoordinateSystemAxisNNPtr &axis);
Expand Down
6 changes: 3 additions & 3 deletions src/iso19111/coordinatesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ DateTimeTemporalCS::create(const util::PropertyMap &properties,
// ---------------------------------------------------------------------------

std::string DateTimeTemporalCS::getWKT2Type(bool use2019Keywords) const {
return use2019Keywords ? "TemporalDateTime" : "temporal";
return use2019Keywords ? WKT2_2019_TYPE : WKT2_2015_TYPE;
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -1560,7 +1560,7 @@ TemporalCountCS::create(const util::PropertyMap &properties,
// ---------------------------------------------------------------------------

std::string TemporalCountCS::getWKT2Type(bool use2019Keywords) const {
return use2019Keywords ? "TemporalCount" : "temporal";
return use2019Keywords ? WKT2_2019_TYPE : WKT2_2015_TYPE;
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -1593,7 +1593,7 @@ TemporalMeasureCS::create(const util::PropertyMap &properties,
// ---------------------------------------------------------------------------

std::string TemporalMeasureCS::getWKT2Type(bool use2019Keywords) const {
return use2019Keywords ? "TemporalMeasure" : "temporal";
return use2019Keywords ? WKT2_2019_TYPE : WKT2_2015_TYPE;
}

} // namespace cs
Expand Down
25 changes: 16 additions & 9 deletions src/iso19111/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ namespace io {
#define GEOG_3D_SINGLE_QUOTED "'geographic 3D'"
#define GEOCENTRIC_SINGLE_QUOTED "'geocentric'"

// Coordinate system types
constexpr const char *CS_TYPE_ELLIPSOIDAL = "ellipsoidal";
constexpr const char *CS_TYPE_CARTESIAN = "Cartesian"; // uppercase intended
constexpr const char *CS_TYPE_SPHERICAL = "spherical";
constexpr const char *CS_TYPE_VERTICAL = "vertical";
constexpr const char *CS_TYPE_ORDINAL = "ordinal";

// See data/sql/metadata.sql for the semantics of those constants
constexpr int DATABASE_LAYOUT_VERSION_MAJOR = 1;
// If the code depends on the new additions, then DATABASE_LAYOUT_VERSION_MINOR
Expand Down Expand Up @@ -1605,11 +1612,11 @@ identifyFromNameOrCode(const DatabaseContextNNPtr &dbContext,

static const char *getCSDatabaseType(const cs::CoordinateSystemNNPtr &obj) {
if (dynamic_cast<const cs::EllipsoidalCS *>(obj.get())) {
return "ellipsoidal";
return CS_TYPE_ELLIPSOIDAL;
} else if (dynamic_cast<const cs::CartesianCS *>(obj.get())) {
return "Cartesian";
return CS_TYPE_CARTESIAN;
} else if (dynamic_cast<const cs::VerticalCS *>(obj.get())) {
return "vertical";
return CS_TYPE_VERTICAL;
}
return nullptr;
}
Expand Down Expand Up @@ -4917,7 +4924,7 @@ AuthorityFactory::createCoordinateSystem(const std::string &code) const {
const auto &orientation = row[2];
const auto &uom_auth_name = row[3];
const auto &uom_code = row[4];
if (uom_auth_name.empty() && csType != "ordinal") {
if (uom_auth_name.empty() && csType != CS_TYPE_ORDINAL) {
throw FactoryException("no unit of measure for an axis is only "
"supported for ordinatal CS");
}
Expand Down Expand Up @@ -4966,7 +4973,7 @@ AuthorityFactory::createCoordinateSystem(const std::string &code) const {
auto props = util::PropertyMap()
.set(metadata::Identifier::CODESPACE_KEY, d->authority())
.set(metadata::Identifier::CODE_KEY, code);
if (csType == "ellipsoidal") {
if (csType == CS_TYPE_ELLIPSOIDAL) {
if (axisList.size() == 2) {
return cacheAndRet(
cs::EllipsoidalCS::create(props, axisList[0], axisList[1]));
Expand All @@ -4977,7 +4984,7 @@ AuthorityFactory::createCoordinateSystem(const std::string &code) const {
}
throw FactoryException("invalid number of axis for EllipsoidalCS");
}
if (csType == "Cartesian") {
if (csType == CS_TYPE_CARTESIAN) {
if (axisList.size() == 2) {
return cacheAndRet(
cs::CartesianCS::create(props, axisList[0], axisList[1]));
Expand All @@ -4988,7 +4995,7 @@ AuthorityFactory::createCoordinateSystem(const std::string &code) const {
}
throw FactoryException("invalid number of axis for CartesianCS");
}
if (csType == "spherical") {
if (csType == CS_TYPE_SPHERICAL) {
if (axisList.size() == 2) {
return cacheAndRet(
cs::SphericalCS::create(props, axisList[0], axisList[1]));
Expand All @@ -4999,13 +5006,13 @@ AuthorityFactory::createCoordinateSystem(const std::string &code) const {
}
throw FactoryException("invalid number of axis for SphericalCS");
}
if (csType == "vertical") {
if (csType == CS_TYPE_VERTICAL) {
if (axisList.size() == 1) {
return cacheAndRet(cs::VerticalCS::create(props, axisList[0]));
}
throw FactoryException("invalid number of axis for VerticalCS");
}
if (csType == "ordinal") {
if (csType == CS_TYPE_ORDINAL) {
return cacheAndRet(cs::OrdinalCS::create(props, axisList));
}
throw FactoryException("unhandled coordinate system type: " + csType);
Expand Down
Loading

0 comments on commit ab58764

Please sign in to comment.