$include_dir="/home/hyper-archives/geometry/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [geometry] Ring intersection question
From: Adam Wulkiewicz (adam.wulkiewicz_at_[hidden])
Date: 2014-11-06 18:33:37
Hi,
Menelaos Karavelas wrote:
> On 07/11/2014 12:10 ??, Menelaos Karavelas wrote:
>> On 06/11/2014 11:56 ??, Will Lucas wrote:
>>
>>> This would hopefully allow me to define a custom multi_polygon. As 
>>> my initial attempt to just create an std::vector<dft::Contour> as a 
>>> multi_polygon, resulted in a bunch of compiler complaints :D
>>>
>>
>> I think this is because your vector's value type is a ring rather 
>> than a polygon.
Actually this works for me. Though since a container of Rings isn't a 
"proper" Geometry other functions may not work with it, e.g. bg::wkt() 
from your example.
My code:
#include<boost/foreach.hpp>
#include  <boost/geometry.hpp>
namespace  bg  =  boost::geometry;
typedef  bg::model::point<int,  2,  bg::cs::cartesian>  point_type;
typedef  bg::model::ring<point_type>  ring_type;
typedef  std::vector<ring_type>  rings_container;
int  main()
{
     ring_type  pol1,  pol2;
     bg::read_wkt("POLYGON((75  75,75  175,275  175,275  75,75  75))",  pol1);
     bg::read_wkt("POLYGON((50  50,50  150,250  150,250  50,50  50))",  pol2);
     rings_container  rings;
     bg::intersection(pol1,  pol2,  rings);
     BOOST_FOREACH(ring_type  const&  r,  rings)
         std::cout  <<  bg::wkt(r)  <<  std::endl;
     return  0;
}
FYI, it compiles also if the input Geometries are Polygons. I tried this:
polygon_typepol1,pol2;
bg::read_wkt("POLYGON((0  0,0  10,10  10,10  0,0  0),(4  4,6  4,6  6,4  6,4  4))",  pol1);
bg::read_wkt("POLYGON((1  1,1  11,11  11,11  1,1  1))",  pol2);
rings_container  rings;
bg::intersection(pol1,  pol2,  rings);
BOOST_FOREACH(ring_type  const&  r,  rings)
     std::cout  <<  bg::wkt(r)  <<  std::endl;
bg::intersection(pol2,  pol1,  rings);
BOOST_FOREACH(ring_type  const&  r,  rings)
     std::cout  <<  bg::wkt(r)  <<  std::endl;
In this case holes aren't included in the output:
POLYGON((1 10,10 10,10 1,1 1,1 10))
POLYGON((1 10,10 10,10 1,1 1,1 10))
Is this behavior intended?
Regards,
Adam