【问题标题】:Check the a Point (Latitude, Longitude) inside Or Outside the Polygon检查多边形内部或外部的一个点(纬度,经度)
【发布时间】:2013-09-18 10:45:33
【问题描述】:

让我们考虑一个具有 N 个点的多边形 (P),每个点用纬度和经度表示。现在我想检查一个新点 P1(纬度和经度)是否在多边形内部/外部?

【问题讨论】:

标签: latitude-longitude


【解决方案1】:

多边形内的点测试是一种通用算法,在许多地理空间库中以不同的编程语言实现。

JTS Topology Suite,例如,是 Java 中二维空间谓词和函数的强大开源 API。它提供了测试几何体(例如点)是否包含在另一个几何体(例如多边形)中的方法。

这是一个代码sn-p:

doube lat = ....; // latitude in decimal degrees
double lon = ...; // longitude in decimal degrees
Coordinate[] points = ... // construct/initialize points for polygon

// now construct the polygon and test the point
GeometryFactory gf = new GeometryFactory();
LinearRing jtsRing = gf.createLinearRing(points);
Polygon poly = gf.createPolygon(jtsRing, null);
Coordinate coord = new Coordinate(lon, lat);
Point pt = gf.createPoint(coord);
if (poly.contains(pt)) {
  // point is contained within polygon
} else {
  // point is NOT contained within polygon
}

contains() 几何谓词在JTS javadoc 中定义。

另见JTS project on github

【讨论】:

    猜你喜欢
    • 2014-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-08
    • 1970-01-01
    • 1970-01-01
    • 2018-08-27
    • 2018-12-20
    相关资源
    最近更新 更多