Sigm0oid / dynamodb-geo.py

A python port of awslabs/dynamodb-geo, for dynamodb geospatial querying
MIT License
32 stars 21 forks source link

QueryRadiusRequest: Get items in a nearest to farthest order #32

Closed waqas-syed closed 4 years ago

waqas-syed commented 4 years ago

I got 2 questions:

  1. Currently, the dynamodbgeo.QueryRadiusRequest gets all of the stored items that fall within the specified radius, but the returned list is not sorted in the order of nearest to farthest point starting from the dynamodbgeo.GeoPoint. It doesn't matter where the provided geopoint is, the resultset is always in the same order sorted as per the calculated geohash attribute. Are there any plans for a feature to get the items in an order of nearest to farthest from a given point inside of a certain radius? Like in the Haversine Formaula?

  2. Secondly, what is the mechanism of the sort order when the items are stored in the DB? The geohash gets generated from a lot of stuff going in the background, but in simple terms, in what manner is the geohash calculated from the coordinates. E.g., from north to south or something along those lines? I couldn't figure a pattern.

Great effort in building this. TIA

Sford4 commented 4 years ago

I too would love to see results ordered by distance!

keyliin0 commented 4 years ago

Hey @waqas-syed,

Sorry for the late reply.

Currently, the dynamodbgeo.QueryRadiusRequest gets all of the stored items that fall within the specified radius, but the returned list is not sorted in the order of nearest to farthest point starting from the dynamodbgeo.GeoPoint. It doesn't matter where the provided geopoint is, the resultset is always in the same order sorted as per the calculated geohash attribute. Are there any plans for a feature to get the items in an order of nearest to farthest from a given point inside of a certain radius? Like in the Haversine Formaula?

This sounds like a good feature, I'll add this, thank you for the suggestion.

Secondly, what is the mechanism of the sort order when the items are stored in the DB? The geohash gets generated from a lot of stuff going in the background, but in simple terms, in what manner is the geohash calculated from the coordinates. E.g., from north to south or something along those lines? I couldn't figure a pattern.

Just as many hashing functions, geohash doesn't perserve any order so I don't think it's possible to find a pattern in it.

keyliin0 commented 4 years ago

Added here.