Subject: Re: [geometry] possibly unwanted behavior in bg::wkt
From: Adam Wulkiewicz (adam.wulkiewicz_at_[hidden])
Date: 2014-10-06 05:27:46
Menelaos Karavelas wrote:
> Hi all.
> I stumbled upon the following behavior when outputting a closed
> polygon in WKT format: I have a closed polygon, I modified its first
> point, but not the last, which means that the polygon is now invalid,
> and then I outputted this invalid polygon in WKT. For the specifics
> see the attached program and its output.
> The "strange" thing with this example is that the modified/corrected
> polygon has one more point that the original one (what used to be the
> first/last point of the original valid polygon). It is really not
> obvious to me whether this is really a bug (as I considering the WKT
> of an invalid polygon), but on the other hand it is really strange for
> me that we introduce a "new" point in the polygon. By "new" here I
> mainly mean that the new polygon has
> To be honest what would have made more sense to me, in the WKT output
> function, is to "close" the polygon with an additional point (the
> first point) only for open polygons, rather than try to close every
> polygon irrespectively of its closedness. For polygons that are
> defined as closed I would not try to close them.
> On the other hand, I consider the behavior of bg::correct as correct
> (see attached program/output again).
> One related question: why do we want to force the closedness in the
> WKT description for polygon and not for rings?
> I would like to hear thoughts/opinions/suggestions about this.
I understand your PoV.
bg::wkt() shouldn't check if the Polygon is invalid because it's not its
bg::correct() is a different story because it's called explicitly when
the user wants to correct an invalid Polygon so he must be aware that
the Polygon may be invalid.
Btw, the opposite problem. Consider read_wkt() which should always take
closed Geometries as WKT. Should it check if the last Point is the same
as the first one or just blindly fill the Polygon with data? Or e.g.
should it check it e.g. only for open Rings and don't append if the
Points were equal? Or should an exception be generated? I'm not sure how
this is implemented right now.
I don't have any problems with either approach. Though I think that IOs
shouldn't try to fix the data, also if the input was wrong then the
exception should be thrown. It's because we CAN'T know or predict what
should be the correct thing to do. Without the checking of the validity
of the 2 possible fixed polygons (last Point replaced or additional
Point added), and even then both polygons could be valid and we'd be in
the similar place. Not to mention that such checks would take a lot of time.
Could changing the way how wkt() works break users' code? If for Rings
it works differently than for Polygons I'd say that changing the
behavior isn't a problem.
Geometry list run by mateusz at loskot.net