gpt4 book ai didi

javascript - 表示为 javascript 坐标数组的多边形联合

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:48:29 25 4
gpt4 key购买 nike

我需要找到表示为地理坐标的 javascript 数组的多边形并集,如下面的代码所示:

           var polygon1 = [[51.49151151647854, -0.20633749635419463],
[51.491517887745886, -0.20663465247037038],
[51.49125377257769, -0.20707803457401042],
[51.49125377257769, -0.20707803457401042],
[51.49090541057069, -0.2071046417369189],
[51.490605858341326, -0.20637621141179352],
[51.49081102624578, -0.20598780005047956],
[51.490859930095496, -0.20592173450688733]]


var polygon2 = [[51.492223312188386, -0.20784254067885688],
[51.49226262897666, -0.20812681455816695],
[51.49162516066342, -0.2090258514344801],
[51.491538051645385, -0.2089717941050469],
[51.49200661100099, -0.20759325088262348]]

我会使用 Google maps Javascript API v3 在 Google map 上绘制生成的多边形,因此它们的结构也可以像下面的代码一样:

   var googleMapPolygon1 = [
new google.maps.LatLng(51.49151151647854, -0.20633749635419463),
new google.maps.LatLng(51.491517887745886, -0.20663465247037038),
new google.maps.LatLng(51.49125377257769, -0.20707803457401042),
new google.maps.LatLng(51.49090541057069, -0.2071046417369189),
new google.maps.LatLng(51.490605858341326, -0.20637621141179352),
new google.maps.LatLng(51.49081102624578, -0.20598780005047956),
new google.maps.LatLng(51.490859930095496, -0.20592173450688733),
new google.maps.LatLng(51.49151151647854, -0.20633749635419463)
];

var googleMapPolygon2 = [
new google.maps.LatLng(51.492223312188386, -0.20784254067885688),
new google.maps.LatLng(51.49226262897666, -0.20812681455816695),
new google.maps.LatLng(51.49162516066342, -0.2090258514344801),
new google.maps.LatLng(51.491538051645385, -0.2089717941050469),
new google.maps.LatLng(51.49200661100099, -0.20759325088262348),
new google.maps.LatLng(51.492223312188386, -0.20784254067885688)
]

那么,我可以用什么来找到多边形的并集呢?提前致谢。

编辑: 这就是我所做的。我有结构为多边形的 Voronoi 单元阵列(下图左侧)。我想要得到的是它们周围的边界(下图右侧的绿色多边形)。 enter image description here

所以,我觉得用union运算就可以搞定。谁能帮忙?

最佳答案

你可以这样做:

var polygon1 = [[51.49151151647854, -0.20633749635419463],
[51.491517887745886, -0.20663465247037038],
[51.49125377257769, -0.20707803457401042],
[51.49125377257769, -0.20707803457401042],
[51.49090541057069, -0.2071046417369189],
[51.490605858341326, -0.20637621141179352],
[51.49081102624578, -0.20598780005047956],
[51.490859930095496, -0.20592173450688733]];

var polygon2 = [[51.492223312188386, -0.20784254067885688],
[51.49226262897666, -0.20812681455816695],
[51.49162516066342, -0.2090258514344801],
[51.491538051645385, -0.2089717941050469],
[51.49200661100099, -0.20759325088262348]];

var union = new google.maps.Polygon({
paths: polygon1.concat(polygon2)
});

关于javascript - 表示为 javascript 坐标数组的多边形联合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28896386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com