检查传单中的多边形点是否位于另一个多边形点内部

2023-11-22

我从传单 geoJSON 地图中选择了两组多边形坐标。 父坐标和子坐标分别是:

var parentCoordinates=[
    [
        32.05898221582174,
        -28.31004731142091
    ],
    [
        32.05898221582174,
        -28.308044824292978
    ],
    [
        32.06134255975485,
        -28.308044824292978
    ],
    [
        32.06134255975485,
        -28.31004731142091
    ],
    [
        32.05898221582174,
        -28.31004731142091
    ]
]
var childCoordinates=[
  [
    32.059904895722866,
    -28.30970726909422
  ],
  [
    32.059904895722866,
    -28.308743809931784
  ],
  [
    32.06089194864035,
    -28.308743809931784
  ],
  [
    32.06089194864035,
    -28.30970726909422
  ],
  [
    32.059904895722866,
    -28.30970726909422
  ]
]

The child is drawn inside the parent area as shown in the picture: enter image description here

Using 光线投射算法确定该点是否位于多边形内部,我无法确定,因为我得到的结果是错误的。 请让我知道我做错的地方或任何其他方法来确定解决方案。谢谢


我有过很好的经验Turf。它运作良好,有很好的文档记录,并且示例已经在传单中展示。

对于你的问题,你可以使用地盘内 with parentCoordinates as turf.polygon and childCoordinates作为一个数组turf.point :

var parentPolygon = turf.polygon([parentCoordinates]);

var inside = true;
childCoordinates.forEach(function(coordinates) {
    point = turf.point(coordinates);
    if (!turf.inside(point, parentPolygon)){
      alert("Oh no! "+ coordinates + " isn't in polygon");
      inside = false;
    }
});

alert("Child polygon inside parent polygon ? " + inside);

Here是一个小提琴的例子。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

检查传单中的多边形点是否位于另一个多边形点内部 的相关文章

随机推荐