如何从NoSQL DBMS(例如DynamoDB)存储半径范围内的GPS坐标和搜索位置 [英] How to store GPS coordinate and search places in a radius from a NoSQL DBMS (like DynamoDB)

查看:146
本文介绍了如何从NoSQL DBMS(例如DynamoDB)存储半径范围内的GPS坐标和搜索位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的团队需要像DynamoDB这样的DBMS来存储大量数据,主要是位置和坐标。
我已经考虑过使用一些基于GIS的DBMS(例如PostGIS)和POINT上的索引,但是DynamoDB似乎非常适合我们使用。

My team needs a DBMS like DynamoDB to store large amount of data, principally places and coordinates. I've considered to use some GIS-based DBMS (like PostGIS) with an index on the POINT, but DynamoDB seems great for our use.

在PostGIS中很容易,就像这样:

In PostGIS it's easy, something like this:

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

如何在NoSQL DBMS中做类似的事情?

How can I do something like that in a NoSQL DBMS?

推荐答案

我们遇到了同样的问题,特别是在使用AWS和DynamoDB。
我们使用CloudSearch Service解决了这个问题,每次我们在数据库中存储一些可地理搜索的数据时,我们都会使用lat,lon作为过滤器对CloudSearch实例中的数据建立索引(为此,您必须将经纬度转换为uint)。

We had the same issue, we're using AWS and DynamoDB in particular. We solved that problem by using CloudSearch Service, every time we store some 'geo-searchable' data in our database we index the data in a CloudSearch instance with lat,lon as filters ( to do this you have to do a transformation on lat and lon to turn it into a uint ).

然后假设您要搜索特定的经度/纬度和半径,以计算相应的地理框(latmin,latlat,lonmin,lonmax)并查询您的CloudSearch具有特定过滤器的实例来检索数据的关键架构,然后可以查询DynamoDB以获取信息。

Then let's say you want to do a search on a particular lat/lon and radius you compute the corresponding geobox ( latmin, latmax , lonmin, lonmax ) and query your CloudSearch instance with the specific filters to retrieve the key schema of your data, you can then query DynamoDB to get the information.

Java中的某些代码可以完成上述操作:

Some code in Java to do just the above :

使用Tyler Coles的com.javadocmd.simplelatlng.window包中的RectangularWindows,计算边界框并进行经纬度转换。

Using RectangularWindows from the com.javadocmd.simplelatlng.window package by Tyler Coles, computing the bounding box and doing the transformation 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);

然后在CloudSearch实例上查询示例:

Then an example of a query on the CloudSearch instance :

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

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

我不确定这是最好的解决方案,但这就是我们想出的办法

I'm not sure it's the best solution but that's what we came up with

这篇关于如何从NoSQL DBMS(例如DynamoDB)存储半径范围内的GPS坐标和搜索位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆