diff --git a/include/mapnik/projection.hpp b/include/mapnik/projection.hpp index dd3183889..032b1370b 100644 --- a/include/mapnik/projection.hpp +++ b/include/mapnik/projection.hpp @@ -26,7 +26,7 @@ // mapnik #include #include - +#include #include MAPNIK_DISABLE_WARNING_PUSH #include @@ -79,15 +79,16 @@ class MAPNIK_DECL projection void inverse(double& x, double& y) const; std::string definition() const; std::string description() const; - void init_proj() const; - + void init_proj(); + std::optional> area_of_use() const; private: void swap(projection& rhs); private: std::string params_; bool defer_proj_init_; - mutable bool is_geographic_; + bool is_geographic_; + std::optional> area_of_use_; mutable PJ* proj_; mutable PJ_CONTEXT* proj_ctx_; }; diff --git a/src/projection.cpp b/src/projection.cpp index 29cffb4d8..6b434a175 100644 --- a/src/projection.cpp +++ b/src/projection.cpp @@ -94,7 +94,7 @@ bool projection::operator!=(const projection& other) const return !(*this == other); } -void projection::init_proj() const +void projection::init_proj() { #ifdef MAPNIK_USE_PROJ if (!proj_) @@ -117,6 +117,11 @@ void projection::init_proj() const } PJ_TYPE type = proj_get_type(proj_); is_geographic_ = (type == PJ_TYPE_GEOGRAPHIC_2D_CRS || type == PJ_TYPE_GEOGRAPHIC_3D_CRS) ? true : false; + double west_lon, south_lat, east_lon, north_lat; + if (proj_get_area_of_use(proj_ctx_, proj_, &west_lon, &south_lat, &east_lon, &north_lat, nullptr)) + { + area_of_use_ = box2d{west_lon, south_lat, east_lon, north_lat}; + } } #endif } @@ -131,6 +136,11 @@ bool projection::is_geographic() const return is_geographic_; } +std::optional> projection::area_of_use() const +{ + return area_of_use_; +} + std::optional projection::well_known() const { return is_well_known_srs(params_);