# Geometry :

Subject: [ggl] Polygon DP simplification
From: V D (zedxz2)
Date: 2011-09-28 20:51:32

Hi Mateusz,

Sure thing. See below.

Basically, the original polygon has values between 0 and 1, and is simplified with 1.0/2048.0
The second polygon is the original with point values multiplied by 2047 (0..2047, so 2048 pixels for example) and is simplified with 1.0

Original polygon has 37 points, simplified with 1.0/2048 I get 20 points
Multiplied by 2047 and simplified with 1.0, I get 35 points (correct behavior with 1 pixel distance).

Shouldn't the number of points of the simplified polygons be the same if the point coordinates and max distance are proportional ?

-v

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/ring.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp>
#include <boost/foreach.hpp>

int main()
{
typedef boost::geometry::model::d2::point_xy<double> point_xy;
typedef boost::geometry::model::polygon<point_xy > polygon;
typedef boost::geometry::model::ring<point_xy > ring;
typedef boost::geometry::model::multi_polygon<polygon > multi_polygon;

multi_polygon original_1;
multi_polygon simplified_1;

// Values between 0..1 and simplified with 1/2048
boost::geometry::read_wkt("MULTIPOLYGON(((0.561648 1,1 1,1 0,0.468083 0,0.52758 0.00800554,0.599683 0.0280924,0.601611 0.265374,0.622693 0.316765,0.69507 0.357497,0.695623 0.429711,0.655111 0.502298,0.696467 0.543147,0.840712 0.593546,0.882583 0.66546,0.852357 0.748213,0.84264 0.789567,0.832667 0.841202,0.832667 0.841202,0.740538 0.873004,0.617349 0.905045,0.566576 0.977697,0.561648 1)),((0 0.801979,0.0308575 0.786234,0.0705513 0.631135,0.141616 0.527248,0.233985 0.505872,0.264777 0.526263,0.336631 0.505009,0.356603 0.422321,0.355803 0.350038,0.375252 0.205364,0.415206 0.0709182,0.45479 0,0 0,0 0,0 0.801979)))", original_1);

std::cout << "Original: \n" << boost::geometry::num_points(original_1) << " points.\n\n";

boost::geometry::simplify(original_1, simplified_1, 1.0 / 2048.0);

std::cout << "Polygon with values 0..1 and simplified with 1.0 / 2048.0 \n"
<< "Result: \n" << boost::geometry::wkt(simplified_1) << "\n" << boost::geometry::num_points(simplified_1) << " points.\n\n";

// Multiply every points from original_1 by 2047
multi_polygon original_2(original_1);
BOOST_FOREACH(polygon& p, original_2)
{
BOOST_FOREACH(point_xy& pt, p.outer())
{
pt.x(pt.x() * 2047.0);
pt.y(pt.y() * 2047.0);
}

BOOST_FOREACH(ring& r, p.inners())
{
BOOST_FOREACH(point_xy& pt, r)
{
pt.x(pt.x() * 2047.0);
pt.y(pt.y() * 2047.0);
}
}
}

multi_polygon simplified_2;
boost::geometry::simplify(original_2, simplified_2, 1.0);
std::cout << "Same values but multiplied by 2047.0 and simplified with 1.0\n"
<< "Result: \n" << boost::geometry::wkt(simplified_2) << "\n" << boost::geometry::num_points(simplified_2) << " points.\n";

return 0;
}

On Sep 27, 2011, at 10:22 AM, Mateusz Loskot wrote:

> On 20/09/11 23:05, V D wrote:
>> I'm hoping someone with experience with bg::simplify might help me here:
>> I am quite mystified as to why the following 2 simplifications does not
>> return the "same" polygon.
>>
>> Suppose in the first case, my coordinates are ratios between 0 and 1,
>> and that I simplify with 1/2048 max distance (pixels)
>> [...]
>
> Could you provide a minimal complete compilable test case that
> exhibits this problem?
>
> Best regards,
> --
> Mateusz Loskot, http://mateusz.loskot.net
> Charter Member of OSGeo, http://osgeo.org
> Member of ACCU, http://accu.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/ggl/attachments/20110927/46158eec/attachment-0001.html

Geometry list run by mateusz at loskot.net