How to store GPS coordinates and search locations in a radius from NoSQL DBMS (for example, DynamoDB)

My team needs a DBMS, such as DynamoDB, to store a lot of data, mainly locations and coordinates. I decided to use some GIS-based DBMSs (like PostGIS) with a POINT index, but DynamoDB seems great for our use.

What is the best method for storing coordinates and quickly retrieving all objects in a specific radius?

In PostGIS, this is easy, something like this:

SELECT * FROM places WHERE ST_DWithin(coordinate, ST_GeomFromText('POINT(45.07085 7.68434)', 4326), 100.0); 

How can I do something like this in NoSQL DBMS?

+7
source share
3 answers

We had the same problem, we use AWS and DynamoDB in particular. We solved this problem with the CloudSearch Service, every time we store some "geo-search" data in our database, we index the data in the CloudSearch instance using lat, lon as filters (for this you need to do the conversion to lat and lon to turn it into uint).

Then we say that you want to search for a specific lat / bosom and radius, you calculate the corresponding geo objects (latmin, latmax, lonmin, lonmax) and request a CloudSearch instance with specific filters to obtain the key scheme of your data, you can query DynamoDB for information .

Some code in Java to do just above:

Using RectangularWindows from the com.javadocmd.simplelatlng.window package by Tyler Coles, calculating the bounding box, and performing the conversion for lat / lon.

 RectangularWindow rectangularWindow = new RectangularWindow(newLatLng(location.getLat().doubleValue(), location.getLon().doubleValue()), radius.doubleValue(), radius.doubleValue(), LengthUnit.KILOMETER); latMin = (long) ((180 + rectangularWindow.getMinLatitude()) * 100000); latMax = (long) ((180 + rectangularWindow.getMaxLatitude()) * 100000); lonMin = (long) ((360 + rectangularWindow.getLeftLongitude()) * 100000); lonMax = (long) ((360 + rectangularWindow.getRightLongitude()) * 100000); 

Then an example query in an instance of CloudSearch:

http: // [SEARCHURL] / 2011-02-01 / search? bq = (and lat: 22300347..22309340 (and lon: 28379282..28391589))

I'm not sure if this is the best solution, but what did we come up with

+5
source

You can use geohashing to query neighboring objects based on strings rather than calculations.

Geohash allows you to save the location of nodes in buckets, which can then be requested using strings as a range or hash key in dynamodb.

Here is a good example https://github.com/davetroy/geohash-js made in javascript that can be easily rewritten in other languages.

+4
source

I am currently studying this topic myself. I am using MongoDb (I know that you asked for DynamoDb, but you also asked for general use of NoSql), and my code looks like this:

record structure:

 public class FrameDocument { [BsonId] public Guid Id { get; set; } [BsonElement("coordinates")] public Point[] Polygon { get; set; } } public class Point { [BsonElement("name")] public string Orientation { get; set; } [BsonElement("loc")] public double[] Location { get; set; } } 

connection and provision of the index:

 MongoServer server = MongoServer.Create(connectionString); MongoDatabase database = server.GetDatabase(databaseName); database.GetCollection(collectionName).EnsureIndex(IndexKeys.GeoSpatial("coordinates.loc")); 

recording:

 var items = database.GetCollection(collectionName); items.InsertBatch(itemsToInsert); 

Search:

 double[,] points; // define you search coordinates var items = database.GetCollection<FrameDocument>(collectionName); var query = Query.WithinPolygon("coordinates.loc", points); var cursor = items.Find(query); 
+1
source

All Articles