make proj4 able to be fully disabled at compile time - refs #1703
This commit is contained in:
parent
e7f648eceb
commit
3969ac246d
3 changed files with 58 additions and 31 deletions
|
@ -28,9 +28,6 @@
|
|||
#include <mapnik/well_known_srs.hpp>
|
||||
|
||||
// boost
|
||||
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#endif
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
// stl
|
||||
|
@ -63,10 +60,8 @@ public:
|
|||
bool is_geographic() const;
|
||||
boost::optional<well_known_srs_e> well_known() const;
|
||||
std::string const& params() const;
|
||||
|
||||
void forward(double & x, double & y) const;
|
||||
void inverse(double & x,double & y) const;
|
||||
|
||||
std::string expanded() const;
|
||||
void init_proj4() const;
|
||||
|
||||
|
@ -79,9 +74,6 @@ private:
|
|||
mutable bool is_geographic_;
|
||||
mutable void * proj_;
|
||||
mutable void * proj_ctx_;
|
||||
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
|
||||
static boost::mutex mutex_;
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -26,8 +26,12 @@
|
|||
#include <mapnik/coord.hpp>
|
||||
#include <mapnik/utils.hpp>
|
||||
|
||||
#define MAPNIK_USE_PROJ4
|
||||
|
||||
#ifdef MAPNIK_USE_PROJ4
|
||||
// proj4
|
||||
#include <proj_api.h>
|
||||
#endif
|
||||
|
||||
// stl
|
||||
#include <vector>
|
||||
|
@ -68,7 +72,6 @@ bool proj_transform::equal() const
|
|||
return is_source_equal_dest_;
|
||||
}
|
||||
|
||||
|
||||
bool proj_transform::forward (double & x, double & y , double & z) const
|
||||
{
|
||||
return forward(&x, &y, &z, 1);
|
||||
|
@ -89,6 +92,7 @@ bool proj_transform::forward (double * x, double * y , double * z, int point_cou
|
|||
return merc2lonlat(x,y,point_count);
|
||||
}
|
||||
|
||||
#ifdef MAPNIK_USE_PROJ4
|
||||
if (is_source_longlat_)
|
||||
{
|
||||
int i;
|
||||
|
@ -98,7 +102,7 @@ bool proj_transform::forward (double * x, double * y , double * z, int point_cou
|
|||
}
|
||||
}
|
||||
|
||||
do {
|
||||
{
|
||||
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
|
||||
mutex::scoped_lock lock(projection::mutex_);
|
||||
#endif
|
||||
|
@ -107,7 +111,7 @@ bool proj_transform::forward (double * x, double * y , double * z, int point_cou
|
|||
{
|
||||
return false;
|
||||
}
|
||||
} while(false);
|
||||
}
|
||||
|
||||
if (is_dest_longlat_)
|
||||
{
|
||||
|
@ -117,7 +121,7 @@ bool proj_transform::forward (double * x, double * y , double * z, int point_cou
|
|||
y[i] *= RAD_TO_DEG;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -135,6 +139,7 @@ bool proj_transform::backward (double * x, double * y , double * z, int point_co
|
|||
return lonlat2merc(x,y,point_count);
|
||||
}
|
||||
|
||||
#ifdef MAPNIK_USE_PROJ4
|
||||
if (is_dest_longlat_)
|
||||
{
|
||||
int i;
|
||||
|
@ -164,7 +169,7 @@ bool proj_transform::backward (double * x, double * y , double * z, int point_co
|
|||
y[i] *= RAD_TO_DEG;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,15 +26,21 @@
|
|||
#include <mapnik/util/trim.hpp>
|
||||
#include <mapnik/well_known_srs.hpp>
|
||||
|
||||
#define MAPNIK_USE_PROJ4
|
||||
|
||||
#ifdef MAPNIK_USE_PROJ4
|
||||
// proj4
|
||||
#include <proj_api.h>
|
||||
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#warning mapnik is building against < proj 4.8, reprojection will be faster if you use >= 4.8
|
||||
static boost::mutex mutex_;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
|
||||
#warning mapnik is building against < proj 4.8, reprojection will be faster if you use >= 4.8
|
||||
boost::mutex projection::mutex_;
|
||||
#endif
|
||||
|
||||
projection::projection(std::string const& params, bool defer_proj_init)
|
||||
: params_(params),
|
||||
|
@ -48,7 +54,11 @@ projection::projection(std::string const& params, bool defer_proj_init)
|
|||
}
|
||||
else
|
||||
{
|
||||
#ifdef MAPNIK_USE_PROJ4
|
||||
init_proj4();
|
||||
#else
|
||||
throw std::runtime_error(std::string("Cannot initialize projection '") + params_ + " ' without proj4 support (-DMAPNIK_USE_PROJ4)");
|
||||
#endif
|
||||
}
|
||||
if (!defer_proj_init_) init_proj4();
|
||||
}
|
||||
|
@ -82,6 +92,7 @@ bool projection::operator!=(const projection& other) const
|
|||
|
||||
void projection::init_proj4() const
|
||||
{
|
||||
#ifdef MAPNIK_USE_PROJ4
|
||||
if (!proj_)
|
||||
{
|
||||
#if PJ_VERSION >= 480
|
||||
|
@ -101,9 +112,9 @@ void projection::init_proj4() const
|
|||
#endif
|
||||
is_geographic_ = pj_is_latlong(proj_) ? true : false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool projection::is_initialized() const
|
||||
{
|
||||
return proj_ ? true : false;
|
||||
|
@ -126,10 +137,14 @@ std::string const& projection::params() const
|
|||
|
||||
void projection::forward(double & x, double &y ) const
|
||||
{
|
||||
if (!proj_) return;
|
||||
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
|
||||
#ifdef MAPNIK_USE_PROJ4
|
||||
if (!proj_)
|
||||
{
|
||||
throw std::runtime_error("projection::forward not supported unless proj4 is initialized");
|
||||
}
|
||||
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
|
||||
mutex::scoped_lock lock(mutex_);
|
||||
#endif
|
||||
#endif
|
||||
projUV p;
|
||||
p.u = x * DEG_TO_RAD;
|
||||
p.v = y * DEG_TO_RAD;
|
||||
|
@ -141,14 +156,22 @@ void projection::forward(double & x, double &y ) const
|
|||
x *=RAD_TO_DEG;
|
||||
y *=RAD_TO_DEG;
|
||||
}
|
||||
#else
|
||||
throw std::runtime_error("projection::forward not supported without proj4 support (-DMAPNIK_USE_PROJ4)");
|
||||
#endif
|
||||
}
|
||||
|
||||
void projection::inverse(double & x,double & y) const
|
||||
{
|
||||
if (!proj_) return;
|
||||
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
|
||||
#ifdef MAPNIK_USE_PROJ4
|
||||
if (!proj_)
|
||||
{
|
||||
throw std::runtime_error("projection::inverse not supported unless proj4 is initialized");
|
||||
}
|
||||
|
||||
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
|
||||
mutex::scoped_lock lock(mutex_);
|
||||
#endif
|
||||
#endif
|
||||
if (is_geographic_)
|
||||
{
|
||||
x *=DEG_TO_RAD;
|
||||
|
@ -160,23 +183,30 @@ void projection::inverse(double & x,double & y) const
|
|||
p = pj_inv(p,proj_);
|
||||
x = RAD_TO_DEG * p.u;
|
||||
y = RAD_TO_DEG * p.v;
|
||||
#else
|
||||
throw std::runtime_error("projection::inverse not supported without proj4 support (-DMAPNIK_USE_PROJ4)");
|
||||
#endif
|
||||
}
|
||||
|
||||
projection::~projection()
|
||||
{
|
||||
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
|
||||
mutex::scoped_lock lock(mutex_);
|
||||
#endif
|
||||
if (proj_) pj_free(proj_);
|
||||
#if PJ_VERSION >= 480
|
||||
if (proj_ctx_) pj_ctx_free(proj_ctx_);
|
||||
#ifdef MAPNIK_USE_PROJ4
|
||||
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
|
||||
mutex::scoped_lock lock(mutex_);
|
||||
#endif
|
||||
if (proj_) pj_free(proj_);
|
||||
#if PJ_VERSION >= 480
|
||||
if (proj_ctx_) pj_ctx_free(proj_ctx_);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string projection::expanded() const
|
||||
{
|
||||
#ifdef MAPNIK_USE_PROJ4
|
||||
if (proj_) return mapnik::util::trim_copy(pj_get_def( proj_, 0 ));
|
||||
return "";
|
||||
#endif
|
||||
return params_;
|
||||
}
|
||||
|
||||
void projection::swap(projection& rhs)
|
||||
|
|
Loading…
Add table
Reference in a new issue