Skip to content

Commit 124362d

Browse files
author
Dane Springmeyer
committed
stop correcting geometries at decode time
- the original motivation for this was to avoid needing to mutate a copy later on (for operations needing correct winding order) - but mutating a copy is looking feasible, so removing this now.
1 parent ef33646 commit 124362d

File tree

5 files changed

+13
-16
lines changed

5 files changed

+13
-16
lines changed

include/mapnik/json/geometry_util.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
#include <mapnik/geometry.hpp>
2727
#include <mapnik/geometry_adapters.hpp>
28-
// boost.geometry
29-
#include <boost/geometry/algorithms/correct.hpp>
3028

3129
namespace mapnik { namespace json {
3230

@@ -86,7 +84,9 @@ struct create_polygon
8684
mapnik::geometry::polygon<double> poly;
8785
std::size_t num_rings = rings.size();
8886
if (num_rings > 1)
87+
{
8988
poly.interior_rings.reserve(num_rings - 1);
89+
}
9090

9191
for ( std::size_t i = 0; i < num_rings; ++i)
9292
{
@@ -100,8 +100,6 @@ struct create_polygon
100100
if (i == 0) poly.set_exterior_ring(std::move(ring));
101101
else poly.add_hole(std::move(ring));
102102
}
103-
// correct oriantations etc
104-
boost::geometry::correct(poly);
105103
geom_ = std::move(poly);
106104
}
107105

plugins/input/shape/shape_io.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <mapnik/make_unique.hpp>
2828
#include <mapnik/datasource.hpp>
2929
#include <mapnik/util/is_clockwise.hpp>
30-
#include <mapnik/geometry_correct.hpp>
3130

3231
using mapnik::datasource_exception;
3332
const std::string shape_io::SHP = ".shp";
@@ -196,6 +195,5 @@ mapnik::geometry::geometry<double> shape_io::read_polygon(shape_file::record_typ
196195
} else {
197196
geom = std::move(poly);
198197
}
199-
mapnik::geometry::correct(geom);
200198
return geom;
201199
}

src/wkb.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <mapnik/feature.hpp>
2929
#include <mapnik/util/noncopyable.hpp>
3030
#include <mapnik/geometry_adapters.hpp>
31-
#include <mapnik/geometry_correct.hpp>
3231

3332
namespace mapnik
3433
{
@@ -411,7 +410,6 @@ mapnik::geometry::geometry<double> geometry_utils::from_wkb(const char* wkb,
411410
{
412411
wkb_reader reader(wkb, size, format);
413412
mapnik::geometry::geometry<double> geom(reader.read());
414-
mapnik::geometry::correct(geom);
415413
return geom;
416414
}
417415

tests/cpp_tests/wkb_formats_test.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <mapnik/feature.hpp>
66
#include <mapnik/geometry_is_valid.hpp>
77
#include <mapnik/geometry_is_simple.hpp>
8+
#include <mapnik/geometry_correct.hpp>
89
#include <mapnik/feature_factory.hpp>
910
#include <vector>
1011
#include <algorithm>
@@ -71,15 +72,16 @@ int main(int argc, char** argv)
7172
mapnik::geometry::geometry<double> geom = mapnik::geometry_utils::from_wkb((const char*)sp_valid_blob,
7273
sizeof(sp_valid_blob) / sizeof(sp_valid_blob[0]),
7374
mapnik::wkbSpatiaLite);
75+
// winding order is not correct per OGC so we'll fix it
76+
mapnik::geometry::correct(geom);
7477
BOOST_TEST(mapnik::geometry::is_valid(geom) && mapnik::geometry::is_simple(geom));
7578

7679
geom = mapnik::geometry_utils::from_wkb((const char*)sp_valid_blob,
7780
sizeof(sp_valid_blob) / sizeof(sp_valid_blob[0]),
7881
mapnik::wkbAuto);
82+
mapnik::geometry::correct(geom);
7983
BOOST_TEST(mapnik::geometry::is_valid(geom) && mapnik::geometry::is_simple(geom));
8084

81-
82-
8385
geom = mapnik::geometry_utils::from_wkb((const char*)sp_invalid_blob,
8486
sizeof(sp_invalid_blob) / sizeof(sp_invalid_blob[0]),
8587
mapnik::wkbAuto);

tests/python_tests/feature_test.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ def test_python_extended_constructor():
3838
def test_add_geom_wkb():
3939
# POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))
4040
wkb = '010300000001000000050000000000000000003e4000000000000024400000000000002440000000000000344000000000000034400000000000004440000000000000444000000000000044400000000000003e400000000000002440'
41-
context = mapnik.Context()
42-
f = mapnik.Feature(context,1)
43-
f.geometry = mapnik.Geometry.from_wkb(unhexlify(wkb))
44-
eq_(f.geometry.is_valid(), True)
45-
eq_(f.geometry.is_simple(), True)
46-
eq_(f.geometry.envelope(), f.envelope())
41+
geometry = mapnik.Geometry.from_wkb(unhexlify(wkb))
42+
eq_(geometry.is_valid(), False) # False because winding order is wrong according to OGC or because end point != first point
43+
eq_(geometry.is_simple(), True)
44+
eq_(geometry.envelope(), mapnik.Box2d(10.0,10.0,40.0,40.0))
45+
geometry.correct()
46+
# valid after calling correct
47+
eq_(geometry.is_valid(), True)
4748

4849
def test_feature_expression_evaluation():
4950
context = mapnik.Context()

0 commit comments

Comments
 (0)