boost::Geometry
boost作為C++中最常用的第三方庫(kù),Geometry庫(kù)里面擁有大量的開源算法。
函數(shù) | 作用 |
---|
get | 獲取幾何圖形(通常為點(diǎn))的坐標(biāo)值 |
get (with index) | 獲取框或段的坐標(biāo)值 |
set | 設(shè)置幾何圖形(通常為點(diǎn))的坐標(biāo)值 |
set (with index) | 設(shè)置Box / Segment的坐標(biāo)值 |
exterior_ring | 獲取多邊形的外接多邊形 |
interior_rings | 獲取多邊形的內(nèi)接多邊形 |
bg::model::polygon<point> poly;
bg::exterior_ring(poly) = boost::assign::tuple_list_of(0, 0)(0, 3)(3, 3)(3, 0)(0, 0);bg::model::polygon<point> poly;
bg::interior_rings(poly) = boost::assign::tuple_list_of(0, 0)(0, 3)(3, 3)(3, 0)(0, 0);
Boost.Array:適用于 Boost.Geometry中不同的點(diǎn)類型
Boost.Fusion:自定義不同的點(diǎn)的結(jié)構(gòu)并適配 Boost.Geometry點(diǎn)的處理方法,因此,可以調(diào)用許多Boost.Geometry算法
Boost.Tuple:組成的點(diǎn)集也可以使用算術(shù)運(yùn)算,元素可以用作 Boost.Geometry 內(nèi)部的點(diǎn)
Boost.Polygon
函數(shù) | 作用 |
---|
point_data | Boost.Polygon點(diǎn)類型(boost::polygon::point_data) |
rectangle_data | Boost.Polygon矩形類型 |
polygon_data | Boost.Polygon多邊形類型 |
polygon_with_holes_data | Boost.Polygon多邊形類型 |
Boost.Range
函數(shù) | 作用 |
---|
filtered | 過(guò)濾不符合條件的數(shù)據(jù) |
reversed | 反轉(zhuǎn)數(shù)據(jù) |
sliced | 指定在數(shù)據(jù)中切出一定部分的數(shù)據(jù) |
strided | 指定在數(shù)據(jù)以n為步長(zhǎng)間接取值 |
area
函數(shù) | 作用 |
---|
area | 計(jì)算幾何圖形的面積 |
area (with strategy) | 使用指定的策略計(jì)算幾何圖形的面積 |
assign
函數(shù) | 作用 |
---|
assign | 將一個(gè)幾何圖形指定給另一個(gè)幾何圖元 |
assign_inverse | 利用assign_ inverse和expand方便地確定兩點(diǎn)的邊界三維框 |
assign_points | 為 linestring, ring 或 polygon指定一系列點(diǎn) |
assign_values | 為幾何圖形指定兩個(gè)坐標(biāo)(通常為二維點(diǎn),三維點(diǎn)和四維點(diǎn)這三種情況) |
assign_zero | assign_zero函數(shù)初始化坐標(biāo)為零的二維或三維點(diǎn)或框 |
append | 將一個(gè)或多個(gè)點(diǎn)附加到linestring, ring, polygon, multi-geometry中 |
buffer
自由函數(shù)緩沖區(qū)計(jì)算幾何體的緩沖區(qū)(多邊形是距離幾何體指定最大距離內(nèi)的空間點(diǎn)集集合)。下圖顯示了策略在生成的緩沖區(qū)中的作用
return_buffer
return_ buffer函數(shù)計(jì)算幾何體的緩沖區(qū)(多邊形是距離幾何體指定最大距離內(nèi)的空間點(diǎn)集集合)。這個(gè)帶有return_前綴的版本返回緩沖區(qū),因此必須在調(diào)用中指定模板參數(shù)。這個(gè)個(gè)人感覺(jué)功能性沒(méi)有buffer好
centroid
centroid
使用指定的策略計(jì)算幾何圖形的質(zhì)心
return_centroid
使用指定的策略計(jì)算幾何圖形的質(zhì)心。這兩個(gè)求質(zhì)心的方式類似。
Densify
線段插值
vector<Point2f> Densify(const Segment2f& seg, int num) {CHECK_GT(num, 0);CHECK(!bg::intersects(seg.s, seg.e));vector<Point2f> pts{seg.s};pts.reserve(num);boost::geometry::line_interpolate(seg, bg::length(seg) / num, pts);pts.emplace_back(seg.e);return pts;
}
部分函數(shù)
函數(shù) | 作用 |
---|
clear | 清除 linestring, ring 或者 polygon (exterior+interiors) 和 multi* |
convert | 將一個(gè)幾何圖形轉(zhuǎn)換為另一個(gè)幾何圖元 |
convex_hull | 計(jì)算幾何體的凸包 |
correct | 糾正幾何圖形:所有相對(duì)于其預(yù)期方向錯(cuò)誤定向的環(huán)都將反轉(zhuǎn)。對(duì)于所有沒(méi)有閉點(diǎn)且按其應(yīng)有類型鍵入的環(huán),將附加第一個(gè)點(diǎn)。也可以校正框。 |
covered_by | 使用指定的策略檢查第一個(gè)幾何圖形是否位于第二個(gè)幾何圖形的內(nèi)部或邊界上 |
crosses | 檢查兩個(gè)幾何圖形是否相交 |
densify | 使用指定的策略加密幾何體 |
difference | 計(jì)算兩種幾何圖形的差異.通過(guò)差分計(jì)算兩種幾何的空間集合論差分 |
discrete_frechet_distance | 使用指定的策略計(jì)算兩個(gè)幾何圖形之間的離散Frechet距離(目前適用于LineString) |
discrete_hausdorff_distance | 使用指定的策略計(jì)算兩個(gè)幾何圖形之間的離散Hausdorff距離(目前適用于 LineString-LineString, MultiPoint-MultiPoint, Point-MultiPoint, MultiLineString-MultiLineString) |
disjoint | 檢查兩個(gè)幾何圖形是否不相交 |
equals | 檢查幾何體在空間上是否相等 |
expand | 使用長(zhǎng)方體來(lái)框選多個(gè)幾何圖形(長(zhǎng)方體、點(diǎn))的邊界框 |
intersection | 計(jì)算兩個(gè)幾何圖形的交點(diǎn) |
intersects | 檢查幾何圖形是否至少有一個(gè)交點(diǎn)(相交或自相切) |
is_empty | 檢查幾何圖形是否為空集 |
is_simple | 檢查幾何圖形是否簡(jiǎn)單 |
is_valid | 檢查幾何圖形是否有效(在OGC意義上) |
length | 函數(shù)長(zhǎng)度計(jì)算幾何體的長(zhǎng)度(連續(xù)點(diǎn)之間的距離之和)。它使用基于幾何體坐標(biāo)系的默認(rèn)策略。 |
line_interpolate | 返回沿LineString方向插值的一個(gè)或多個(gè)點(diǎn) |
make | 構(gòu)造幾何圖形 |
make_inverse | 用逆無(wú)窮坐標(biāo)構(gòu)造一個(gè)長(zhǎng)方體 |
make_zero | 構(gòu)造一個(gè)坐標(biāo)初始化為零的幾何體 |
num_geometries | 計(jì)算幾何圖形的幾何圖形數(shù) |
num_interior_rings | 計(jì)算幾何圖形的內(nèi)解多邊形數(shù) |
num_points | 計(jì)算幾何圖形的點(diǎn)數(shù) |
num_segments | 計(jì)算幾何圖形的線段數(shù)(segments) |
overlaps | 檢查兩個(gè)幾何圖形是否重疊 |
perimeter | 計(jì)算幾何圖形的周長(zhǎng) |
relate | 檢查由遮罩定義的一對(duì)幾何圖形之間的關(guān)系 |
relation | 計(jì)算DE-9IM中定義的一對(duì)幾何圖形之間的關(guān)系 |
reverse | 反轉(zhuǎn)幾何圖形中的點(diǎn) |
simplify | 簡(jiǎn)化幾何圖形 |
sym_difference | 計(jì)算兩種幾何體的對(duì)稱差 |
touches | 檢查幾何圖形是否至少有一個(gè)接觸點(diǎn)(自相切) |
transform | 使用策略從一個(gè)幾何圖形轉(zhuǎn)換到另一個(gè)幾何圖元 |
union_ | 組合兩個(gè)相互關(guān)聯(lián)的幾何圖形 |
unique | 計(jì)算幾何圖形的最小集 |
within | 檢查第一個(gè)幾何體是否完全位于第二個(gè)幾何體內(nèi)部 |
distance
comparable_distance
使用指定的策略計(jì)算兩個(gè)幾何圖形的可比距離測(cè)量值,點(diǎn)在多邊形內(nèi)部,可以使用comparable_distance
double cmpDst = boost::geometry::comparable_distance(segment,pt);
distance
使用指定的策略計(jì)算兩個(gè)幾何圖形之間的距離。distance可以正確處理多邊形外部的點(diǎn),但是似乎將多邊形視為實(shí)體。因此,多邊形內(nèi)的每個(gè)點(diǎn)到多邊形的距離顯然為0。
double cmpDst = boost::geometry::distance(segment,pt);
envelope
envelope
自由函數(shù)包絡(luò)計(jì)算幾何體的包絡(luò)(也稱為軸對(duì)齊邊界框、aabb或最小邊界矩形、mbr)
return_envelope
自由函數(shù)return_envelope計(jì)算幾何體的包絡(luò)(也稱為軸對(duì)齊邊界框、aabb或最小邊界矩形、mbr)。這個(gè)帶有return_前綴的版本返回信封,因此必須在調(diào)用中指定模板參數(shù)
點(diǎn)云處理
函數(shù) | 作用 |
---|
add_point | 將一個(gè)點(diǎn)添加到另一個(gè)點(diǎn) |
add_value | 將相同的值添加到點(diǎn)的每個(gè)坐標(biāo) |
assign_point | 用另一個(gè)點(diǎn)指定一個(gè)點(diǎn) |
assign_value | 為點(diǎn)的每個(gè)坐標(biāo)指定相同的值 |
cross_product | 計(jì)算兩個(gè)向量的叉積 |
divide_point | 將一點(diǎn)除以另一點(diǎn) |
divide_value | 將同一點(diǎn)的每個(gè)坐標(biāo)除以一個(gè)值 |
dot_product | 計(jì)算2個(gè)矢量(點(diǎn))的點(diǎn)積(或標(biāo)量積) |
multiply_point | 將一個(gè)點(diǎn)乘以另一個(gè)點(diǎn) |
multiply_value | 將點(diǎn)的每個(gè)坐標(biāo)乘以相同的值 |
subtract_point | 將一點(diǎn)減去另一點(diǎn) |
subtract_value | 將相同的值減去點(diǎn)的每個(gè)坐標(biāo) |
常數(shù)控制
函數(shù) | 作用 |
---|
min_corner | 指示要獲取、設(shè)置或處理的框的最小角 |
max_corner | 指示要獲取、設(shè)置或處理的框的最大角 |
坐標(biāo)系轉(zhuǎn)換
函數(shù) | 作用 |
---|
cs::cartesian | 笛卡爾坐標(biāo)系 |
cs::spherical | 球面(極坐標(biāo))坐標(biāo)系,以度或弧度表示 |
cs::spherical_equatorial | 球面赤道坐標(biāo)系,以度或弧度表示 |
cs::geographic | 地理坐標(biāo)系,以度或弧度表示 |
核心元函數(shù)
函數(shù) | 作用 |
---|
closure | 將值定義為指定幾何圖形類型的閉包(順時(shí)針、逆時(shí)針)的函數(shù) |
coordinate_system | 函數(shù)將類型定義為構(gòu)成指定幾何類型的點(diǎn)類型的坐標(biāo)系(笛卡爾坐標(biāo)系、球面坐標(biāo)系等) |
coordinate_type | 函數(shù)將類型定義為構(gòu)成指定幾何類型的點(diǎn)類型的坐標(biāo)類型(int、float、double等) |
cs_tag | 函數(shù)返回任意幾何體的坐標(biāo)系標(biāo)記(cs族) |
degree | 定義球面坐標(biāo)系的平面角單位的標(biāo)記。此標(biāo)記指定坐標(biāo)的定義單位為度(-180…180)。必須為某些坐標(biāo)系指定它 |
dimension | 將值定義為構(gòu)成指定幾何圖形類型的點(diǎn)類型的函數(shù) |
interior_type | 將類型定義為指定幾何類型的interior_ type(內(nèi)環(huán)的容器類型)的函數(shù) |
point_order | 將值定義為指定幾何圖形類型的點(diǎn)順序(順時(shí)針、逆時(shí)針)的函數(shù) |
point_type | 將類型定義為指定幾何體類型的point_ type的元函數(shù) |
radian | 平面角單位:弧度 |
ring_type | 將類型定義為指定幾何體類型的環(huán)_類型的函數(shù) |
tag | 將類型定義為指定幾何體類型的標(biāo)記的函數(shù) |
tag_cast | 標(biāo)記轉(zhuǎn)換,標(biāo)記可以相互繼承。例如,multi_ point繼承multi_。通常,行為可以在不同的幾何圖形類型之間共享。由metafunction標(biāo)記找到的標(biāo)記可以轉(zhuǎn)換為更基本的標(biāo)記,然后由該標(biāo)記分派 |
模型
函數(shù) | 作用 |
---|
model::point | 基點(diǎn)類,具有以中性方式定義的坐標(biāo) |
model::d2::point_xy | 笛卡爾坐標(biāo)系中的二維點(diǎn) |
model::d3::point_xyz | 笛卡爾坐標(biāo)系中的三維點(diǎn) |
model::linestring | linestring(由OGC命名)是點(diǎn)的集合(默認(rèn)為向量) |
model::polygon | 多邊形包含一個(gè)外圈和零個(gè)或多個(gè)內(nèi)圈 |
model::multi_point | multi_point,點(diǎn)的集合 |
model::multi_linestring | multi_line,linestring的集合 |
model::multi_polygon | multi_ polygon,多邊形的集合 |
model::box | 類框:定義由兩個(gè)描述點(diǎn)組成的框 |
model::ring | 環(huán)(也稱為線性環(huán))是一條不應(yīng)自相交的閉合線 |
model::segment | 在幾何學(xué)中,線段是由兩個(gè)不同端點(diǎn)限定的直線的一部分,包含其端點(diǎn)之間直線上的每個(gè)點(diǎn) |
model::referring_segment | 類段:包含兩個(gè)(模板化)點(diǎn)引用的小類 |
空間索引
boost::geometry::index::rtree
函數(shù) | 作用 |
---|
rtree() | rtree的構(gòu)造函數(shù) |
~rtree() | rtree的析構(gòu)函數(shù) |
operator=(rtree const &) | 賦值運(yùn)算符 |
swap(rtree &) | 交換兩個(gè)RTree的內(nèi)容 |
insert(value_type const &) | 在索引中插入一個(gè)值 |
remove(value_type const &) | 從容器中刪除值 |
query(Predicates const &, OutIter) | 此查詢函數(shù)執(zhí)行空間和k近鄰搜索。它允許傳遞一組數(shù)據(jù)。僅當(dāng)滿足所有數(shù)據(jù)時(shí)才會(huì)返回值 |
qbegin(Predicates const &) | 返回指向查詢范圍開頭的查詢迭代器 |
qend() | 返回一個(gè)指向查詢范圍末尾的查詢迭代器 |
begin() | 返回指向rtree值范圍開頭的迭代器 |
end() | 返回指向rtree值范圍末尾的迭代器 |
size() | 返回存儲(chǔ)值的數(shù)目 |
empty() | 查詢?nèi)萜魇欠駷榭?/td> |
clear() | 刪除存儲(chǔ)在容器中的所有值 |
bounds() | 返回能夠包含容器中存儲(chǔ)的所有值的框 |
count(ValueOrIndexable const &) | 對(duì)于indexable_type,它返回可索引的值的數(shù)目等于參數(shù)。對(duì)于value_type,它返回等于參數(shù)的值的數(shù)量 |
parameters() | 返回參數(shù) |
indexable_get() | 返回從值檢索可索引的函數(shù) |
value_eq() | 返回比較值的函數(shù) |
get_allocator() | 返回rtree使用的分配器 |
R-tree parameters (boost::geometry::index)
函數(shù) | 作用 |
---|
boost::geometry::index::linear | 線性r樹創(chuàng)建算法參數(shù) |
boost::geometry::index::quadratic | 二次r樹生成算法參數(shù) |
boost::geometry::index::rstar | R*-樹創(chuàng)建算法參數(shù) |
boost::geometry::index::dynamic_linear | 線性r樹創(chuàng)建算法參數(shù)-運(yùn)行時(shí)版本 |
boost::geometry::index::dynamic_quadratic | 二次r樹創(chuàng)建算法參數(shù)-運(yùn)行時(shí)版本 |
boost::geometry::index::dynamic_rstar | R*-樹創(chuàng)建算法參數(shù)-運(yùn)行時(shí)版本 |
其他函數(shù)
函數(shù) | 作用 |
---|
boost::geometry::index::indexable | 從值中提取可索引的函數(shù)對(duì)象,這個(gè)是override轉(zhuǎn)換 |
boost::geometry::index::equal_to | 函數(shù)對(duì)象比較值,這個(gè)是override轉(zhuǎn)換 |
inserter(Container &) | 插入迭代器生成器,這個(gè)是override轉(zhuǎn)換 |
queried(Predicates const &) | 查詢索引適配器生成器 |
Predicates (boost::geometry::index)
Predicates (boost::geometry::index) 下面的這些都是與前文同名函數(shù)相同的意思,只是是適用于RTree的函數(shù)
函數(shù) |
---|
contains(Geometry const &) |
covered_by(Geometry const &) |
covers(Geometry const &) |
disjoint(Geometry const &) |
intersects(Geometry const &) |
overlaps(Geometry const &) |
within(Geometry const &) |
satisfies(UnaryPredicate const &) |
nearest(Geometry const &, unsigned) |
Geometry策略方式
函數(shù) | 作用 |
---|
strategy::area::cartesian | 笛卡爾面積計(jì)算 |
strategy::area::spherical | 球面面積計(jì)算 |
strategy::area::geographic | 地理區(qū)域計(jì)算 |
strategy::buffer::join_round | 讓緩沖區(qū)創(chuàng)建圓角 |
strategy::buffer::join_miter | 讓緩沖區(qū)創(chuàng)建銳角 |
strategy::buffer::end_round | 讓緩沖區(qū)創(chuàng)建圓角端點(diǎn) |
strategy::buffer::end_flat | 讓緩沖區(qū)創(chuàng)建平端 |
strategy::buffer::distance_symmetric | 讓緩沖區(qū)算法創(chuàng)建具有相同距離的緩沖區(qū) |
strategy::buffer::distance_asymmetric | 讓緩沖區(qū)是不對(duì)稱 |
strategy::buffer::point_circle | 圍繞點(diǎn)創(chuàng)建圓形緩沖區(qū) |
strategy::buffer::point_square | 圍繞點(diǎn)創(chuàng)建方形緩沖區(qū) |
strategy::buffer::geographic_point_circle | 在地球上的一個(gè)點(diǎn)周圍創(chuàng)建一個(gè)圓形緩沖區(qū) |
strategy::buffer::side_straight | 讓緩沖區(qū)沿線段使用直邊(默認(rèn)) |
strategy::centroid::average | 質(zhì)心計(jì)算取點(diǎn)的平均值 |
strategy::centroid::bashein_detmer | 使用Bashein/Detmer算法計(jì)算質(zhì)心 |
strategy::convex_hull::graham_andrew | Graham掃描策略計(jì)算凸包 |
strategy::densify::cartesian | 笛卡爾線段的致密化 |
strategy::densify::geographic | 地理段的致密化,對(duì)應(yīng)了上文的densify方法 |
strategy::densify::spherical | 球形段的致密化,對(duì)應(yīng)了上文的densify方法 |
strategy::distance::pythagoras | 計(jì)算兩點(diǎn)之間距離的策略,對(duì)應(yīng)了上文的distance方法 |
strategy::distance::pythagoras_box_box | 計(jì)算兩個(gè)盒子之間距離的策略,對(duì)應(yīng)了上文的distance方法 |
strategy::distance::pythagoras_point_box | 計(jì)算點(diǎn)與長(zhǎng)方體之間距離的策略,對(duì)應(yīng)了上文的distance方法 |
strategy::distance::haversine | 使用哈弗斯線計(jì)算完美球體上球坐標(biāo)的距離 |
strategy::distance::projected_point | 點(diǎn)到線段的距離策略 |
strategy::distance::cross_track | 用于點(diǎn)到線段距離計(jì)算的策略函數(shù) |
strategy::distance::cross_track_point_box | 用于計(jì)算點(diǎn)到框的距離的策略函數(shù) |
strategy::line_interpolate::cartesian | 在笛卡爾線段上插值點(diǎn),對(duì)應(yīng)了上文的line_interpolate方法 |
strategy::line_interpolate::geographic | 插值地理線段上的點(diǎn),對(duì)應(yīng)了上文的line_interpolate方法 |
strategy::line_interpolate::spherical | 在球面段上插值點(diǎn),對(duì)應(yīng)了上文的line_interpolate方法 |
strategy::side::side_by_triangle | 檢查點(diǎn)位于線段的哪一側(cè):線段左側(cè)(>0),線段右側(cè)(<0),線段上(0) |
strategy::side::side_by_cross_track | 檢查大圓線段的哪一側(cè)有一個(gè)點(diǎn)位于線段左側(cè)(>0),線段右側(cè)(<0),線段(0) |
strategy::side::spherical_side_formula | 檢查大圓線段的哪一側(cè)有一個(gè)點(diǎn)位于線段左側(cè)(>0),線段右側(cè)(<0),線段(0)上 |
strategy::side::geographic | 檢查線段的哪一側(cè)有一個(gè)點(diǎn)位于線段左側(cè)(>0)、右側(cè)(<0)和線段(0)上 |
strategy::simplify::douglas_peucker | 實(shí)現(xiàn)簡(jiǎn)化算法 |
strategy::transform::inverse_transformer | 在笛卡爾坐標(biāo)系中進(jìn)行逆變換的變換策略 |
strategy::transform::map_transformer | 從一個(gè)笛卡爾坐標(biāo)系映射到另一個(gè)笛卡兒坐標(biāo)系的轉(zhuǎn)換策略 |
strategy::transform::rotate_transformer | 笛卡爾坐標(biāo)系中的旋轉(zhuǎn)變換策略 |
strategy::transform::scale_transformer | 笛卡爾系統(tǒng)中的尺度變換策略 |
strategy::transform::translate_transformer | 笛卡爾系統(tǒng)中的平移變換策略 |
strategy::transform::matrix_transformer | 笛卡爾系統(tǒng)中的仿射變換策略 |
strategy::within::winding | 在使用纏繞規(guī)則的檢測(cè)范圍內(nèi)。根據(jù)點(diǎn)的坐標(biāo)系選擇內(nèi)部使用的邊策略。 |
strategy::within::franklin | 在使用交叉計(jì)數(shù)的檢測(cè)范圍內(nèi) |
strategy::within::crossings_multiply | 在使用交叉計(jì)數(shù)的檢測(cè)范圍內(nèi) |
示例
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/foreach.hpp>
#include <boost/assign/list_of.hpp>
namespace bg = boost::geometry;
typedef bg::model::d2::point_xy<double> Point;
typedef bg::model::segment<Point> Segment;
typedef bg::model::linestring<Point> LineString;
typedef bg::model::box<Point> Box;
typedef bg::model::ring<Point, false> Ring;
typedef bg::model::polygon<Point, false> Polygon;int main()
{Point pt0(100, 100);Point pt1(200, 200);Segment sg0(pt0, pt1);double Distance = 0;Distance = bg::distance(pt0, pt1); Distance = bg::distance(Point(200, 100), sg0); Distance = bg::distance(Point(100, 0), sg0); Segment sg1(Point(0, 100), Point(100, 0));Segment sg2(Point(100, 200), Point(200, 100));bool bIntersect = false;bIntersect = bg::intersects(sg0, sg1); bIntersect = bg::intersects(sg0, sg2); std::list<Point> lstPoints;bg::intersection(sg0, sg1, lstPoints);lstPoints.clear();bg::intersection(sg0, sg2, lstPoints); Box rc(Point(0, 0), Point(200, 200));Box rc0(Point(250, 250), Point(450, 450));Box rc1(Point(100, 100), Point(300, 300));bIntersect = bg::intersects(rc, rc0); bIntersect = bg::intersects(rc, rc1); LineString line0;line0.push_back(Point(10, 250));line0.push_back(Point(100, 100));line0.push_back(Point(120, -10));line0.push_back(Point(210, 200));bIntersect = bg::intersects(rc, line0); bIntersect = bg::intersects(rc0, line0); std::list<LineString> lstLines;bg::intersection(rc, line0, lstLines); Box rc7(Point(0, 0), Point(100, 100));bool bInside = false;bInside = bg::within(Point(50, 50), rc7); bInside = bg::within(Point(0, 0), rc7); LineString line1, line2, line3;line1.push_back(Point(50, 50));line1.push_back(Point(150, 50));line1.push_back(Point(50, 200));line1.push_back(Point(150, 200));line2.push_back(Point(100, 0));line2.push_back(Point(70, 100));line2.push_back(Point(150, 210));line3.push_back(Point(200, 0));line3.push_back(Point(200, 200));bIntersect = bg::intersects(line1, line2); bIntersect = bg::intersects(line1, line3); lstPoints.clear();bg::intersection(line1, line2, lstPoints); lstPoints.clear();bg::intersection(line1, line3, lstPoints);Point arDPoint0[6] = {Point(0, 0), Point(100, 0), Point(200, 100), Point(100, 200), Point(0, 200), Point(0, 0)};Point arDPoint1[6] = {Point(100, 100), Point(200, 0), Point(300, 0), Point(300, 200), Point(200, 200), Point(100, 100)};Ring r0(arDPoint0, arDPoint0 + 6);Ring r1(arDPoint1, arDPoint1 + 6);bIntersect = bg::intersects(r0, r1); lstPoints.clear();bg::intersection(r0, r1, lstPoints); Polygon poly1;Polygon poly2;Polygon poly3;auto lstOf = boost::assign::list_of(Point(0, 0))(Point(200, 0))(Point(200, 200))(Point(0, 200))(Point(0, 0));poly1.outer().assign(lstOf.begin(), lstOf.end());lstOf = boost::assign::list_of(Point(50, 50))(Point(150, 50))(Point(150, 150))(Point(50, 150))(Point(50, 50));poly1.inners().push_back(lstOf);lstOf = boost::assign::list_of(Point(100, 0))(Point(120, 0))(Point(120, 200))(Point(100, 200))(Point(100, 0));poly2.outer().assign(lstOf.begin(), lstOf.end());lstOf = boost::assign::list_of(Point(100, 60))(Point(120, 60))(Point(120, 140))(Point(100, 140))(Point(100, 60));poly3.outer().assign(lstOf.begin(), lstOf.end());bIntersect = bg::intersects(poly1, poly2); bIntersect = bg::intersects(poly1, poly3); std::list<Polygon> lstPolygon;bg::intersection(poly1, poly2, lstPolygon);lstPolygon.clear();bg::intersection(poly1, poly3, lstPolygon);bInside = bg::within(Point(100, 100), poly1); bInside = bg::within(Point(25, 25), poly1); return 0;
}
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/foreach.hpp>
#include <boost/assign/list_of.hpp>int main()
{typedef boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > polygon;polygon green, blue;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))", green);boost::geometry::read_wkt("POLYGON((4.0 -0.5 , 3.5 1.0 , 2.0 1.5 , 3.5 2.0 , 4.0 3.5 , 4.5 2.0 , 6.0 1.5 , 4.5 1.0 , 4.0 -0.5))", blue);std::deque<polygon> output;boost::geometry::intersection(green, blue, output);int i = 0;std::cout << "green && blue:" << std::endl;BOOST_FOREACH(polygon const& p, output){std::cout << i++ << ": " << boost::geometry::area(p) << std::endl; }return 0;
}