简体   繁体   English

带有Boost Geometry的地理坐标没有交集区域

[英]No Intersection Area for geographic coordinates with Boost Geometry

I need to check whether two points (GPS coordinates) q , m are in the same side or on the opposite side or co linear to a line (great circle segment) (p,t) . 我需要检查两个点(GPS坐标) qm是否在同一侧或相反侧或与线(大圆弧段) (p,t) I know that q is not co linear to (p, t) . 我知道q(p, t)不成线性关系。 I didn't find and any direct function to use in the boost.geometry library. 我没有发现在boost.geometry库中使用任何直接函数。 So I tried to calculate it in a different way. 因此,我尝试以不同的方式进行计算。

I construct two triangles (p, q, t) and (p, m, t) . 我构造了两个三角形(p, q, t)(p, m, t) Then I intersect these two and check the area of the intersection polygon. 然后,我将这两个相交并检查相交多边形的面积。 Following is my code. 以下是我的代码。

typedef boost::geometry::model::point<
    double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree>
> geo_point;
typedef boost::geometry::model::polygon<geo_point> geo_polygon;

geo_point p(110.48316, 29.05043);
geo_point q(110.48416, 29.05104);
geo_point t(110.48416, 29.05228);
geo_point m(110.48408, 29.05079);

geo_polygon ut, es;

boost::geometry::append(ut.outer(), p);
boost::geometry::append(ut.outer(), q);
boost::geometry::append(ut.outer(), t);
boost::geometry::append(ut.outer(), p);

boost::geometry::append(es.outer(), p);
boost::geometry::append(es.outer(), m);
boost::geometry::append(es.outer(), t);
boost::geometry::append(es.outer(), p);

std::list<geo_point> intersection_points;
boost::geometry::intersection(ut, es, intersection_points);
std::cout << intersection_points.size() << std::endl;

std::vector<geo_polygon> intersection_polygons;
boost::geometry::intersection(ut, es, intersection_polygons);
std::cout << intersection_polygons.size() << std::endl;

Live at cpp.sh 住在cpp.sh

If we plot these two triangles we can clearly see that they intersects on 3 vertices yielding another triangle in the intersected region. 如果我们绘制这两个三角形,我们可以清楚地看到它们在3个顶点上相交,从而在相交区域产生了另一个三角形。

在此处输入图片说明

The above code correctly returns the number of intersected points, but it doesn't return any intersection polygon. 上面的代码正确返回相交点的数量,但不返回任何相交多边形。

3
0

I have tried using geographic instead of using spherical_equatorial coordinate system. 我尝试使用geographic而不是spherical_equatorial坐标系。 But got the same results. 但是得到了相同的结果。 Am I missing something ? 我想念什么吗? or this is a problem in Boost.Geometry 或者这是Boost.Geometry的问题

To ensure that polygons are closed and oriented as needed, apply correct . 为确保根据需要关闭多边形并确定其方向,请应用正确的 Inserting 插入

boost::geometry::correct(ut);
boost::geometry::correct(es);

gives result 1 polygon for your test 测试提供结果1多边形

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM