Code Monkey home page Code Monkey logo

Comments (4)

davidmoten avatar davidmoten commented on August 24, 2024

Glad you are finding the library useful!

If the dimensions of the axes are very different then that might have negative effects on the performance of the rtree because of bias to or away from an axis. I would normally suggest translating and scaling the coordinates in this case say so they are in the 0..1 range.

Euclidean distance doesn't sound like it has a lot of meaning as you point out. I would just do a search with a rectangle (x-xDistance, y-yDistance, x+xDistance, y+yDistance) which seems to match your use case exactly. Am I missing something?

from rtree.

chhh avatar chhh commented on August 24, 2024

That's what I'm doing now (search with a rectangle), but it finds everything that intersects the query. In my case such a search might bring up a lot of unnecessary stuff (e.g. some large rectangles that are also in the tree), I thought that it could be much more efficient to do nearest() with small k because I only need the closest things to my query point.

After writing this I think I know what I'm missing -- a method like search(Geometry g, boolean fullyEncloses). Instead of intersections I'd like to be able to find all things that are completely enclosed by the query. In case of arbitrary geometries that would be full enclosure of their bounding boxes.

I don't know if such queries are possible/easy to implement with an RTree. If not, then a nearest() with different constraints for coordinates might work.

from rtree.

davidmoten avatar davidmoten commented on August 24, 2024

To get the contains seach you would do this:

RTree<Object, Rectangle> tree = ...;
List<Entry<Object,Rectangle>>  entries = 
  tree
    .search(rect)
    .filter(entry -> rect.contains(entry.geometry()))
    .toList().toBlocking().single(); 

This will be the most efficient way of doing it and any api additions would probably do this under the covers. Are you using filter with the returned observable as above?

from rtree.

chhh avatar chhh commented on August 24, 2024

No, I wasn't using filter, I thought that some direct serach solution would be faster. But since you say this is how you'd implement this type of query anyway, I just have to believe you :)

Thank you!

PS: I guess this can be added to the readme (how to perform contains queries)

from rtree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.