Skip to content
Draft
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
28 changes: 22 additions & 6 deletions geo/Geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,39 @@ util::geo::CRSType util::geo::getCRSType(const char* c, const char** endr) {
return CRS84; // Default.
}

if (strncicmp("<http://www.opengis.net/def/crs/OGC/1.3/CRS84>", c, 46) == 0) {
if (endr) (*endr) = c + 46;
if (strncicmp(crs84Iri, c, crs84IriLen) == 0) {
if (endr) (*endr) = c + crs84IriLen;
return CRS84;
}
if (strncicmp("<http://www.opengis.net/def/crs/EPSG/0/4326>", c, 44) == 0) {
if (endr) (*endr) = c + 44;
if (strncicmp(wgs84Iri, c, wgs84IriLen) == 0) {
if (endr) (*endr) = c + wgs84IriLen;
return WGS84;
}
if (strncicmp("<http://www.opengis.net/def/crs/EPSG/0/3857>", c, 44) == 0) {
if (endr) (*endr) = c + 44;
if (strncicmp(webMercIri, c, webMercIriLen) == 0) {
if (endr) (*endr) = c + webMercIriLen;
return WEB_MERCATOR;
Comment thread
yarox-1 marked this conversation as resolved.
}

if (endr) (*endr) = c;
return UNSUPPORTED;
}

// _____________________________________________________________________________
std::string util::geo::getCrsIri(util::geo::CRSType targetCRS) {
switch (targetCRS)
{
case CRS84:
// Not attaching IRI as CRS84 is the default.
return "";
case WGS84:
return std::string{wgs84Iri} + " ";
case WEB_MERCATOR:
return std::string{webMercIri} + " ";
default:
throw std::runtime_error("Trying to get CRS IRI for unsupported CRS type.");
}
}

// _____________________________________________________________________________
double util::geo::distToSegment(double lax, double lay, double lbx, double lby,
double px, double py) {
Expand Down
42 changes: 28 additions & 14 deletions geo/Geo.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ enum CRSType : uint8_t {
WEB_MERCATOR = 3,
};

constexpr const char crs84Iri[] = "<http://www.opengis.net/def/crs/OGC/1.3/CRS84>";
constexpr size_t crs84IriLen = sizeof(crs84Iri) - 1;
constexpr const char wgs84Iri[] = "<http://www.opengis.net/def/crs/EPSG/0/4326>";
constexpr size_t wgs84IriLen = sizeof(wgs84Iri) - 1;
constexpr const char webMercIri[] = "<http://www.opengis.net/def/crs/EPSG/0/3857>";
constexpr size_t webMercIriLen = sizeof(webMercIri) - 1;

uint8_t boolArrToInt8(const std::array<bool, 8> arr);

template <typename T>
Expand Down Expand Up @@ -298,29 +305,36 @@ RotatedBox<T> shrink(const RotatedBox<T>& b, double d);

bool doubleEq(double a, double b);

// This is used by 'getWKT' to attach the CRS IRI for a specified CRS.
std::string getCrsIri(CRSType targetCRS);

// The 'getWKT' functions now attach a given CRS IRI (specified by 'targetCRS').
// By default or for 'targetCRS == CRS84' no IRI will be attached.
// The point will also be projected from 'currentCRS' to the 'targetCRS'.
// As the collection uses the 'getWKT' function of the subgeometries, the IRIs for these geometries are hidden (via 'hideIri').
template <typename T>
std::string getWKT(const Point<T>& p, uint16_t prec);
std::string getWKT(const Point<T>& p, uint16_t prec, CRSType currentCRS = CRS84, CRSType targetCRS = CRS84, bool hideIri = false);

template <typename T>
std::string getWKT(const Point<T>& p);
std::string getWKT(const Point<T>& p, CRSType currentCRS = CRS84, CRSType targetCRS = CRS84, bool hideIri = false);

template <typename T>
std::string getWKT(const std::vector<Point<T>>& p, uint16_t prec);
std::string getWKT(const std::vector<Point<T>>& p, uint16_t prec, CRSType currentCRS = CRS84, CRSType targetCRS = CRS84, bool hideIri = false);

template <typename T>
std::string getWKT(const std::vector<Point<T>>& p);
std::string getWKT(const std::vector<Point<T>>& p, CRSType currentCRS = CRS84, CRSType targetCRS = CRS84, bool hideIri = false);

template <typename T>
std::string getWKT(const Line<T>& l, uint16_t prec);
std::string getWKT(const Line<T>& l, uint16_t prec, CRSType currentCRS = CRS84, CRSType targetCRS = CRS84, bool hideIri = false);

template <typename T>
std::string getWKT(const Line<T>& l);
std::string getWKT(const Line<T>& l, CRSType currentCRS = CRS84, CRSType targetCRS = CRS84, bool hideIri = false);

template <typename T>
std::string getWKT(const std::vector<Line<T>>& ls, uint16_t prec);
std::string getWKT(const std::vector<Line<T>>& ls, uint16_t prec, CRSType currentCRS = CRS84, CRSType targetCRS = CRS84, bool hideIri = false);

template <typename T>
std::string getWKT(const std::vector<Line<T>>& ls);
std::string getWKT(const std::vector<Line<T>>& ls, CRSType currentCRS = CRS84, CRSType targetCRS = CRS84, bool hideIri = false);

template <typename T>
std::string getWKT(const XSortedPolygon<T>& ls, uint16_t prec);
Expand All @@ -341,22 +355,22 @@ template <typename T>
std::string getWKT(const Box<T>& l);

template <typename T>
std::string getWKT(const Polygon<T>& p, uint16_t prec);
std::string getWKT(const Polygon<T>& p, uint16_t prec, CRSType currentCRS = CRS84, CRSType targetCRS = CRS84, bool hideIri = false);

template <typename T>
std::string getWKT(const Polygon<T>& p);
std::string getWKT(const Polygon<T>& p, CRSType currentCRS = CRS84, CRSType targetCRS = CRS84, bool hideIri = false);

template <typename T>
std::string getWKT(const std::vector<Polygon<T>>& ls, uint16_t prec);
std::string getWKT(const std::vector<Polygon<T>>& ls, uint16_t prec, CRSType currentCRS = CRS84, CRSType targetCRS = CRS84, bool hideIri = false);

template <typename T>
std::string getWKT(const std::vector<Polygon<T>>& ls);
std::string getWKT(const std::vector<Polygon<T>>& ls, CRSType currentCRS = CRS84, CRSType targetCRS = CRS84, bool hideIri = false);

template <typename T>
std::string getWKT(const Collection<T>& coll, uint16_t prec);
std::string getWKT(const Collection<T>& coll, uint16_t prec, CRSType currentCRS = CRS84, CRSType targetCRS = CRS84, bool hideIri = false);

template <typename T>
std::string getWKT(const Collection<T>& coll);
std::string getWKT(const Collection<T>& coll, CRSType currentCRS = CRS84, CRSType targetCRS = CRS84, bool hideIri = false);

template <typename T>
bool contains(const Point<T>& p, const Box<T>& box);
Expand Down
Loading