Boost logo

Geometry :

Subject: Re: [geometry] reading WKT (was: #8376: difference of non-closed polygons returns closed polygon)
From: Volker Schöch (vschoech_at_[hidden])
Date: 2014-10-13 05:28:03


Dear Adam,
Dear Geometry Team,

First of all, please accept my apologies for sidetracking your attention to the difference method while the issue at hand was in fact a shortcoming in my understanding of WKT. My evaluation of 1.56.0 is still not complete, so I do not want to go into any more detail just yet. In the meantime, in reply to your email:

> It seems that read_wkt() function always naiively fills the Polygon with data, not taking into account the closure. This means that open Polygons contains duplicated Points if "proper" closed WKT is passed. I consider this as a bug, what do you think?
> If we decided to fix it, do you think that read_wkt() for open Polygons should:
> 1. check the last Point and if it was the same as the first one, not append it
> 2. check the correctness of the input and e.g. throw if the WKT wasn't closed
> 3. always assume that a valid WKT is passed and always ommit the last Poin
> 4. ?
>
> 1 is probably the best because it's backward compatible.

Thank you for looking into this. Yes, I agree that this must be considered a bug.

Personally I'm fine as long as correct WKT polygons are converted to their correct equivalents in the chosen internal representation (which as you point out currently isn't the case). I am generally not in favor of "forgiving code". Rather, I am a proponent of "crash early". As a user, I am responsible for following the correct syntax, and if some forgivingness is needed, then I can add another layer with heuristics that try to interpret malformed input and cleverly transform it into a conforming representation.

IMO, in the situation at hand, there is no problem with requiring the correct WKT syntax. The problem is that I could get by with my ignorance of WKT syntax for such a long time that I became convinced I had a proper understanding of how WKT is meant to be used. Now I have to catch up and fix my WKT representations. I'll do it regardless of how you deal with not well-defined WKT in the future, and then I'll go from there.

> The opposite situation could also be possible. Filling closed Polygon with open WKT would probably result in invalid Polygon.
> Though this could be handled by bg::correct().

Based on my line of thought above, there is no "open WKT". If I am not mistaken (again), this problem does not occur with well-defined WKT input, thus I don't care much how you treat this case (and generally prefer a "crash early" approach).

> Btw, maybe bg::correct() should not only append missing Points for closed Polygons but also remove duplicated for open ones? For consistency.

I don't have an opinion on this one because I'm still not entirely clear about the semantics and the use cases for correct vs. unique vs. remove_spikes.

Regards and thanks again!
   Volker
--
Volker Schöch | vschoech_at_[hidden]
Senior Software Engineer

We are looking for C++ Developers: http://www.think-cell.com/career

think-cell Software GmbH | Chausseestr. 8/E | 10115 Berlin | Germany
http://www.think-cell.com | phone +49 30 666473-10 | US phone +1 800 891 8091

Amtsgericht Berlin-Charlottenburg, HRB 85229 | European Union VAT Id DE813474306
Directors: Dr. Markus Hannebauer, Dr. Arno Schödl


Geometry list run by mateusz at loskot.net