Boost logo

Geometry :

Subject: Re: [geometry] problem with wkt io
From: Mateusz Loskot (mateusz_at_[hidden])
Date: 2013-10-09 15:14:00


On 9 October 2013 20:00, lepere renaud <lepere.renaud_at_[hidden]> wrote:
>
> I am using read_wkt to read wkt polygons and wkt to convert them to string
> but i have some problems. I though that wkt polygons should have the last
> point equal to the first one ; however in my model polygons are not closed.
> The function read_wkt and wkt do not handle the last point, is this normal
> or did i missed something ?
>
> A small code to illustrate the problem.
>
> #include "boost/geometry.hpp"
> #include "boost/geometry/geometries/geometries.hpp"
> #include "boost/geometry/io/wkt/wkt.hpp"
>
> using namespace boost::geometry;
>
> typedef model::point< double, 2, boost::geometry::cs::cartesian > Point;
> typedef model::polygon< Point, false, false > Polygon;

You specify non-closed polygon....

> int main()
> {
> Polygon p;
> read_wkt("POLYGON((0.0 0.0, 10.0 0.0, 10.0 10.0, 0 10.0, 0.0 0.0))", p);
> // p is invalid according to the definition above
> // (do not repeat last point)
> correct(p);

and, correct will make it correct according to the type specification above,
As you mean non-closed polygon, the redundant point is removed.

Either specify closed polygon:

typedef model::polygon< Point, false, true> Polygon;

or do not call correct()

The documentation about the correct() algorithm [1] says:

"""
To all rings which do not have a closing point and are typed as they
should have one, the first point is appended
"""

but it does not say that apparently the opposite correction will
happen as well - redundant repeated last point is removed if
non-closed polygon/ring type is specified.

Barend, shall we update the docs there?

[1] http://www.boost.org/doc/libs/1_54_0/libs/geometry/doc/html/geometry/reference/algorithms/correct.html

Best regards,

-- 
Mateusz  Loskot, http://mateusz.loskot.net

Geometry list run by mateusz at loskot.net