Random geographic coordinates (on land, avoid ocean)

前端 未结 16 1153
死守一世寂寞
死守一世寂寞 2020-12-08 10:03

Any clever ideas on how to generate random coordinates (latitude / longitude) of places on Earth? Latitude / Longitude. Precision to 5 points and avoid bodies of water. <

16条回答
  •  青春惊慌失措
    2020-12-08 10:37

    Definitely you should have a map as a resource. You can take it here: http://www.naturalearthdata.com/

    Then I would prepare 1bit black and white bitmap resource with 1s marking land and 0x marking water.

    The size of bitmap depends on your required precision. If you need 5 degrees then your bitmap will be 360/5 x 180/5 = 72x36 pixels = 2592 bits.

    Then I would load this bitmap in Java, generate random integer withing range above, read bit, and regenerate if it was zero.

    P.S. Also you can dig here http://geotools.org/ for some ready made solutions.

提交回复
热议问题