benchmark: add tests for longlat/merc transformations
This commit is contained in:
parent
430e3d3406
commit
19526eb7f7
1 changed files with 93 additions and 0 deletions
|
@ -269,6 +269,64 @@ struct test5
|
|||
};
|
||||
|
||||
|
||||
#include <mapnik/box2d.hpp>
|
||||
#include <mapnik/projection.hpp>
|
||||
#include <mapnik/proj_transform.hpp>
|
||||
#include <mapnik/well_known_srs.hpp>
|
||||
|
||||
struct test6
|
||||
{
|
||||
unsigned iter_;
|
||||
unsigned threads_;
|
||||
std::string src_;
|
||||
std::string dest_;
|
||||
mapnik::box2d<double> from_;
|
||||
mapnik::box2d<double> to_;
|
||||
explicit test6(unsigned iterations,
|
||||
unsigned threads,
|
||||
std::string const& src,
|
||||
std::string const& dest,
|
||||
mapnik::box2d<double> from,
|
||||
mapnik::box2d<double> to) :
|
||||
iter_(iterations),
|
||||
threads_(threads),
|
||||
src_(src),
|
||||
dest_(dest),
|
||||
from_(from),
|
||||
to_(to) {}
|
||||
|
||||
bool validate()
|
||||
{
|
||||
mapnik::projection src(src_);
|
||||
mapnik::projection dest(dest_);
|
||||
mapnik::proj_transform tr(src,dest);
|
||||
mapnik::box2d<double> bbox = from_;
|
||||
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)
|
||||
);
|
||||
}
|
||||
void operator()()
|
||||
{
|
||||
mapnik::projection src(src_);
|
||||
mapnik::projection dest(dest_);
|
||||
mapnik::proj_transform tr(src,dest);
|
||||
unsigned count=0;
|
||||
for (int i=-180;i<180;i=++i)
|
||||
{
|
||||
for (int j=-85;j<85;++j)
|
||||
{
|
||||
mapnik::box2d<double> box(i,j,i,j);
|
||||
if (!tr.forward(box)) throw std::runtime_error("could not transform coords");
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main( int argc, char** argv)
|
||||
{
|
||||
if (argc > 0) {
|
||||
|
@ -338,6 +396,41 @@ int main( int argc, char** argv)
|
|||
benchmark(runner,"double to string conversion with snprintf");
|
||||
}
|
||||
|
||||
mapnik::box2d<double> from(-180,-80,180,80);
|
||||
mapnik::box2d<double> to(-20037508.3427892476,-15538711.0963092316,20037508.3427892476,15538711.0963092316);
|
||||
{
|
||||
// echo -180 -60 | cs2cs -f "%.10f" +init=epsg:4326 +to +init=epsg:3857
|
||||
test6 runner(100000000,100,
|
||||
"+init=epsg:4326",
|
||||
"+init=epsg:3857",
|
||||
from,to);
|
||||
benchmark(runner,"lonlat -> merc coord transformation (epsg)");
|
||||
}
|
||||
|
||||
{
|
||||
test6 runner(100000000,100,
|
||||
"+init=epsg:3857",
|
||||
"+init=epsg:4326",
|
||||
to,from);
|
||||
benchmark(runner,"merc -> lonlat coord transformation (epsg)");
|
||||
}
|
||||
|
||||
{
|
||||
test6 runner(100000000,100,
|
||||
"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs",
|
||||
"+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",
|
||||
from,to);
|
||||
benchmark(runner,"lonlat -> merc coord transformation (literal)");
|
||||
}
|
||||
|
||||
{
|
||||
test6 runner(100000000,100,
|
||||
"+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",
|
||||
"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs",
|
||||
to,from);
|
||||
benchmark(runner,"merc -> lonlat coord transformation (literal)");
|
||||
}
|
||||
|
||||
std::cout << "...benchmark done\n";
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue