Hi, this is not exactly a Julia question I guess. But I really like this forum. So I post it here. I was wondering, how to randomly generate a GPS location from China in WGS 84 format? I guess we will need to find the range of GPS locations of China and randomly generate a location from this range. Could anyone provide some reference links for doing this?

Many thanks indeed.

# Randomly generate a GPS location in WGS 84 format from China?

Do you need the distribution of the point to be uniform over all of China? Or how close to uniform do you need the distribution to be?

One good workflow could be:

- Find or generate the description of a polygon defining the boundaries of China. This can be in any coordinate system you want. Depending on the precision you need, you could use a tool like this to sketch a boundary yourself.
- Pick a coordinate system over which youâ€™ll sample points. A quick moment of searching suggests that https://spatialreference.org/ref/sr-org/7564/ might be a reasonable choice. For lower precision, even https://epsg.io/3857 could be okay.
- If your polygon from #1 isnâ€™t already in this coordinate system, project it. I havenâ€™t used it myself but believe ArchGDAL.jl (docs) can do this.
- Use an acceptance-rejection algorithm to generate a point within the defined polygon in your projected coordinate system. In brief, this would mean generating a point over the bounding box of the polygon and checking if the point is actually in the China polygon. If yes, move on to the next step; if no, generate a new point and try again. For checking if a point is in a polygon, I would recommend LibGEOS.
- Project the point you found back to WGS84 lat-lon coordinates.

Itâ€™s worth noting that China is big [citation needed], so any projected coordinate system will have some slight inaccuracy somewhere!

With GMT.jl you can get the China polygons (many) with

```
china=coast(DCW=:CN, dump=true);
```

The `gmtselect`

module (option F) will let you select only the points inside the polygons.

Sorry have no time now to elaborate more (maybe later).

The fact that this preserves area is a good thing. If you sample in a coordinate system in which dy,dx varies in area (such as latitude-longitude) you will get nonuniform samplingâ€¦ more points per unit area in the regions in the north where the area is smaller per dlat,dlong and fewer points per area in regions near the equator.