Added tests for non standard projections, forcing use of proj4.

This commit is contained in:
Blake Thompson 2015-04-10 14:05:58 -05:00
parent 2392c7eb12
commit f98fd0da7c
3 changed files with 153 additions and 28 deletions

View file

@ -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<double> & p) const;
bool backward (geometry::point<double> & p) const;
unsigned int forward (geometry::line_string<double> & ls) const;

View file

@ -105,6 +105,9 @@ bool proj_transform::forward (geometry::point<double> & p) const
unsigned int proj_transform::forward (geometry::line_string<double> & 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<double> & ls) const
return 0;
}
unsigned int err_n = 0;
for (auto & p : ls)
geometry::point<double> * ptr = ls.data();
double * x = reinterpret_cast<double*>(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<point_count; i++) {
x[i] *= DEG_TO_RAD;
y[i] *= DEG_TO_RAD;
x[i*offset] *= DEG_TO_RAD;
y[i*offset] *= DEG_TO_RAD;
}
}
if (pj_transform( source_.proj_, dest_.proj_, point_count,
0, x,y,z) != 0)
offset, x,y,z) != 0)
{
return false;
}
@ -165,15 +168,15 @@ bool proj_transform::forward (double * x, double * y , double * z, int point_cou
{
int i;
for(i=0; i<point_count; i++) {
x[i] *= RAD_TO_DEG;
y[i] *= RAD_TO_DEG;
x[i*offset] *= RAD_TO_DEG;
y[i*offset] *= RAD_TO_DEG;
}
}
#endif
return true;
}
bool proj_transform::backward (double * x, double * y , double * z, int point_count) const
bool proj_transform::backward (double * x, double * y , double * z, int point_count, int offset) const
{
if (is_source_equal_dest_)
return true;
@ -192,13 +195,13 @@ bool proj_transform::backward (double * x, double * y , double * z, int point_co
{
int i;
for(i=0; i<point_count; i++) {
x[i] *= DEG_TO_RAD;
y[i] *= DEG_TO_RAD;
x[i*offset] *= DEG_TO_RAD;
y[i*offset] *= DEG_TO_RAD;
}
}
if (pj_transform( dest_.proj_, source_.proj_, point_count,
0, x,y,z) != 0)
offset, x,y,z) != 0)
{
return false;
}
@ -207,8 +210,8 @@ bool proj_transform::backward (double * x, double * y , double * z, int point_co
{
int i;
for(i=0; i<point_count; i++) {
x[i] *= RAD_TO_DEG;
y[i] *= RAD_TO_DEG;
x[i*offset] *= RAD_TO_DEG;
y[i*offset] *= RAD_TO_DEG;
}
}
#endif
@ -228,6 +231,9 @@ bool proj_transform::backward (geometry::point<double> & p) const
unsigned int proj_transform::backward (geometry::line_string<double> & 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<double> & ls) const
return 0;
}
unsigned int err_n = 0;
for (auto & p : ls)
geometry::point<double> * ptr = ls.data();
double * x = reinterpret_cast<double*>(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<double> & box) const

View file

@ -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<double> geom1;
geom1.emplace_back(point<double>(-97.48872756958008, 35.360286150765084));
geom1.emplace_back(point<double>(-97.48065948486328, 35.34894577151337));
geom1.emplace_back(point<double>(-97.47267723083496, 35.36224605490395));
geom1.emplace_back(point<double>(-97.46323585510252, 35.34523530173256));
geom1.emplace_back(point<double>(-97.45963096618651, 35.36329598397908));
geom1.emplace_back(point<double>(-97.47550964355469, 35.369245324153866));
line_string<double> geom2;
geom2.emplace_back(point<double>(-10852395.511130, 4212951.024108));
geom2.emplace_back(point<double>(-10851497.376047, 4211403.174286));
geom2.emplace_back(point<double>(-10850608.795594, 4213218.553707));
geom2.emplace_back(point<double>(-10849557.786455, 4210896.778973));
geom2.emplace_back(point<double>(-10849156.492056, 4213361.873135));
geom2.emplace_back(point<double>(-10850924.098335, 4214174.016561));
unsigned int err = 0;
{
// Test Standard Transform
line_string<double> new_geom = reproject_copy(geom1, proj_trans1, err);
REQUIRE(err == 0);
assert_g_equal(new_geom, geom2);
}
{
// Transform in reverse
line_string<double> new_geom = reproject_copy(geom2, proj_trans2, err);
REQUIRE(err == 0);
assert_g_equal(new_geom, geom1);
}
{
// Transform providing projections not transfrom
line_string<double> new_geom = reproject_copy(geom1, source, dest, err);
REQUIRE(err == 0);
assert_g_equal(new_geom, geom2);
}
{
// Transform providing projections in reverse
line_string<double> new_geom = reproject_copy(geom2, dest, source, err);
REQUIRE(err == 0);
assert_g_equal(new_geom, geom1);
}
{
// Transform in place
line_string<double> 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<double> 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<double> geom1(-97.552175, 35.522895);
point<double> geom2(-10859458.446776, 4235169.496066);
unsigned int err = 0;
{
// Test Standard Transform
point<double> new_geom = reproject_copy(geom1, proj_trans1, err);
REQUIRE(err == 0);
assert_g_equal(new_geom, geom2);
}
{
// Transform in reverse
point<double> new_geom = reproject_copy(geom2, proj_trans2, err);
REQUIRE(err == 0);
assert_g_equal(new_geom, geom1);
}
{
// Transform providing projections not transfrom
point<double> new_geom = reproject_copy(geom1, source, dest, err);
REQUIRE(err == 0);
assert_g_equal(new_geom, geom2);
}
{
// Transform providing projections in reverse
point<double> new_geom = reproject_copy(geom2, dest, source, err);
REQUIRE(err == 0);
assert_g_equal(new_geom, geom1);
}
{
// Transform in place
point<double> 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<double> 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