Fix missing proj context and cleanup/simplify proj_transform
This commit is contained in:
parent
6cc353f8a2
commit
db9829d702
2 changed files with 11 additions and 27 deletions
|
@ -38,8 +38,7 @@ template <typename T> class box2d;
|
||||||
class MAPNIK_DECL proj_transform : private util::noncopyable
|
class MAPNIK_DECL proj_transform : private util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
proj_transform(projection const& source,
|
proj_transform(projection const& source, projection const& dest);
|
||||||
projection const& dest);
|
|
||||||
~proj_transform();
|
~proj_transform();
|
||||||
bool equal() const;
|
bool equal() const;
|
||||||
bool is_known() const;
|
bool is_known() const;
|
||||||
|
@ -55,14 +54,9 @@ public:
|
||||||
bool backward (box2d<double> & box) const;
|
bool backward (box2d<double> & box) const;
|
||||||
bool forward (box2d<double> & box, int points) const;
|
bool forward (box2d<double> & box, int points) const;
|
||||||
bool backward (box2d<double> & box, int points) const;
|
bool backward (box2d<double> & box, int points) const;
|
||||||
mapnik::projection const& source() const;
|
|
||||||
mapnik::projection const& dest() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PJ_CONTEXT* ctx_ = nullptr;
|
PJ_CONTEXT* ctx_ = nullptr;
|
||||||
PJ* transform_ = nullptr;
|
PJ* transform_ = nullptr;
|
||||||
projection const& source_;
|
|
||||||
projection const& dest_;
|
|
||||||
bool is_source_longlat_;
|
bool is_source_longlat_;
|
||||||
bool is_dest_longlat_;
|
bool is_dest_longlat_;
|
||||||
bool is_source_equal_dest_;
|
bool is_source_equal_dest_;
|
||||||
|
|
|
@ -95,19 +95,17 @@ auto envelope_points(box2d<T> const& env, std::size_t num_points)
|
||||||
|
|
||||||
proj_transform::proj_transform(projection const& source,
|
proj_transform::proj_transform(projection const& source,
|
||||||
projection const& dest)
|
projection const& dest)
|
||||||
: source_(source),
|
: is_source_longlat_(false),
|
||||||
dest_(dest),
|
|
||||||
is_source_longlat_(false),
|
|
||||||
is_dest_longlat_(false),
|
is_dest_longlat_(false),
|
||||||
is_source_equal_dest_(false),
|
is_source_equal_dest_(false),
|
||||||
wgs84_to_merc_(false),
|
wgs84_to_merc_(false),
|
||||||
merc_to_wgs84_(false)
|
merc_to_wgs84_(false)
|
||||||
{
|
{
|
||||||
is_source_equal_dest_ = (source_ == dest_);
|
is_source_equal_dest_ = (source == dest);
|
||||||
if (!is_source_equal_dest_)
|
if (!is_source_equal_dest_)
|
||||||
{
|
{
|
||||||
is_source_longlat_ = source_.is_geographic();
|
is_source_longlat_ = source.is_geographic();
|
||||||
is_dest_longlat_ = dest_.is_geographic();
|
is_dest_longlat_ = dest.is_geographic();
|
||||||
boost::optional<well_known_srs_e> src_k = source.well_known();
|
boost::optional<well_known_srs_e> src_k = source.well_known();
|
||||||
boost::optional<well_known_srs_e> dest_k = dest.well_known();
|
boost::optional<well_known_srs_e> dest_k = dest.well_known();
|
||||||
bool known_trans = false;
|
bool known_trans = false;
|
||||||
|
@ -127,22 +125,23 @@ proj_transform::proj_transform(projection const& source,
|
||||||
if (!known_trans)
|
if (!known_trans)
|
||||||
{
|
{
|
||||||
#ifdef MAPNIK_USE_PROJ
|
#ifdef MAPNIK_USE_PROJ
|
||||||
|
ctx_ = proj_context_create();
|
||||||
transform_ = proj_create_crs_to_crs(ctx_,
|
transform_ = proj_create_crs_to_crs(ctx_,
|
||||||
source_.params().c_str(),
|
source.params().c_str(),
|
||||||
dest_.params().c_str(), nullptr);
|
dest.params().c_str(), nullptr);
|
||||||
if (transform_ == nullptr)
|
if (transform_ == nullptr)
|
||||||
{
|
{
|
||||||
throw std::runtime_error(std::string("Cannot initialize proj_transform for given projections without proj4 support (-DMAPNIK_USE_PROJ): '") + source_.params() + "'->'" + dest_.params() + "'");
|
throw std::runtime_error(std::string("Cannot initialize proj_transform for given projections without proj4 support (-DMAPNIK_USE_PROJ): '") + source.params() + "'->'" + dest.params() + "'");
|
||||||
}
|
}
|
||||||
PJ* transform_gis = proj_normalize_for_visualization(ctx_, transform_);
|
PJ* transform_gis = proj_normalize_for_visualization(ctx_, transform_);
|
||||||
if (transform_gis == nullptr)
|
if (transform_gis == nullptr)
|
||||||
{
|
{
|
||||||
throw std::runtime_error(std::string("Cannot initialize proj_transform for given projections without proj4 support (-DMAPNIK_USE_PROJ): '") + source_.params() + "'->'" + dest_.params() + "'");
|
throw std::runtime_error(std::string("Cannot initialize proj_transform for given projections without proj4 support (-DMAPNIK_USE_PROJ): '") + source.params() + "'->'" + dest.params() + "'");
|
||||||
}
|
}
|
||||||
proj_destroy(transform_);
|
proj_destroy(transform_);
|
||||||
transform_ = transform_gis;
|
transform_ = transform_gis;
|
||||||
#else
|
#else
|
||||||
throw std::runtime_error(std::string("Cannot initialize proj_transform for given projections without proj4 support (-DMAPNIK_USE_PROJ): '") + source_.params() + "'->'" + dest_.params() + "'");
|
throw std::runtime_error(std::string("Cannot initialize proj_transform for given projections without proj4 support (-DMAPNIK_USE_PROJ): '") + source.params() + "'->'" + dest.params() + "'");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -452,13 +451,4 @@ bool proj_transform::forward(box2d<double>& env, int points) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapnik::projection const& proj_transform::source() const
|
|
||||||
{
|
|
||||||
return source_;
|
|
||||||
}
|
|
||||||
mapnik::projection const& proj_transform::dest() const
|
|
||||||
{
|
|
||||||
return dest_;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue