开发者

Randomly generate a point within a country boundary polygon

开发者 https://www.devze.com 2023-01-22 03:49 出处:网络
I\'m interested in pulling street view data at random within a country. I can only figure out how to generate a point within a bounding box.Often it pulls data from nearby nations.I\'m using a GIS se

I'm interested in pulling street view data at random within a country.

I can only figure out how to generate a point within a bounding box. Often it pulls data from nearby nations. I'm using a GIS server right now, but I'm interested in removing it from the workflow since it's a 开发者_运维问答pain.

Anybody know of any javascript mapping API that can randomly generate a point within a complex polygon, such as a country boundary?

Phil


I don't know of any practical algorithm to do this for an arbitrary, potentially-concave polygon, and still maintain uniform probability for each possible point.

(I mean, you could pick an axis crossing the polygon at random, find the crossing-points and pick a position from somewhere inside odd crossing-point-ranges. But that would leave some points more likely to be picked then others.)

I would go with the approach of picking a random point inside the rectangular bounding box, checking for collision against the country's vector data and generating another one on a miss.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号