Boost logo

Geometry :

Subject: Re: [geometry] polygons with holes
From: Barend Gehrels (barend_at_[hidden])
Date: 2012-01-30 17:57:53


Hi Jeff,

On 30-1-2012 23:39, jeffpoly wrote:
>
> Thanks for your help. Unfortunately I do not have the shapefil.h file and I
> am new to Boost Geometry, so I am not sure that I if I understand your
> answers fully.

Well, shapefil.h is not necessary (in that file it is, but for the
algorithm it is not). This is just the place where I coded it.

> This assumes that:
> - clockwise rings are outer rings (area is positive)
> - counterclockwise rings are inner rings (area is negative)
> I do not know rings area before construct, actaully I need to make sure that
> CW rings are outer rings with positive area, and CCW rings are inner rings
> with negative area. Also I do have open rings, could I use similar
> algorithm?

OK - that is also possible. Are all your rings open? If all are, you can
use the polygon type for that (with "true" for the open template
parameter). If some are, that is inconvenient, you better all close them
then (you can use geometry::correct for that, which works on a ring,
will close it and will turn it in clockwise order).

If you don't know the orientation before, (maybe) no problem. You sort
all rings on abs(area). (If you called correct they are all clockwise
now). Sorting is just a convenience, because a larger ring can never be
within a smaller ring. Then you check (with the "within") function for
all rings if they are inside a larger ring. If they are, you add them to
the polygon.

Possible problem: it can be more complex if you have more nesting, so
polygon A contains B and B contains C and C contains D. If that is the
case - you have to use multi-polygons. If you don't know before, yes, to
be sure you have to use a multi-polygon and implement the complex case...

Another possible problem: do your rings (the boundaries) intersect each
other? If yes you cannot build a correct (multi)polygon of it.

>
>> In the sample (shp_read_object) it assumes one exterior ring, but it (or
>> something similar) will work for a multi-polygon as well.
> Sorry that I can not figure out how to make this happen, could you please a
> little more details or examples?
>

Yeah, this explanation might be still too short for your needs. I'll
recheck this weekend if I happen to have a better example or create a
bit more thorough explanation...

Regards, Barend


Geometry list run by mateusz at loskot.net