Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting nearest neighbors with S2 geometry. #80

Closed
winash12 opened this issue Aug 30, 2019 · 4 comments
Closed

Getting nearest neighbors with S2 geometry. #80

winash12 opened this issue Aug 30, 2019 · 4 comments

Comments

@winash12
Copy link

winash12 commented Aug 30, 2019

I am looking for a S2 geometry version of this SE answer - https://gis.stackexchange.com/questions/18330/using-geohash-for-proximity-searches/92331#92331

  1. I want to use S2 cells to do approximate nearest neighbor searches

  2. I have a bounding box on a 2D grid i.e. composed of latitudes and longitudes. For each latitude and longitude I want a S2 cell.These need to be "indexed" with a particular precision. That precision needs to be linked to a radius in kilometers or meters.

  3. Then I have a whole bunch of query coordinates completely unrelated to the above coordinates. So I can convert this coordinate to a index as well and maybe get's neighbors as well. These can be indexed at a lower precision.

  4. Then use this index to return nearest neighbors from the original bounding box. Here I am assuming some bit shifting will have to be done.

I have a highly optimized SkipList which does fast inserts and range queries. So the range query would return coordinates from the bounding box given the lower and upper range values from (3).

Is that possible with s2 geometry ?

@a1983
Copy link

a1983 commented Sep 6, 2019

Strange issue. It seems S2ClosestPointQuery is what you want.

@winash12
Copy link
Author

winash12 commented Sep 6, 2019

@a1983 Looks a good API to use. Certainly will do what I want.

Can you clarify on the precision part ? Should I index at the highest "level" which I believe is 30 for my bounding box coordinates ?

I also need to know what precision I should index my query coordinates.

@jmr
Copy link
Member

jmr commented Sep 20, 2019

What @a1983 said.

@winash12: you don't need to worry about "precision" or which level to index at. Just create an S2PointIndex, add your points, then use S2ClosestPointQuery to find the closest points. There's an example in point_index.cc.

@925781609
Copy link

Strange issue. It seems S2ClosestPointQuery is what you want.

Sorry, this is only available in C++. Does java has the same function or can achieve the same function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants