Boost logo

Geometry :

Subject: [ggl] Difference / xor for multi polygons
From: Barend Gehrels (barend)
Date: 2011-03-07 13:30:27


Hi Javier,

On 7-3-2011 4:15, Javier Gonzalez wrote:
>
> Unfortunately, here's another faulty case
>
> UNION of:
>
> POLYGON((-2 2, 1842 2, 1842 -2362, -2 -2362, -2 2), (0 0, 0 -2360,
> 1840 -2360, 1840 0, 0 0))
>
> with:
>
> POLYGON((-0.01 -1960, 0 -1960, 0 -1880, 80.01 -1960, -0.01 -1960))

Note that the last polygon is not valid. It has a
"Self-intersection[-0.01 -1960]" as reported by PostGIS, and also SQL
Server Spatial reports it as invalid.

Do you mean POLYGON ((-0.01 -1960, 80.01 -1960, 0 -1880, -0.01 -1960)),
which looks visually the same and is valid?

The first, invalid one gives indeed that polygon. Boost.Geometry does
not check validity beforehand. Self-intersections might give unexpected
results.

Unioning with the valid one I suggested above gives me :

POLYGON((-2 2,1842 2,1842 -2362,-2 -2362,-2 2),(0 -1880,80.01 -1960,0
-1960,0 -2360,1840 -2360,1840 0,0 0,0 -1880))

visually the same as the clipper result and giving the same area. So
this case is not faulty, but as designed.

>
> should give (at least using clipper)
> POLYGON((-1.999999 -2362, -1.999999 1.999999, 1842 1.999999, 1842
> -2362, -1.999999 -2362), (0 -2360, 1840 -2360, 1840 0, 0 0, 0 -1880,
> 80.01 -1960, 0 -1960, 0 -2360))

The result of clipper, or this representation of it, is not completely
correct: the input has a minimal x-value of -2, meaning the union should
have that minimum x-value too. But that is a detail.

Regards, Barend

-- 
Barend Gehrels
http://about.me/barendgehrels

Geometry list run by mateusz at loskot.net