mapbox - 如何在多边形内生成随机坐标
mapbox - how to generate a random coordinate inside a polygon
我看过 mapbox 的传单插件,它可以找到特定点/坐标所在的多边形,但我该怎么做相反的事情 - 在特定多边形内生成随机点/坐标?
您可以使用Turf's Point on Surface方法生成一个随机点:
Takes a feature and returns a Point guaranteed to be on the surface of the feature.
要检查点是否包含在多边形中,您可以使用 Inside 方法:
Takes a Point and a Polygon or MultiPolygon and determines if the point resides inside the polygon. The polygon can be convex or concave. The function accounts for holes.
我看过 mapbox 的传单插件,它可以找到特定点/坐标所在的多边形,但我该怎么做相反的事情 - 在特定多边形内生成随机点/坐标?
您可以使用Turf's Point on Surface方法生成一个随机点:
Takes a feature and returns a Point guaranteed to be on the surface of the feature.
要检查点是否包含在多边形中,您可以使用 Inside 方法:
Takes a Point and a Polygon or MultiPolygon and determines if the point resides inside the polygon. The polygon can be convex or concave. The function accounts for holes.