NoSQL: How to retrieve a 'house' based on lat & long?

♀尐吖头ヾ 提交于 2019-12-03 16:31:40

Sql or no sql is not the problem -- the problem is, strictly, what kind of indices do you have on your key. spatial indices, which is what you'd need to satisfy your query efficiently, have nothing to do with Sql, or even more generally with relational databases -- they're totally orthogonal to relational vs non-relational issues. Unfortunately, I don't know of any publicly available spatial-indexing systems for Cassandra or other popular non-relational DBs (indeed, the only GIS-oriented DB engine I know well is PostGIS, which happens to be built as an extension of the powerful open-source PostGres... which is relational;-).

If you don't have a spatial index but only a plain one (e.g., one sorted by Lat, then Long), then you'll have to scan through all records with suitable Lat, to discard those with unsuitable Long -- just as a relational engine would have to do for you under the same circumstances (when you select with a couple of BETWEENs and all it has to go on is a plain sorted index of the two fields thus constrained). Nothing to do with relational-ness... everything to do with indexing;-).

MongoDB is the only NoSQL database I know of that supports geospatial indexes. If you're using MongoDB, you should look at the documentation, but basically you'd create a geospatial index with:

db.houses.ensureIndex({house : "2d"})

You'd insert points like:

db.houses.insert({house : {latitude : y, longitude : x}})

and then query for it with:

db.houses.find({house : {$within : {$box : [[xxx, yyy], [www, zzz]]}}})

MongoDB also lets you search within a given radius and just for the nearest matches to a point.

Lucene also has something called Local Lucene. It can be reached over REST HTTP with Local Solr : http://www.gissearch.com/geo_search_intro http://wiki.apache.org/solr/SpatialSearch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!