boostorg / boostorg/geometry

Haversine distance does not always multiply by radius

オープン
#484 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
C++
スター
517
フォーク
232
PR マージ指標
30日以内にマージされた PR はありません

説明

Hello,
I might have found an issue in the point to polygon distance calculation.

Given this code:

```
#include
#include
#include
#include
#include

using coordinate_system = boost::geometry::cs::spherical_equatorial;
using lonlat = boost::geometry::model::point;
using polygon = boost::geometry::model::polygon;
using multi_polygon = boost::geometry::model::multi_polygon;
static const constexpr double mean_radius = 6371.0 * 1000;
static const auto Haversine = [] {
return boost::geometry::strategy::distance::haversine(
mean_radius);
};

int main()
{
std::string c = "POINT(2.37314 48.854)";
std::string p = "MULTIPOLYGON(((2.37198 48.8539, 2.37214 48.8539, 2.3721 48.854, 2.37198 48.854, 2.37198 48.8539)))";

lonlat center;
multi_polygon poly;
boost::geometry::read_wkt(c, center);
boost::geometry::read_wkt(p, poly);

{
int i = 0;
for (auto p : poly[0].outer())
{
auto distance = boost::geometry::distance(center, p, Haversine());
std::cout << "Haversine distance center<>polygons[0][" << i++ << "]: " << distance << std::endl;
}
}

{
auto distance = boost::geometry::distance(center, poly, Haversine());
std::cout << "Haversine distance center<>polygons: " << distance << std::endl;
std::cout << "Haversine distance center<>polygons * radius: " << distance*mean_radius << std::endl;
}
}
```

The output with boost 1.67 is:

```
Haversine distance center<>polygons[0][0]: 85.5957
Haversine distance center<>polygons[0][1]: 74.0043
Haversine distance center<>polygons[0][2]: 76.0906
Haversine distance center<>polygons[0][3]: 84.8703
Haversine distance center<>polygons[0][4]: 85.5957
Haversine distance center<>polygons: 1.16158e-05
Haversine distance center<>polygons * radius: 74.0043
```

As one can see, the distance returned does not seem to be multiplied by the given radius.

~This leads to another question, it is not clear in the documentation that the distance between a point and a polygon is the distance between the point and the closest point of the polygon.~

Cheers :)

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。