
Geometry : 
Subject: Re: [geometry] problem with wkt io
From: Mateusz Loskot (mateusz_at_[hidden])
Date: 20131009 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 nonclosed 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 nonclosed 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
nonclosed polygon/ring type is specified.
Barend, shall we update the docs there?
Best regards,
 Mateusz Loskot, http://mateusz.loskot.net
Geometry list run by mateusz at loskot.net