Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72294 - in trunk/libs/geometry/test: algorithms strategies
From: barend.gehrels_at_[hidden]
Date: 2011-05-30 16:58:10


Author: barendgehrels
Date: 2011-05-30 16:58:09 EDT (Mon, 30 May 2011)
New Revision: 72294
URL: http://svn.boost.org/trac/boost/changeset/72294

Log:
Added spherical test for within
Updated spherical test for area
Fixed spherical side test
Text files modified:
   trunk/libs/geometry/test/algorithms/area.cpp | 16 ++++++++++--
   trunk/libs/geometry/test/algorithms/within.cpp | 48 ++++++++++++++++++++++++++++++++++++++++
   trunk/libs/geometry/test/strategies/spherical_side.cpp | 2
   3 files changed, 62 insertions(+), 4 deletions(-)

Modified: trunk/libs/geometry/test/algorithms/area.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/area.cpp (original)
+++ trunk/libs/geometry/test/algorithms/area.cpp 2011-05-30 16:58:09 EDT (Mon, 30 May 2011)
@@ -91,7 +91,17 @@
> spherical_earth(6373);
     bg::read_wkt("POLYGON((-178.7858 70.7852, 177.4758 71.2333, 179.7436 71.5733, -178.7858 70.7852))", geometry);
     area = bg::area(geometry, spherical_earth);
- BOOST_CHECK_CLOSE(area, 4506.6389, 0.001); // SQL Server gives: 4537.9654419375
+ // SQL Server gives: 4537.9654419375
+ // PostGIS gives: 4537.9311668307
+ // Note: those are Geographic, this test is Spherical
+ BOOST_CHECK_CLOSE(area, 4506.6389, 0.001);
+
+ // Wrangel, more in detail
+ bg::read_wkt("POLYGON((-178.568604 71.564148,-178.017548 71.449692,-177.833313 71.3461,-177.502838 71.277466 ,-177.439453 71.226929,-177.620026 71.116638,-177.9389 71.037491,-178.8186 70.979965,-179.274445 70.907761,-180 70.9972,179.678314 70.895538,179.272766 70.888596,178.791016 70.7964,178.617737 71.035538,178.872192 71.217484,179.530273 71.4383 ,-180 71.535843 ,-179.628601 71.577194,-179.305298 71.551361,-179.03421 71.597748,-178.568604 71.564148))", geometry);
+ area = bg::area(geometry, spherical_earth);
+ // SQL Server gives: 7669.10402181435
+ // PostGIS gives: 7669.55565459832
+ BOOST_CHECK_CLOSE(area, 7616.523769, 0.001);
 
     // Check more at the equator
     /*
@@ -141,7 +151,7 @@
             // Create colatitudes (measured from pole)
             BOOST_FOREACH(Point& p, aurha)
             {
- bg::set<1>(p, 90.0 - bg::get<1>(p));
+ bg::set<1>(p, ct(90) - bg::get<1>(p));
             }
             bg::correct(aurha);
         }
@@ -201,7 +211,7 @@
 
 #ifdef HAVE_TTMATH
     test_all<bg::model::d2::point_xy<ttmath_big> >();
- test_spherical<bg::model::point<ttmath_big, 2, bg::cs::spherical<bg::degree> > >();
+ test_spherical<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >();
 #endif
 
     return 0;

Modified: trunk/libs/geometry/test/algorithms/within.cpp
==============================================================================
--- trunk/libs/geometry/test/algorithms/within.cpp (original)
+++ trunk/libs/geometry/test/algorithms/within.cpp 2011-05-30 16:58:09 EDT (Mon, 30 May 2011)
@@ -62,7 +62,51 @@
         true, false);
 }
 
+template <typename Point>
+void test_spherical()
+{
+ typedef typename bg::coordinate_type<Point>::type ct;
+ bg::model::polygon<Point> wrangel;
+
+ // SQL Server check (no geography::STWithin, so check with intersection trick)
+ /*
+
+ with q as (
+ select geography::STGeomFromText('POLYGON((-178.569 71.5641,-179.034 71.5977,-179.305 71.5514,-179.629 71.5772,-180 71.5358,179.53 71.4383,178.872 71.2175,178.618 71.0355,178.791 70.7964,179.273 70.8886,179.678 70.8955,-180 70.9972,-179.274 70.9078,-178.819 70.98,-177.939 71.0375,-177.62 71.1166,-177.439 71.2269,-177.503 71.2775,-177.833 71.3461,-178.018 71.4497,-178.569 71.5641))',4326) as wrangel
+ )
+
+ select wrangel.STArea()/1000000.0
+ ,geography::STGeomFromText('POINT(-179.3 71.27)',4326).STIntersection(wrangel).STAsText() as workaround_within_1
+ ,geography::STGeomFromText('POINT(-179.9 70.95)',4326).STIntersection(wrangel).STAsText() as workaround_within_2
+ ,geography::STGeomFromText('POINT(179.9 70.95)',4326).STIntersection(wrangel).STAsText() as workaround_within_3
+ from q
+
+ -> 7669.10402181435 POINT (-179.3 71.27) GEOMETRYCOLLECTION EMPTY GEOMETRYCOLLECTION EMPTY
+
+ PostGIS knows Within for Geography neither, and the intersection trick gives the same result
+
+ */
+
+ bg::read_wkt("POLYGON((-178.568604 71.564148,-178.017548 71.449692,-177.833313 71.3461,-177.502838 71.277466 ,-177.439453 71.226929,-177.620026 71.116638,-177.9389 71.037491,-178.8186 70.979965,-179.274445 70.907761,-180 70.9972,179.678314 70.895538,179.272766 70.888596,178.791016 70.7964,178.617737 71.035538,178.872192 71.217484,179.530273 71.4383 ,-180 71.535843 ,-179.628601 71.577194,-179.305298 71.551361,-179.03421 71.597748,-178.568604 71.564148))", wrangel);
 
+ bool within = bg::within(Point(-179.3, 71.27), wrangel);
+ BOOST_CHECK_EQUAL(within, true);
+
+ within = bg::within(Point(-179.9, 70.95), wrangel);
+ BOOST_CHECK_EQUAL(within, false);
+
+ within = bg::within(Point(179.9, 70.95), wrangel);
+ BOOST_CHECK_EQUAL(within, false);
+
+ // Test using great circle mapper
+ // http://www.gcmap.com/mapui?P=5E52N-9E53N-7E50N-5E52N,7E52.5N,8E51.5N,6E51N
+
+ bg::model::polygon<Point> triangle;
+ bg::read_wkt("POLYGON((5 52,9 53,7 50,5 52))", triangle);
+ BOOST_CHECK_EQUAL(bg::within(Point(7, 52.5), triangle), true);
+ BOOST_CHECK_EQUAL(bg::within(Point(8.0, 51.5), triangle), false);
+ BOOST_CHECK_EQUAL(bg::within(Point(6.0, 51.0), triangle), false);
+}
 
 
 int test_main( int , char* [] )
@@ -70,8 +114,12 @@
     test_all<bg::model::d2::point_xy<int> >();
     test_all<bg::model::d2::point_xy<double> >();
 
+ test_spherical<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
+
+
 #if defined(HAVE_TTMATH)
     test_all<bg::model::d2::point_xy<ttmath_big> >();
+ test_spherical<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >();
 #endif
 
     return 0;

Modified: trunk/libs/geometry/test/strategies/spherical_side.cpp
==============================================================================
--- trunk/libs/geometry/test/strategies/spherical_side.cpp (original)
+++ trunk/libs/geometry/test/strategies/spherical_side.cpp 2011-05-30 16:58:09 EDT (Mon, 30 May 2011)
@@ -135,7 +135,7 @@
 
 #if defined(HAVE_TTMATH)
     typedef ttmath::Big<1,4> tt;
- test_all<bg::model::point<tt, 2, bg::cs::spherical<bg::degree> > >();
+ test_all<bg::model::point<tt, 2, bg::cs::spherical_equatorial<bg::degree> > >();
 #endif
 
     return 0;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk