Geometry :

Subject: [ggl] intersection of two vectors of polygons
From: Barend Gehrels (barend)
Date: 2011-04-29 08:58:11

Hi Vishnu,

On 28-4-2011 19:17, Vishnu wrote:
> I'm wondering whether anyone has recommendations for calculating the
> intersection between two vectors of polygons.

> Currently, I use boost::geometry::intersection(). Before calling this
> function, I convert the 2 vectors of polygons into 2 valid multi_polygons.
> The problem with this approach is that instead of getting 9 discrete
> polygons in the intersection result, I get a single polygon that is the
> union of the 9 polygons.

If I understand you correctly, this is my advice: you have to convert
the 2 vectors (apart from each other) to 2 valid multi-polygons using
the union operation... And then do the intersection with those 2
multi-polygons. Not union them all.

So (as I answered earlier off-list):

I would say:
2) Make of each of them a multi-polygon by:
a) start with first polygon of v1 as "result" (result is a
multi_polygon), for all other polygons in v1, union it with "result"
b) same for v2
3) You now have two valid multi-polygons and can intersect them.

> The reason it's important to get 9 discrete polygons in the intersection is
> as follows. Say that 4 adjacent squares in the first collection are 4 farms
> labeled by ownership and the 4 adjacent squares in the 2nd set are labeled
> according to mineral rights. Let's say one wants the polygons corresponding
> to farm with owner "1" and mineral rights "3". (...)

I think I will look in more detail to your use case and answer in more
detail, this weekend (time permitted).

Regards, Barend

Geometry list run by mateusz at loskot.net