gpt4 book ai didi

android - 获取多边形角内的随机点?

转载 作者:行者123 更新时间:2023-12-04 23:56:41 26 4
gpt4 key购买 nike

我在谷歌地图中绘制了一个多边形。我想在多边形边界内生成随机坐标以在多边形内添加一些标记。我该怎么做?

我得到了这个链接

https://gis.stackexchange.com/questions/163044/mapbox-how-to-generate-a-random-coordinate-inside-a-polygon

但是是javascript代码但是如何在java代码中获取。

最佳答案

在 Python 中,您可以在定义的多边形中生成随机坐标,如下所示

import numpy as np
import random

from shapely.geometry import Polygon, Point


poly = Polygon([(23.789642, 90.354714), (23.789603, 90.403000), (23.767688, 90.403597),(23.766510, 90.355448)])

def random_points_within(poly, num_points):
min_x, min_y, max_x, max_y = poly.bounds

points = []

while len(points) < num_points:
random_point = Point([random.uniform(min_x, max_x), random.uniform(min_y, max_y)])
if (random_point.within(poly)):
points.append(random_point)

return points


points = random_points_within(poly,1000)

for p in points:
print(p.x,",",p.y)

关于android - 获取多边形角内的随机点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55392019/

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