From f98fd0da7c47d075da67da7a2f79980324e0693e Mon Sep 17 00:00:00 2001 From: Blake Thompson Date: Fri, 10 Apr 2015 14:05:58 -0500 Subject: [PATCH] Added tests for non standard projections, forcing use of proj4. --- include/mapnik/proj_transform.hpp | 4 +- src/proj_transform.cpp | 58 ++++++++------ tests/cxx/geometry_reprojection.cpp | 119 ++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+), 28 deletions(-) diff --git a/include/mapnik/proj_transform.hpp b/include/mapnik/proj_transform.hpp index 2f83c7120..2dd123479 100644 --- a/include/mapnik/proj_transform.hpp +++ b/include/mapnik/proj_transform.hpp @@ -46,8 +46,8 @@ public: bool is_known() const; bool forward (double& x, double& y , double& z) const; bool backward (double& x, double& y , double& z) const; - bool forward (double *x, double *y , double *z, int point_count) const; - bool backward (double *x, double *y , double *z, int point_count) const; + bool forward (double *x, double *y , double *z, int point_count, int offset = 1) const; + bool backward (double *x, double *y , double *z, int point_count, int offset = 1) const; bool forward (geometry::point & p) const; bool backward (geometry::point & p) const; unsigned int forward (geometry::line_string & ls) const; diff --git a/src/proj_transform.cpp b/src/proj_transform.cpp index 8b058a456..7931e9123 100644 --- a/src/proj_transform.cpp +++ b/src/proj_transform.cpp @@ -105,6 +105,9 @@ bool proj_transform::forward (geometry::point & p) const unsigned int proj_transform::forward (geometry::line_string & ls) const { + std::size_t size = ls.size(); + if (size == 0) return 0; + if (is_source_equal_dest_) return 0; @@ -119,18 +122,18 @@ unsigned int proj_transform::forward (geometry::line_string & ls) const return 0; } - unsigned int err_n = 0; - for (auto & p : ls) + geometry::point * ptr = ls.data(); + double * x = reinterpret_cast(ptr); + double * y = x + 1; + double * z = NULL; + if(!forward(x, y, z, size, 2)) { - if (!forward(p)) - { - err_n++; - } + return size; } - return err_n; + return 0; } -bool proj_transform::forward (double * x, double * y , double * z, int point_count) const +bool proj_transform::forward (double * x, double * y , double * z, int point_count, int offset) const { if (is_source_equal_dest_) @@ -150,13 +153,13 @@ bool proj_transform::forward (double * x, double * y , double * z, int point_cou { int i; for(i=0; i & p) const unsigned int proj_transform::backward (geometry::line_string & ls) const { + std::size_t size = ls.size(); + if (size == 0) return 0; + if (is_source_equal_dest_) return 0; @@ -242,15 +248,15 @@ unsigned int proj_transform::backward (geometry::line_string & ls) const return 0; } - unsigned int err_n = 0; - for (auto & p : ls) + geometry::point * ptr = ls.data(); + double * x = reinterpret_cast(ptr); + double * y = x + 1; + double * z = NULL; + if(!backward(x, y, z, size, 2)) { - if (!backward(p)) - { - err_n++; - } + return size; } - return err_n; + return 0; } bool proj_transform::forward (box2d & box) const diff --git a/tests/cxx/geometry_reprojection.cpp b/tests/cxx/geometry_reprojection.cpp index 988d44979..1c604d260 100644 --- a/tests/cxx/geometry_reprojection.cpp +++ b/tests/cxx/geometry_reprojection.cpp @@ -1152,4 +1152,123 @@ SECTION("test_projection_4326_3857 - Geometry Collection Variant Object") { } } // END SECTION +SECTION("test_projection_4269_3857 - Line_String Geometry Object") { + using namespace mapnik::geometry; + mapnik::projection source("+init=epsg:4269"); + mapnik::projection dest("+init=epsg:3857"); + mapnik::proj_transform proj_trans1(source, dest); + mapnik::proj_transform proj_trans2(dest, source); + line_string geom1; + geom1.emplace_back(point(-97.48872756958008, 35.360286150765084)); + geom1.emplace_back(point(-97.48065948486328, 35.34894577151337)); + geom1.emplace_back(point(-97.47267723083496, 35.36224605490395)); + geom1.emplace_back(point(-97.46323585510252, 35.34523530173256)); + geom1.emplace_back(point(-97.45963096618651, 35.36329598397908)); + geom1.emplace_back(point(-97.47550964355469, 35.369245324153866)); + line_string geom2; + geom2.emplace_back(point(-10852395.511130, 4212951.024108)); + geom2.emplace_back(point(-10851497.376047, 4211403.174286)); + geom2.emplace_back(point(-10850608.795594, 4213218.553707)); + geom2.emplace_back(point(-10849557.786455, 4210896.778973)); + geom2.emplace_back(point(-10849156.492056, 4213361.873135)); + geom2.emplace_back(point(-10850924.098335, 4214174.016561)); + unsigned int err = 0; + { + // Test Standard Transform + line_string new_geom = reproject_copy(geom1, proj_trans1, err); + REQUIRE(err == 0); + assert_g_equal(new_geom, geom2); + } + { + // Transform in reverse + line_string new_geom = reproject_copy(geom2, proj_trans2, err); + REQUIRE(err == 0); + assert_g_equal(new_geom, geom1); + } + { + // Transform providing projections not transfrom + line_string new_geom = reproject_copy(geom1, source, dest, err); + REQUIRE(err == 0); + assert_g_equal(new_geom, geom2); + } + { + // Transform providing projections in reverse + line_string new_geom = reproject_copy(geom2, dest, source, err); + REQUIRE(err == 0); + assert_g_equal(new_geom, geom1); + } + { + // Transform in place + line_string geom3(geom1); + REQUIRE(reproject(geom3, proj_trans1)); + assert_g_equal(geom3, geom2); + // Transform in place reverse + REQUIRE(reproject(geom3, proj_trans2)); + assert_g_equal(geom3, geom1); + } + { + // Transform in place providing projections + line_string geom3(geom1); + REQUIRE(reproject(geom3, source, dest)); + assert_g_equal(geom3, geom2); + // Transform in place provoding projections reversed + REQUIRE(reproject(geom3, dest, source)); + assert_g_equal(geom3, geom1); + } +} // End Section + +SECTION("test_projection_4269_3857 - Point Geometry Object") { + using namespace mapnik::geometry; + mapnik::projection source("+init=epsg:4269"); + mapnik::projection dest("+init=epsg:3857"); + mapnik::proj_transform proj_trans1(source, dest); + mapnik::proj_transform proj_trans2(dest, source); + point geom1(-97.552175, 35.522895); + point geom2(-10859458.446776, 4235169.496066); + unsigned int err = 0; + { + // Test Standard Transform + point new_geom = reproject_copy(geom1, proj_trans1, err); + REQUIRE(err == 0); + assert_g_equal(new_geom, geom2); + } + { + // Transform in reverse + point new_geom = reproject_copy(geom2, proj_trans2, err); + REQUIRE(err == 0); + assert_g_equal(new_geom, geom1); + } + { + // Transform providing projections not transfrom + point new_geom = reproject_copy(geom1, source, dest, err); + REQUIRE(err == 0); + assert_g_equal(new_geom, geom2); + } + { + // Transform providing projections in reverse + point new_geom = reproject_copy(geom2, dest, source, err); + REQUIRE(err == 0); + assert_g_equal(new_geom, geom1); + } + { + // Transform in place + point geom3(-97.552175, 35.522895); + REQUIRE(reproject(geom3, proj_trans1)); + assert_g_equal(geom3, geom2); + // Transform in place reverse - back + REQUIRE(reproject(geom3, proj_trans2)); + assert_g_equal(geom3, geom1); + } + { + // Transform in place providing projections + point geom3(-97.552175, 35.522895); + REQUIRE(reproject(geom3, source, dest)); + assert_g_equal(geom3, geom2); + // Transform in place provoding projections reversed + REQUIRE(reproject(geom3, dest, source)); + assert_g_equal(geom3, geom1); + } +} // End Section + + } // End Testcase