[ create a new paste ] login | about

Link: http://codepad.org/cXbYPVie    [ raw code | fork ]

C++, pasted on Apr 15:
#include <iostream>

#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/domains/gis/io/wkt/wkt.hpp>

int main()
{
    typedef boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > polygon;
    typedef boost::geometry::model::multi_polygon<polygon> mp;

    mp green, blue;
    
    try
    {
    
        std::string const invalid = "MULTIPOLYGON (((447672 5033500, 447890 5033500, 447891 5033500, 447872 5033450, 447841 5033400, 447804 5033370, 447765 5033350, 447755 5033360, 447746 5033380, 447739 5033380, 447718 5033380, 447696 5033410, 447689 5033440, 447672 5033500)), ((447890 5033500, 448000 5033500, 448000 5033080, 447956 5033040, 447900 5033000, 447839 5032960, 447835 5032950, 447797 5032990, 447784 5033040, 447777 5033100, 447766 5033150, 447767 5033160, 447778 5033180, 447779 5033240, 447816 5033320, 447816 5033330, 447780 5033340, 447765 5033350, 447804 5033370, 447841 5033400, 447872 5033450, 447891 5033500, 447890 5033500), (447849 5033190, 447869 5033190, 447907 5033230, 447923 5033260, 447951 5033300, 447951 5033320, 447929 5033350, 447907 5033360, 447900 5033370, 447878 5033380, 447872 5033370, 447839 5033310, 447813 5033260, 447812 5033230, 447829 5033200, 447849 5033190)))";
        std::string const valid =   "MULTIPOLYGON (((447835 5032950, 447839 5032960, 447900 5033000, 447956 5033040, 448000 5033080, 448000 5033500, 447891 5033500, 447890 5033500, 447672 5033500, 447689 5033440, 447696 5033410, 447718 5033380, 447739 5033380, 447746 5033380, 447755 5033360, 447765 5033350, 447780 5033340, 447816 5033330, 447816 5033320, 447779 5033240, 447778 5033180, 447767 5033160, 447766 5033150, 447777 5033100, 447784 5033040, 447797 5032990, 447835 5032950), (447849 5033190, 447829 5033200, 447812 5033230, 447813 5033260, 447839 5033310, 447872 5033370, 447878 5033380, 447900 5033370, 447907 5033360, 447929 5033350, 447951 5033320, 447951 5033300, 447923 5033260, 447907 5033230, 447869 5033190, 447849 5033190)))";

        boost::geometry::read_wkt(valid, green);
        boost::geometry::read_wkt(valid, blue);
        
        std::cout << "is self-intersecting: " << (boost::geometry::intersects(green) ? "yes" : "no") << std::endl;
        std::cout << "green: " << boost::geometry::area(green) << std::endl;
            
        mp output;
        boost::geometry::intersection(green, blue, output);
        std::cout << "green && blue: " << boost::geometry::area(output) << std::endl;
    }
    catch(std::exception const& e)
    {
        std::cout << e.what() << std::endl;
    }
    return 0;
}


Create a new paste based on this one


Comments: