从Boost几何多边形获取点的坐标 [英] Getting the coordinates of points from a Boost Geometry polygon

查看:573
本文介绍了从Boost几何多边形获取点的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的DLL使用Boost几何多边形进行一些计算。 (主要是交集和差异)由于DLL很可能从C#代码调用,而从Delphi和谁知道从哪里,我应该将结果转换为数组,一切都可以处理。

I have a simple DLL doing some calculations with Boost Geometry polygons. (Mostly intersections and differences.) Since the DLL will be most likely called from C# code, and from Delphi and who knows from where else, I should convert the result into arrays that everything can handle.

UPDATE:
我已经简化并稍微纠正了我的代码。新代码看起来完全不同,使用完全不同的方法( for_each_point ),并且仍然无法编译。

UPDATE: I had simplified and somewhat corrected my code. The new code looks completely different, uses a completely different approach (for_each_point), and somehow still doesn't compile.

我的新代码:

#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) {
        resultX = x;
        resultY = y;
    }
};

void VectorToArray(std::vector<model::polygon<spherical_point>> resultVector, double x[], double y[], int *count) {
    int i = 0;      
    for (std::vector<model::polygon<spherical_point>>::iterator it = resultVector.begin(); it != resultVector.end(); ++it) {
        if (boost::size(*it) >= 2) {
            *count = boost::size(*it);
            PointAggregator* pa = new PointAggregator(*count);
            boost::geometry::for_each_point(*it, *pa);
            pa->GetResult(x, y);
            delete(pa);
            break;
        }       
    }
}

当前编译错误是:


  1. 错误C2039:'type':不是'boost :: mpl :: eval_if_c'iterator.hpp 63的成员

  2. 错误C3203:'type':非特定类模板不能用作模板参数'Iterator'的模板参数,期望为真实类型difference_type.hpp 25

  3. 错误C2955:'boost :: type':使用类模板需要模板参数列表difference_type.hpp 25

  4. 错误C2955:'boost :: iterator_difference':使用类模板需要模板参数列表difference_type.hpp 26

  1. error C2039: 'type' : is not a member of 'boost::mpl::eval_if_c' iterator.hpp 63
  2. error C3203: 'type' : unspecialized class template can't be used as a template argument for template parameter 'Iterator', expected a real type difference_type.hpp 25
  3. error C2955: 'boost::type' : use of class template requires template argument list difference_type.hpp 25
  4. error C2955: 'boost::iterator_difference' : use of class template requires template argument list difference_type.hpp 26

哪些不像这部分代码有什么关系filename是geometry.cpp),但是使用Boost Geometry的所有东西都被注释掉了,我仍然得到这些错误,所以...

Which ones don't look like they have anything to do with this part of code (my filename is geometry.cpp), but everything else that uses Boost Geometry is commented out and I still get these errors, so...

这是我以前的错误代码(由sehe编辑)

m新到C + +和Boost,所以我可能错过了一些基本的概念,而把代码从互联网在一起。)
我假设我可以只是不能迭代通过一个多边形,我错过了不平凡的部分,一个多边形不能用作一个环,或者迭代只是不是我认为他们是,或者我不知道还有什么可能是错的。

(I'm new to C++ and Boost so I might have missed some basic concept while putting code from the internet together.) I assume that I can just not iterate through a polygon that easily and I missed the non-trivial part, or that a polygon can not be used as a ring, or iterations are just not the way I thought they are, or I have no idea what else can be wrong. What did I do wrong?

推荐答案

我找到了一些需要修正的问题:

I found a few things that needed to be fixed:


  1. 我看到的一个问题是在您的模板中。

  2. boost范围适用于包含开始,结束对的容器或范围

  3. 迭代器表示类似指向对象的指针。获取迭代器的大小不会做你想要的。您需要使用整个容器的boost :: size,或者使用std :: distance(begin_iterator,end_iterator)。

编译的版本:

#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) {
        resultX = x;
        resultY = y;
    }
};

// added spaces to the close brackets >> becomes > >
void VectorToArray(std::vector<model::polygon<spherical_point> > resultVector, double x[], double y[], int *count) {
    for (std::vector<model::polygon<spherical_point> >::iterator it = resultVector.begin(); it != resultVector.end(); ++it) {
        if (boost::size(resultVector) >= 2) {
            // getting the size of the whole container
            *count = boost::size(resultVector);
            PointAggregator* pa = new PointAggregator(*count);
            boost::geometry::for_each_point(*it, *pa);
            pa->GetResult(x, y);
            delete(pa);
            break;
        }       
    }
}

这篇关于从Boost几何多边形获取点的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆