| 1 | #include <iostream>
|
|---|
| 2 | #include <deque>
|
|---|
| 3 |
|
|---|
| 4 | #include <boost/geometry.hpp>
|
|---|
| 5 | #include <boost/geometry/geometries/point_xy.hpp>
|
|---|
| 6 | #include <boost/geometry/geometries/polygon.hpp>
|
|---|
| 7 | #include <boost/geometry/geometries/linestring.hpp>
|
|---|
| 8 |
|
|---|
| 9 | #include <boost/foreach.hpp>
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 | int main()
|
|---|
| 13 | {
|
|---|
| 14 | typedef boost::geometry::model::d2::point_xy<long> point;
|
|---|
| 15 | typedef boost::geometry::model::polygon<point> polygon;
|
|---|
| 16 | typedef boost::geometry::model::linestring<point> linestring;
|
|---|
| 17 |
|
|---|
| 18 | polygon green;
|
|---|
| 19 | linestring blue;
|
|---|
| 20 |
|
|---|
| 21 | boost::geometry::read_wkt(
|
|---|
| 22 | "POLYGON((0 0, 0 2, 2 2, 2 0, 1 0, 0 0))", green);
|
|---|
| 23 |
|
|---|
| 24 | boost::geometry::read_wkt(
|
|---|
| 25 | "LINESTRING(1 -1,1 0, 1 1)", blue);
|
|---|
| 26 |
|
|---|
| 27 | boost::geometry::correct(green);
|
|---|
| 28 | boost::geometry::correct(blue);
|
|---|
| 29 |
|
|---|
| 30 | std::deque<linestring> output;
|
|---|
| 31 | boost::geometry::intersection(blue, green, output);
|
|---|
| 32 |
|
|---|
| 33 | int i = 0;
|
|---|
| 34 | std::cout << "green && blue:" << std::endl;
|
|---|
| 35 | BOOST_FOREACH(linestring const& p, output)
|
|---|
| 36 | {
|
|---|
| 37 | std::cout << i++ << ": " << boost::geometry::dsv(p) << std::endl;
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 | return 0;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|