2013-11-15 07:11:21 +00:00
|
|
|
#include "bench_framework.hpp"
|
2017-01-26 08:51:37 +00:00
|
|
|
#include <mapnik/geometry/box2d.hpp>
|
2013-11-15 07:11:21 +00:00
|
|
|
#include <mapnik/projection.hpp>
|
|
|
|
#include <mapnik/proj_transform.hpp>
|
|
|
|
|
|
|
|
class test : public benchmark::test_case
|
|
|
|
{
|
|
|
|
std::string src_;
|
|
|
|
std::string dest_;
|
|
|
|
mapnik::box2d<double> from_;
|
|
|
|
mapnik::box2d<double> to_;
|
2021-03-18 15:32:13 +00:00
|
|
|
bool defer_proj_init_;
|
2022-01-26 22:32:21 +00:00
|
|
|
|
|
|
|
public:
|
2013-11-15 07:11:21 +00:00
|
|
|
test(mapnik::parameters const& params,
|
|
|
|
std::string const& src,
|
|
|
|
std::string const& dest,
|
|
|
|
mapnik::box2d<double> const& from,
|
|
|
|
mapnik::box2d<double> const& to,
|
|
|
|
bool defer_proj)
|
2022-01-26 22:32:21 +00:00
|
|
|
: test_case(params)
|
|
|
|
, src_(src)
|
|
|
|
, dest_(dest)
|
|
|
|
, from_(from)
|
|
|
|
, to_(to)
|
|
|
|
, defer_proj_init_(defer_proj)
|
|
|
|
{}
|
2013-11-15 07:11:21 +00:00
|
|
|
bool validate() const
|
|
|
|
{
|
2022-01-26 22:32:21 +00:00
|
|
|
mapnik::projection src(src_, defer_proj_init_);
|
|
|
|
mapnik::projection dest(dest_, defer_proj_init_);
|
|
|
|
mapnik::proj_transform tr(src, dest);
|
2013-11-15 07:11:21 +00:00
|
|
|
mapnik::box2d<double> bbox = from_;
|
2022-01-26 22:32:21 +00:00
|
|
|
if (!tr.forward(bbox))
|
|
|
|
return false;
|
|
|
|
return ((std::fabs(bbox.minx() - to_.minx()) < .5) && (std::fabs(bbox.maxx() - to_.maxx()) < .5) &&
|
|
|
|
(std::fabs(bbox.miny() - to_.miny()) < .5) && (std::fabs(bbox.maxy() - to_.maxy()) < .5));
|
2013-11-15 07:11:21 +00:00
|
|
|
}
|
2014-12-12 16:59:45 +00:00
|
|
|
bool operator()() const
|
2013-11-15 07:11:21 +00:00
|
|
|
{
|
2022-01-26 22:32:21 +00:00
|
|
|
mapnik::projection src(src_, defer_proj_init_);
|
|
|
|
mapnik::projection dest(dest_, defer_proj_init_);
|
|
|
|
mapnik::proj_transform tr(src, dest);
|
|
|
|
for (std::size_t i = 0; i < iterations_; ++i)
|
2015-06-15 23:41:40 +00:00
|
|
|
{
|
2022-01-26 22:32:21 +00:00
|
|
|
for (int j = -180; j < 180; j = j + 5)
|
2013-11-15 07:11:21 +00:00
|
|
|
{
|
2022-01-26 22:32:21 +00:00
|
|
|
for (int k = -85; k < 85; k = k + 5)
|
2013-11-15 07:11:21 +00:00
|
|
|
{
|
2022-01-26 22:32:21 +00:00
|
|
|
mapnik::box2d<double> box(j, k, j, k);
|
|
|
|
if (!tr.forward(box))
|
|
|
|
throw std::runtime_error("could not transform coords");
|
2013-11-15 07:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-12 16:59:45 +00:00
|
|
|
return true;
|
2013-11-15 07:11:21 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-15 15:21:09 +00:00
|
|
|
// echo -180 -60 | cs2cs -f "%.10f" epsg:4326 +to epsg:3857
|
2013-11-15 07:11:21 +00:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2022-01-26 22:32:21 +00:00
|
|
|
mapnik::box2d<double> from(-180, -80, 180, 80);
|
|
|
|
mapnik::box2d<double> to(-20037508.3427892476, -15538711.0963092316, 20037508.3427892476, 15538711.0963092316);
|
2021-01-15 15:21:09 +00:00
|
|
|
std::string from_str("epsg:4326");
|
|
|
|
std::string to_str("epsg:3857");
|
2013-11-15 07:11:21 +00:00
|
|
|
std::string from_str2("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
|
2022-01-26 22:32:21 +00:00
|
|
|
std::string to_str2("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m "
|
|
|
|
"+nadgrids=@null +wktext +no_defs +over");
|
2016-02-16 18:53:03 +00:00
|
|
|
return benchmark::sequencer(argc, argv)
|
2022-01-26 22:32:21 +00:00
|
|
|
.run<test>("lonlat->merc epsg (internal)", from_str, to_str, from, to, true)
|
|
|
|
.run<test>("lonlat->merc literal (libproj)", from_str2, to_str2, from, to, true)
|
|
|
|
.run<test>("merc->lonlat epsg (internal)", to_str, from_str, to, from, true)
|
|
|
|
.run<test>("merc->lonlat literal (libproj)", to_str2, from_str2, to, from, true)
|
|
|
|
.done();
|
2013-11-15 07:11:21 +00:00
|
|
|
}
|