mapnik::projection - add area_of_use method returning std::optional<mapnik::box2d<double>> (WGS84) [WIP] [skip ci]

This commit is contained in:
Artem Pavlenko 2024-07-29 11:21:54 +01:00
parent 727e3a1ca7
commit 7358a66c2f
2 changed files with 16 additions and 5 deletions

View file

@ -26,7 +26,7 @@
// mapnik // mapnik
#include <mapnik/config.hpp> #include <mapnik/config.hpp>
#include <mapnik/well_known_srs.hpp> #include <mapnik/well_known_srs.hpp>
#include <mapnik/geometry/box2d.hpp>
#include <mapnik/warning.hpp> #include <mapnik/warning.hpp>
MAPNIK_DISABLE_WARNING_PUSH MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/warning_ignore.hpp> #include <mapnik/warning_ignore.hpp>
@ -79,15 +79,16 @@ class MAPNIK_DECL projection
void inverse(double& x, double& y) const; void inverse(double& x, double& y) const;
std::string definition() const; std::string definition() const;
std::string description() const; std::string description() const;
void init_proj() const; void init_proj();
std::optional<box2d<double>> area_of_use() const;
private: private:
void swap(projection& rhs); void swap(projection& rhs);
private: private:
std::string params_; std::string params_;
bool defer_proj_init_; bool defer_proj_init_;
mutable bool is_geographic_; bool is_geographic_;
std::optional<box2d<double>> area_of_use_;
mutable PJ* proj_; mutable PJ* proj_;
mutable PJ_CONTEXT* proj_ctx_; mutable PJ_CONTEXT* proj_ctx_;
}; };

View file

@ -94,7 +94,7 @@ bool projection::operator!=(const projection& other) const
return !(*this == other); return !(*this == other);
} }
void projection::init_proj() const void projection::init_proj()
{ {
#ifdef MAPNIK_USE_PROJ #ifdef MAPNIK_USE_PROJ
if (!proj_) if (!proj_)
@ -117,6 +117,11 @@ void projection::init_proj() const
} }
PJ_TYPE type = proj_get_type(proj_); PJ_TYPE type = proj_get_type(proj_);
is_geographic_ = (type == PJ_TYPE_GEOGRAPHIC_2D_CRS || type == PJ_TYPE_GEOGRAPHIC_3D_CRS) ? true : false; 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<double>{west_lon, south_lat, east_lon, north_lat};
}
} }
#endif #endif
} }
@ -131,6 +136,11 @@ bool projection::is_geographic() const
return is_geographic_; return is_geographic_;
} }
std::optional<box2d<double>> projection::area_of_use() const
{
return area_of_use_;
}
std::optional<well_known_srs_e> projection::well_known() const std::optional<well_known_srs_e> projection::well_known() const
{ {
return is_well_known_srs(params_); return is_well_known_srs(params_);