add Projection.expanded() function to ask proj4 what its internal, normalized definition looks like (useful only for debugging)

This commit is contained in:
Dane Springmeyer 2011-05-17 19:05:15 +00:00
parent e119dc503c
commit ba15947a4f
4 changed files with 24 additions and 0 deletions

View File

@ -104,6 +104,8 @@ void export_projection ()
.def ("params", make_function(&projection::params,
return_value_policy<copy_const_reference>()),
"Returns the PROJ.4 string for this projection.\n")
.def ("expanded",&projection::expanded,
"normalize PROJ.4 definition by expanding +init= syntax\n")
.add_property ("geographic", &projection::is_geographic,
"This property is True if the projection is a geographic projection\n"
"(i.e. it uses lon/lat coordinates)\n")

View File

@ -68,6 +68,8 @@ public:
void forward(double & x, double &y ) const;
void inverse(double & x,double & y) const;
std::string expanded() const;
private:
void init();

View File

@ -25,6 +25,10 @@
// mapnik
#include <mapnik/projection.hpp>
#include <mapnik/utils.hpp>
// boost
#include <boost/algorithm/string.hpp>
// proj4
#include <proj_api.h>
@ -139,6 +143,16 @@ void projection::init()
if (!proj_) throw proj_init_error(params_);
is_geographic_ = pj_is_latlong(proj_) ? true : false;
}
std::string projection::expanded() const
{
if (proj_) {
std::string def(pj_get_def( proj_, 0 ));
//boost::algorithm::ireplace_first(def,params_,"");
return boost::trim_copy(def);
}
return std::string("");
}
void projection::swap (projection& rhs)
{

View File

@ -6,6 +6,12 @@ import mapnik2, pickle
# Tests that exercise map projections.
def test_normalizing_definition():
p = mapnik2.Projection('+init=epsg:4326')
expanded = p.expanded()
eq_('+proj=longlat' in expanded,True)
# Trac Ticket #128
def test_wgs84_inverse_forward():
p = mapnik2.Projection('+init=epsg:4326')