arjunmehta / node-georedis

Super fast geo queries.
MIT License
192 stars 33 forks source link

georedis with own storage #24

Open measwel opened 6 years ago

measwel commented 6 years ago

Good day,

I would like to implement geohashing based on your module, but using own storage ( not redis ). Currently I store locations as int geohash (bit depth 52). For one location this is: 3672837726667608

By using the module I can calculate ranges based on location and radius. The result is:

[ 3672437556248576, 3672506275725312 ],
[ 3672574995202048, 3672918592585728 ],
[ 3672987312062464, 3673056031539200 ],
[ 3673193470492672, 3673330909446144 ]

My question:

  1. How should the query to the database look like? How should I compare the stored locations to the calculated range values? Should I just have 4 conditions testing if the geohash falls between the range boundaries?
  2. Why are there 4 ranges and not 8?
  3. Is searching within 4 ranges actually searching within a rectangle and not within a circle? ( the ranges have been calculated based on a radius.

Thank you.

arjunmehta commented 6 years ago

@measwel You can look at my answer here at gis.stackechange.

You will need to find a way to query a range of numbers. As long as you can do that, you should be able to implement this using your own form of storage.

Hope this helps!

measwel commented 6 years ago

Hallo Arjun,

Thank you. I managed to implement integer geohash search using my own storage :) However, I get results which I cannot explain.

  1. The smaller the search radius, the longer the query takes. I am querying 100.000 random points. With 100km radius, the query takes 5 seconds to execute. However, with 200km radius, execution time drops to 80 ms. Is this normal?

  2. When I calculate the distance between the central point of the search and the results, I get values bigger than the search radius. Searching with 200km radius returns points which are almost 400km away. Is this normal?

arjunmehta commented 6 years ago

That seems very wrong. The query shouldn't take much longer with different radii with a properly implemented ordered set. You need to be able to query your set with specific ranges.

measwel commented 6 years ago

I simply run 4 queries ( one for each range I get ) and aggregate the results.

I have a feeling that the errors I see might have to do with bigint implementation. I am considering switching to integer (32 bit) storage of integer hashes. How much precision can I expect in meters for 32 and for 64 bit integer storage? Can you provide me with an estimate of the maximum error I can expect?

Thank you!

The getQueryRangesFromRadius function for: lat lon radius accurate INPUT: 52.582014799999996 13.4913122 10000 true

getQueryRangesFromBitDepth(lat, lon, rangeBitDepth, 52);

Produces: RANGES: [ [ 3672810144661504, 3672811218403328 ], [ 3672813365886976, 3672815513370624 ], [ 3672833766981632, 3672834840723456 ], [ 3672835914465280, 3672841283174400 ] ]

Could you please check if I am getting the correct integer values here?