1.0.0 • Published 9 years ago

geotrie v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
9 years ago

#Geotrie Store and search geo data. Geohashes and stores latitude/longitude coordinates and provides a search interface.

Right now depends on leveldb, as it uses the lexographical sorting of leveldb to provide a trie like data structure and efficient search algorithm. However this approach can and should be generalized to work in memory and with other databases.

Heavily borrowed from / inspired by level-trie and level-places. Thanks to Julian Gruber.

##Usage

var level = require('level')
var GeoTrie = require('geotrie')
var geotrie = geotrie(level(__dirname + '/db'))

geotrie.add({lat: 1, lon: 1}, 'SomeReferenceString')
geotrie.add({lat: 1.01, lon: 1}, 'OtherReferenceString')

geotrie.search({lat: 1, lon: 1}).toArray(function(err, results){
  //...
})

Results will come in the form of

{
  distance: 10, //in meters
  pos: {lat: 1, lon 1}, //stored position (will not be exact because of geohashing fidelity loss)
  ref: 'your string' //the reference string supplied during .add
}

Search Options ###hardLimit (Int) If supplied the search will immediately return after reaching this number of results (setting hard limit may result in omitted results that are closer to the centroid than other returned results) ###softLimit (Int) Usually a better option to setting hardLimit - If hit, the search will finish streaming after it completes it's current resolution level ###maxResolution (int) Defaults to 12. The search will start from the max resolution. If your relevant results will always be far apart then you can set this number lower for small efficiency gains ###minResolution (int) Defaults to 0. The search will end at this resolution even if the hard/soft limits have not been met.

##Notes Unfortunately geohash's are roughly rectangular in shape (and generally not square). If using a 2^(odd) base odd precision hash boxes will be square - all other hash boxes are about twice as big in the longitudinal direction at the equator (it reverses as you travel to extreme latitudes where longitudinal distances pinch).

##Geohash Precision Assuming base16 geohashing (4 bits per character) the hash precision will be as follows:

PrecisionLat ErrorLon Error
21248.75 km2497.5 km
478.046875 km156.09375 km
64.8779296875 km9.755859375 km
8304.870605469 m609.741210938 m
1019.0544128418 m38.1088256836 m
121.19090080261 m2.38180160522 m