我有这样的代码
namespace bg = boost::geometry;
typedef typename std::conditional<highDimension,
typename bg::model::point<double, 6, bg::cs::cartesian>,
typename bg::model::point<double, 5, bg::cs::cartesian>>::type point;
..........
point p;
p.set<0>(0);
p.set<1>(0);
p.set<2>(0);
..........
Run Code Online (Sandbox Code Playgroud)
GCC向我展示了很多错误,例如"错误:类型'的无效操作数'和'int'到二进制'运算符<'p.set <1>(col.a());" 所以它只是试图'比较' p.set和1
boost类实际上有模板函数集,但编译器不使用它作为函数.
如果我直接从boost类型生成typedef,就像typedef bg::model::point<double, 5, bg::cs::cartesian> point;一切正常.
我只想根据模板参数选择不同的尺寸大小highDimension.但现在我不知道如何强迫GCC了解我:)
我想要一个std::vector地理区域的几何形状.其中一些区域是连续的,并由多边形表示.有些区域是不连续的,由多边形表示.我的计划是使用a std::vector<boost::variant<polygon,multipolygon>>来处理这种差异.
双方polygon并multipolygon履行几何概念,所以我们应该能够呼吁任何一个信封.这一工程,但我似乎无法调用envelope上variant<polygon,multipolygon>.
#include <vector>
#include <boost/variant.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp>
namespace bg = boost::geometry;
typedef bg::model::point<double, 2, bg::cs::cartesian> point;
typedef bg::model::box<point> box;
typedef bg::model::polygon<point, true, true> polygon; //cw, closed polygon
typedef bg::model::multi_polygon<polygon> multipolygon;
typedef boost::variant<polygon,multipolygon> star_polygon;
int main(void){
polygon staunton_county;
bg::read_wkt("POLYGON ((-79.091666 38.132142, -79.09711 38.184771,"
" -79.02301 38.195777, -79.049779 38.121112, -79.091666 38.132142))",
staunton_county);
multipolygon dickson_county;
bg::read_wkt("MULTIPOLYGON (((-87.151995 36.289037, -87.146906 36.293344,"
" -87.144172 …Run Code Online (Sandbox Code Playgroud) 我似乎找不到一种有效的方法来迭代一个boost R-tree(boost::geometry::index::rtree).到目前为止,我提出的唯一方法是使用非常大的边界框执行查询,以便在向量中返回所有元素的副本,但这显然既不节省空间也不节省时间.理想情况下,我只是想使用STL样式的迭代器以通常的方式迭代树,但这似乎不可能?
我想使用带有直线和多边形的boost几何的交点函数.我希望交叉点是多边形内部线条的一部分.
不幸的是,boost几何体返回位于多边形外部的线条部分.这是boost几何中的错误还是我的代码有问题?
#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/ring.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/segment.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/multi/geometries/multi_point.hpp>
#include <boost/geometry/multi/geometries/multi_linestring.hpp>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/algorithms/intersection.hpp>
namespace bg = boost::geometry;
using value_type = double ;
using cs_type = bg::cs::cartesian;
using point_type = bg::model::point< value_type , 2 , cs_type >;
using polygon_type = bg::model::ring< point_type > ;
using line_string_type = bg::model::linestring< point_type >;
using multi_line_type = bg::model::multi_linestring< line_string_type >;
int main( int argc , char *argv[] )
{
line_string_type line;
line.push_back( point_type { …Run Code Online (Sandbox Code Playgroud) Boost rtree为段查询的某些交集提供了错误的交集结果.在这种情况下,边界框是y = 0时的y平面10×10平方.我正在查询从(2,1,0)到(2,1,10)的z对齐线.有趣的是,如果我使用一个框进行查询而不是一个段,那么它会按预期工作.当框不是平面时,也会出现此行为,只需将最小角移动到(0,-5,0),它仍然会发生.
我使用这个错误还是增强中的错误?
编辑:在Boost 1.56和1.59上试过这个.
#include <vector>
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/segment.hpp>
#include <boost/geometry/index/rtree.hpp>
#include <vector>
#include <iterator>
#include <memory>
namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;
typedef bg::model::point<double, 3, bg::cs::cartesian> point_def;
typedef bg::model::box<point_def> box;
typedef bg::model::segment<point_def> segment;
typedef std::pair<box, size_t> tri_box;
typedef bgi::rtree< tri_box, bgi::linear<8>> tree_type;
using namespace std;
TEST(boost_rtree, cant_intersect_box_with_segment) {
vector<tri_box> buff(1);
buff[0].first = box{point_def{0, 0, 0}, point_def{10, 0, 10}};
buff[0].second = 1;
tree_type tree(buff);
segment query{point_def{2, …Run Code Online (Sandbox Code Playgroud) 我想获得从点(t)到线段的垂直距离(p, q)。垂线不能与线相交[p, q]。在这种情况下,我想(p, q)假设地延长线,然后绘制垂直线以获得距离。p、q、t 都是 gps 坐标。我正在使用增强几何。
typedef boost::geometry::model::point<
double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree>
> geo_point;
typedef boost::geometry::model::segment<geo_point> geo_segment;
geo_point p(88.41253929999999, 22.560206299999997);
geo_point q(88.36928063300775, 22.620867969497795);
geo_point t(88.29580956367181, 22.71558662052875);
Run Code Online (Sandbox Code Playgroud)
我在地图上标出了这三个位置

我衡量两个距离qt从和距离t来pq
double dist_qt = boost::geometry::distance(q, t);
std::cout << dist_qt*earth_radius << std::endl;
geo_segment line(p, q);
double perp_dist = boost::geometry::distance(t, line);
std::cout << perp_dist*earth_radius << std::endl;
Run Code Online (Sandbox Code Playgroud)
这两个距离是相同的。这意味着它不计算垂直距离。相反,它计算了shortest从一个点到一条线的距离bounds。
如何以这种方式计算垂直距离,使其无论边界如何都必须垂直?
cpp.sh 中的工作示例
我只是写了一个简单的例子,由 boost ( http://www.boost.org/doc/libs/1_52_0/libs/geometry/doc/html/geometry/quickstart.html ) 给出。编译过程中出现一些错误。我使用 eclipse 和 Mingw 来编译它。有人能告诉我有什么问题吗?
测试代码如下:
#include <iostream>
using namespace std;
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/algorithms/distance.hpp>
using namespace boost::geometry;
int main() {
cout << "!!!Hello World!!!" << endl;
model::d2::point_xy<int> p1(1, 1), p2(2, 2);
cout << "Distance p1-p2 is: " << distance(p1, p2) << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
错误如下:
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-
mingw32/4.7.1/include/c++/bits/stl_iterator_base_funcs.h:114:5:
required by substitution of 'template<class _InputIterator>
typename std::iterator_traits::difference_type
std::distance(_InputIterator, _InputIterator) [with _InputIterator
= boost::geometry::model::d2::point_xy<int>]'
..\src\test.cpp:22:50: required from here
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-
mingw32/4.7.1/include/c++/bits/stl_iterator_base_types.h:166:53: …Run Code Online (Sandbox Code Playgroud) 我发现,我失去了不漂亮<as>和<wrap>命令,RCPP及其相关软件包提供了对不同对象类型之间的转换.
我有一个点矩阵,行代表二维笛卡尔空间中的点:
pointsMatrix <- matrix(runif(100,-1,1),50,50)
Run Code Online (Sandbox Code Playgroud)
然后我想使用boost几何中的convex_hull算法来找到点的凸包.
但是,我不确定如何将其转换NumericMatrix为convex_hull理解的数据类型之一.此外,我不确定如何将Boost Geometry的输出转换回Rcpp可以交回R的内容.
#include <Rcpp.h>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
using namespace Rcpp;
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
// [[Rcpp::export]]
NumericMatrix convexHullRcpp(NumericMatrix pointsMatrix){
typedef boost::tuple<double, double> point;
typedef boost::geometry::model::polygon<point> polygon;
// Some sort of conversion of pointsMatrix here to pointsMatrixBG//
polygon hull;
boost::geometry::convex_hull(pointsMatrixBG, hull);
//Now to convert hull into something that Rcpp can hand back to R.//
return hullToR;
}
Run Code Online (Sandbox Code Playgroud)
看起来boost.tuple可能是最好的选择
我一直在使用Boost几何体,主要用于操纵多边形; 我使用质心内置方法(http://www.boost.org/doc/libs/1_55_0/libs/geometry/doc/html/geometry/reference/algorithms/centroid/centroid_2.html)来计算几何(bary)我的多边形的中心,但最近输出了我的点的坐标(组成一个特定的多边形)(并用一些Python脚本分析它们)我意识到前一个方法的质心坐标给了我不对应到多边形点的几何平均数.
我是两个维度并把它放入方程式,我应该:
x_centroid = \frac{1}{number of points composing the polygon} \sum{point i} x_i
Run Code Online (Sandbox Code Playgroud)
和y坐标相同.我现在怀疑这可能与升力几何库不只是看多边形边缘上的点(它的外环),而是将其视为填充对象这一事实有关.
你们中的任何人都有操纵这些功能的经验吗?
顺便说一下,我使用:
point my_center(0,0);
bg::centroid(my_polygon,my_center);
Run Code Online (Sandbox Code Playgroud)
计算质心.
谢谢.
我正在尝试使用提升几何,并且无法将点分配给多边形.让我们假设我创建了一个静态的点向量
boost::geometry::model::d2::point_xy<double> >* a;
Run Code Online (Sandbox Code Playgroud)
然后我创建一个多边形:
boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > polygon;
Run Code Online (Sandbox Code Playgroud)
假设我已经定义了a的点的值.
如何将点从a分配到P?