0

I am new to AWS DynamoDB and I want to find the list of locations within r mile of radius from DynamoDB table( based on Latitude, Longitude and GeoHash) What is the best possible way to achieve this?

Preet
  • 1
  • 1
  • You may try to have a look at the DynamoDb GeoLibrary https://aws.amazon.com/blogs/aws/new-geo-library-for-dynamodb/ – gusto2 Oct 07 '21 at 18:59
  • Could you share what you have tried so far? [ask] – HoRn Oct 11 '21 at 07:09
  • @HoRn - I have followed the link https://www.movable-type.co.uk/scripts/geohash.html and calculated the 9 geohash boundaries. I can scan with these value but not query and scan is a costly operation. Is there a way to query DynamoDB(what should be the partition key and sort key - Table holds lat, lon, geoHash) – Preet Oct 12 '21 at 04:30

1 Answers1

0

This is something that, unless you are working with a very small data set, Dyanmo is not really suited for.

What you need is a weighted directional graph that links all points to all others. This kind of multi linkage is not what dynamo is good at. You would need, in effect, to have a dynamo that is set up like this:

pk: a location identifier | sk: another location id-number of miles from pk

then you can do a single query against a given location identifier with all values that are less than miles away, and you would get your answer.

you'd also have to query the exact point you want to know what is nearby, and youd have to have that eaxact point in the db. No doing 'close to this point' queries.

But as soon as you start dealing with thousands of data points you might see a problem. Even one of those locations will have to have every other location as an sk under the same pk in order to do that query. So you'd end up with:

pk           | sk
location 1   | location2#miles
location 1   | location3#miles
location 1   | location4#miles
location 2   | location1#miles
location 2   | location3#miles
location 2   | location4#miles
location 3   | location1#miles... ect

This is what a directed weighted graph object structure is for - and that object structure that actually does translate very well to dynamodb... (because under the fancy hood a directed weighted graph object is just a series of attributes saying how far away a given other object is) but may be impractical depending on how granular you are trying to be.

lynkfox
  • 2,003
  • 1
  • 8
  • 16
  • Hi lynkfox, this solution seems to be perfect for small data set. I am looking for a solution that's feasible with thousands of locations. – Preet Oct 07 '21 at 14:47
  • yes indeed... but no matter what solution you end up using, it is going to look much the same way. A Weighted Graph object, each node (ie: location) will have to have all connecting nodes in its attributes. This is how things like Maps and navmesh grids work - and so its entirely possible with billions of locations, but yes - it is very memory intensive. – lynkfox Oct 07 '21 at 16:16
  • I am stuck here, did you find a way ? – da45 Jan 29 '23 at 07:13