我最近被一家GIS公司雇用来重写旧的地理信息库.所以我目前正在寻找一个好的计算几何库.我见过CGAL,这太棒了,但我的老板想要一些免费的东西.
所以我现在正在检查Boost.Geometry.这个库看起来很棒,但它似乎也在快速变化.很多事情还没有实现,邮件列表上讨论了很多问题.
因此我的问题是:Boost.Geometry足够成熟,所以我可以在它上面构建一些东西吗?或者设计仍在发展?
谢谢
我正在使用boost :: geometry 的Rtree实现来存储(大量)2D点.现在我需要做距离最近的neigbors查询.
但是,本手册仅将查询描述为矩形框(即"获取此矩形内的所有点")或"KNN"查询("从此处获取最近的'n'点).
我想要的实际上是"让我得到距离小于'n'的点集."
我注意到你可以定义一元谓词,但是是......一元(因此,不适合两点的条件).
手册记录了model::ring我认为最初可能适合圆形的一些类,但它实际上更像是一种分段线(多边形).这个假设是否正确?
有没有其他方法来处理这样的查询?或者它根本不可能?
所以我想在multi_polygon中加入所有相互关联的poligons.怎么办这样的事情?
我们想要优化这样的图像(一个绿色multi_polygon)(我们可以看到黄色虚线 - 显然是在multi_polygon的每个poligon上执行的简化结果,而不是在multi_polygon上)

这里有可编译的代码来生成这样的图像:
#include <iostream>
#include <fstream>
#include <boost/assign.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp>
#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
template <typename Geometry1, typename Geometry2>
void create_svg(std::string const& filename, Geometry1 const& a, Geometry2 const& b)
{
typedef typename boost::geometry::point_type<Geometry1>::type point_type;
std::ofstream svg(filename.c_str());
boost::geometry::svg_mapper<point_type> mapper(svg, 400, 400);
mapper.add(a);
mapper.add(b);
mapper.map(a, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2");
mapper.map(b, "opacity:0.8;fill:none;stroke:rgb(255,128,0);stroke-width:4;stroke-dasharray:1,7;stroke-linecap:round");
}
boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > make_point(int x, int y)
{
boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > return_item;
boost::geometry::model::d2::point_xy<double> p1(x, y);
boost::geometry::model::d2::point_xy<double> p2(x-1, y);
boost::geometry::model::d2::point_xy<double> p3(x-1, y-1);
boost::geometry::model::d2::point_xy<double> p4(x, y-1);
boost::geometry::append( return_item, p1);
boost::geometry::append( …Run Code Online (Sandbox Code Playgroud) 我有一个简单的DLL用Boost Geometry多边形做一些计算.(主要是交叉点和差异.)因为DLL很可能是从C#代码调用的,而且是从Delphi调用的,我应该将结果转换为所有可以处理的数组.
更新:
我已经简化并稍微纠正了我的代码.新代码看起来完全不同,使用完全不同的方法(for_each_point),并且仍然不能编译.
我的新代码:
#include <vector>
#include <boost/range.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
using namespace boost::geometry;
typedef boost::geometry::model::point
<
double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree>
> spherical_point;
class PointAggregator {
private :
double *x, *y;
int count;
public :
PointAggregator(int size) {
x = (double*) malloc(sizeof(double) * size);
y = (double*) malloc(sizeof(double) * size);
count = 0;
}
~PointAggregator() {
free(x);
free(y);
}
inline void operator()(spherical_point& p) {
x[count] = get<0>(p);
y[count] = get<1>(p);
count++;
}
void GetResult(double *resultX, double *resultY) …Run Code Online (Sandbox Code Playgroud) 我正在尝试编译以下代码:
#include <boost/geometry/geometries/point_xy.hpp>
#include <iostream>
#include <utility>
typedef boost::geometry::model::d2::point_xy<long> Point;
typedef std::pair<Point, Point> Vector;
bool operator==(const Point& p1, const Point& p2) {
return p1.x() == p2.x() && p1.y() == p2.y();
}
int main() {
Vector vec1(Point(0,0), Point(1,1));
Vector vec2(Point(0,0), Point(1,2));
std::cout << ((vec1 == vec2) == false) << std::endl;
std::cout << ((vec1 == vec1) == true) << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
VS2012 C++编译器返回以下编译错误:
... VC\include\utility(219):错误C2678:二进制'==':找不到哪个运算符带有'const Point'类型的左手操作数(或者没有可接受的转换)
GCC C++编译器返回以下编译错误:
/usr/include/c++/4.8/bits/stl_pair.h:
在实例化'bool std :: operator ==(const std :: pair <_T1,_T2>&,const std :: pair <_T1,_T2>&)[with …
我有两个变形金刚,翻译和轮换如下:
namespace bg = boost::geometry;
namespace trans = bg::strategy::transform;
trans::translate_transformer<point, point> translate(px, py);
trans::rotate_transformer<point, point, bg::radian> rotate(rz);
Run Code Online (Sandbox Code Playgroud)
如何将它们合并为一个,这样我bg::transform每次都不必调用两次并使用中间变量?
Boost中有很好的几何图形库.它还允许绘制SVG图像.我想在我的某个项目中使用它,但它对我来说真的很奇怪(见下图).
所以我们在2d空间中有3个像素点表示为方形poligons
1 1
0 1
Run Code Online (Sandbox Code Playgroud)
pic 1
我们希望从他们那里得到一个联合并简化它,这样当我们缩放它时,我们会得到一个三角形
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
0 1 1 1 1 1
0 0 1 1 1 1
0 0 0 1 1 1
Run Code Online (Sandbox Code Playgroud)
pic 2
但是我们得到了这个:

黄色虚线是联合,绿色是简化.
源代码:
#include <iostream>
#include <fstream>
#include <boost/assign.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp>
#include <boost/geometry/algorithms/envelope.hpp>
#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
template <typename Geometry1, typename Geometry2>
void create_svg(std::string const& filename, Geometry1 const& a, …Run Code Online (Sandbox Code Playgroud) 如何将boost :: geometry多边形转换为STL对象?
我确信这一定很简单,因为我无法在文档中找到任何示例.然而,我花了大约4个工作日试图做这件小事.我是C++的新手(长时间的R程序员),但这些小数据转换事件让我疯狂.
是的,有一个问题的标题与我的很相似:从Boost Geometry多边形获取点的坐标
但代码是如此复杂(海报不断改变它),我无法做出正面或反面,我也无法想象其他C++新手能够做到的.
这是一个简单的例子,应该转换为其他一些boost :: geometry数据类型,所以希望任何人都可以遵循它.
#include <iostream>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
//One thing I tried is a function to use with `for_each_point()` so I set that up first.
template <typename Point>
void get_coordinates(Point const& p)
{
using boost::geometry::get;
std::cout << get<0>(p) get<1>(p) << std::endl;
}
int main()
{
typedef boost::tuple<double, double> point;
typedef boost::geometry::model::polygon<point> polygon;
polygon poly;
boost::geometry::read_wkt("polygon((2.0 1.3, 2.4 1.7, 2.8 1.8, 3.4 1.2, 3.7 1.6, 3.4 2.0, 4.1 3.0, …Run Code Online (Sandbox Code Playgroud)
我必须联合许多boost :: polgons,但我的方法似乎不是很高效(> 15分钟),特别是对于更多数量的多边形(> 2000).
我将所有要联合的多边形推入多面,然后加入多面,
请参阅我的代码:
BOOST_FOREACH(polygon, multipolygon)
{
boost::geometry::clear(tmp_union); //tmp_union is a multipolygon
boost::geometry::union_(result, poly, tmp_union);
result = tmp_union;
}
Run Code Online (Sandbox Code Playgroud)
结果可能不包含很多多边形,因为要连接的大多数多边形将相交.
有没有办法让这个更高效,比如按特定顺序排序多边形或完全不同的方法?
谢谢
我做了一些简单的笛卡尔点对点测试:
rtree.qbegin(bgi::nearest(Point(4, 4), 2))
Run Code Online (Sandbox Code Playgroud)
它们按照Boost 1.61排序.
现在我想要一份文件或来源报价来确认.
如果没有,我将自己对查询输出进行排序.