示例#1
0
int main()
{
    typedef boost::geometry::model::d2::point_xy<double> point_type;
    typedef boost::geometry::model::polygon<point_type> polygon_type;

    polygon_type poly;
    boost::geometry::read_wkt(
        "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)"
            "(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", poly);

    point_type p(4, 1);

    std::cout << "within: " << (boost::geometry::within(p, poly) ? "yes" : "no") << std::endl;
    /*<-*/ create_svg("within.svg", poly, p); /*->*/
    return 0;
}
示例#2
0
int main()
{
    typedef boost::geometry::model::d2::point_xy<double> point_type;
    typedef boost::geometry::model::polygon<point_type> polygon_type;

    polygon_type poly;
    boost::geometry::read_wkt(
        "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)"
            "(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", poly);

    point_type p;
    boost::geometry::centroid(poly, p);

    std::cout << "centroid: " << boost::geometry::dsv(p) << std::endl;
    /*<-*/ create_svg("centroid.svg", poly, p); /*->*/
    return 0;
}
示例#3
0
int main()
{
    typedef boost::geometry::model::d2::point_xy<double> point;

    boost::geometry::model::polygon<point> polygon;

    boost::geometry::read_wkt(
        "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)"
            "(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", polygon);

    boost::geometry::model::box<point> box;
    boost::geometry::envelope(polygon, box);

    std::cout << "envelope:" << boost::geometry::dsv(box) << std::endl;

    /*<-*/ create_svg("envelope.svg", polygon, box); /*->*/
    return 0;
}
示例#4
0
int main()
{
    typedef boost::geometry::model::d2::point_xy<double> point_type;
    typedef boost::geometry::model::polygon<point_type> polygon_type;

    polygon_type poly;
    boost::geometry::read_wkt(
        "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)"
            "(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", poly);

    point_type p(4, 1);

    boost::geometry::de9im::matrix matrix = boost::geometry::relation(p, poly);
    std::string code = matrix.str();

    std::cout << "relation: " << code << std::endl;
    /*<-*/ create_svg("relation.svg", poly, p); /*->*/
    return 0;
}
示例#5
0
文件: main.cpp 项目: CCJY/coliru
int main()
{
   typedef boost::geometry::model::d2::point_xy<long long,    boost::geometry::cs::cartesian> point_2d;
   typedef boost::geometry::model::polygon<point_2d> polygon_2d;

    polygon_2d green;

    boost::geometry::append(green, point_2d(2861880L,  909575L));
    boost::geometry::append(green, point_2d(2749020L,  562215L));
    boost::geometry::append(green, point_2d(2742380L,  557393L));
    boost::geometry::append(green, point_2d(2469080L,  519765L));
    boost::geometry::append(green, point_2d(1944770L,  597441L));
    boost::geometry::append(green, point_2d(1592130L, 1011410L));
    boost::geometry::append(green, point_2d(2035760L, 1495370L));
    boost::geometry::append(green, point_2d(2861880L,  909575L));


    polygon_2d blue;
    boost::geometry::append(blue, point_2d(2400000L,  530000L));
    boost::geometry::append(blue, point_2d(2400000L, -530000L));
    boost::geometry::append(blue, point_2d(-600000L, -530000L));
    boost::geometry::append(blue, point_2d(-600000L,  530000L));
    boost::geometry::append(blue, point_2d(2400000L,  530000L));

    boost::geometry::correct(green);
    boost::geometry::correct(blue);

    std::vector<polygon_2d> output;
    boost::geometry::intersection(green, blue, output);

    create_svg("test.svg", green, blue);
    if(output.size())
    {
        std::cout << "green && blue:" << std::endl;
        std::cout<<boost::geometry::dsv(output[0])<<std::endl;
        std::cout<<boost::geometry::area(output[0])<<std::endl;
    }

    return 0;
}
示例#6
0
void test_random_multi_points(MultiPoint& result, int& index,
            Generator& generator,
            int pcount, settings_type const& settings)
{
    typedef typename bg::point_type<MultiPoint>::type point_type;

    MultiPoint mp;
    bg::model::polygon<point_type> hull;

    make_multi_point(mp, generator, pcount);
    bg::convex_hull(mp, hull);
    // Check if each point lies in the hull
    bool correct = check_hull(mp, hull);
    if (! correct)
    {
        std::cout << "ERROR! " << std::endl
            << bg::wkt(mp) << std::endl
            << bg::wkt(hull) << std::endl
            << std::endl;
            ;
    }

    if (settings.svg || ! correct)
    {
        std::ostringstream out;
        out << "random_mp_" << index++ << "_" << pcount << ".svg";
        create_svg(out.str(), mp, hull);
    }
    if (settings.wkt)
    {
        std::cout 
            << "input: " << bg::wkt(mp) << std::endl
            << "output: " << bg::wkt(hull) << std::endl
            << std::endl;
            ;
    }
}