Live data from Hacker News

How to generate random geo-coordinates within a given radius

jordinl.com

1–10 of 57 posts

Re: How to generate random geo-coordinates within a given radius

#4

Buffer your point to create a polygon then use ST_PointOnSurface (or equivalent) in any competent spatially-enabled DBMS to create a point guaranteed to intersect the bounding polygon. Trivial in SQLite, PostGIS, etc.

GIS buffer polygons were magical when I first stumbled upon them.

Re: How to generate random geo-coordinates within a given radius

#5
post #4

Buffer your point to create a polygon then use ST_PointOnSurface (or equivalent) in any competent spatially-enabled DBMS to create a point guaranteed to intersect the bounding polygon. Trivial in SQLite, PostGIS, etc.

GIS buffer polygons were magical when I first stumbled upon them.

Something wrong with them nowadays?

Re: How to generate random geo-coordinates within a given radius

#6
If the rationale is privacy this is probably not the algorithm you want to use, especially if it's possible to force the generation of multiple random points (e.g. by refreshing the map). If you're using a circle with a fixed radius just 3 points would be enough to exactly locate the center. A variable radius could take more, but since the distribution is uniform each additional point would significantly improve the precision.

Re: How to generate random geo-coordinates within a given radius

#7
> On a previous project we needed to show markers on a map to indicate there was a property, but for privacy reasons we wanted to show the marker on the map close to the property but not at the exact location of the property. So we needed to generate random points within a fixed distance of the original point location

This raises a couple of interesting questions.

1. How do you stop someone from finding the actual property location by querying that map a bunch of times and averaging the positions returned?

2. Are there any negative consequences for the people whose property a displaced marker ends up on? For example, if someone is using the map lookup to find the home of a rival gang officer in order to do a drive by attack, and I happen to live down the street, I really don't want that marker showing up on my house.

Rather than a displaced marker, maybe divide the map into rectangular or hexagonal regions, and just highlight the region containing the property.

Re: How to generate random geo-coordinates within a given radius

#8
post #6

If the rationale is privacy this is probably not the algorithm you want to use, especially if it's possible to force the generation of multiple random points (e.g. by refreshing the map). If you're using a circle with a fixed radius just 3 points would be enough to exactly locate the center. A variable radius could take more, but since the distribution is uniform each additional point would significantly improve the…

I imagine its for something like AirBnb where the site doesn't want the users to the location the property so they only way to book it is via the site.

Re: How to generate random geo-coordinates within a given radius

#9
post #7

> On a previous project we needed to show markers on a map to indicate there was a property, but for privacy reasons we wanted to show the marker on the map close to the property but not at the exact location of the property. So we needed to generate random points within a fixed distance of the original point location This raises a couple of interesting questions. 1. How do you stop someone from finding the actual pr…

[deleted]

Re: How to generate random geo-coordinates within a given radius

#10
post #7

> On a previous project we needed to show markers on a map to indicate there was a property, but for privacy reasons we wanted to show the marker on the map close to the property but not at the exact location of the property. So we needed to generate random points within a fixed distance of the original point location This raises a couple of interesting questions. 1. How do you stop someone from finding the actual pr…

[deleted]
Post reply on HN