Code Monkey home page Code Monkey logo

Comments (9)

davidmoten avatar davidmoten commented on August 24, 2024

Thanks for your comment. So the fact that it does get returned in order is
really an implementation detail that I don't want guaranteed by the api so
that if I want to I can change it. I don't think that the method name
'nearest' implies that it should be returned in any order so on that basis
I think the doco is valid.

On 25 February 2015 at 16:14, Dustin Spicuzza [email protected]
wrote:

Looking at the implementation of rtree.nearest, it states that it returns
objects in no particular order. However, it looks like the comparator that
it uses is called ascendingDistance... I haven't actually tested this of
course, but was wondering.


Reply to this email directly or view it on GitHub
#19.

from rtree.

virtuald avatar virtuald commented on August 24, 2024

So if I wanted to guarantee that they were returned in order, then I suppose I would add the comparator again -- just in case the implementation detail changed?

An alternative is you could add yet another overload with a boolean 'sorted' that does guarantee some type of order, and one that doesn't.

I think that 'nearest' with a count should make some guarantee about ordering. It would be difficult to imagine (though, certainly possible) something that returns the N nearest without checking somehow that they are in fact the N nearest. Presumably to determine that ordering it would have to be sorted somewhere, so why not pass that on to the caller?

from rtree.

davidmoten avatar davidmoten commented on August 24, 2024

I think your last point is good. I'm happy to change the doco to guarantee ordering.

from rtree.

davidmoten avatar davidmoten commented on August 24, 2024

thanks for your contribution @virtuald

from rtree.

virtuald avatar virtuald commented on August 24, 2024

Thanks! This is a super useful library.

from rtree.

virtuald avatar virtuald commented on August 24, 2024

@davidmoten sorry for bringing this up again, but it appears that nearest does not in fact return results sorted by distance -- even though the code appears to use a sorting comparator. Perhaps this is why the original docs state that the results aren't sorted?

It's confusing to me, but when I print out e.geometry().distance(searchBounds), I get print outs that look like this:

==
0.0
0.23379993438720703
0.2892003059387207
0.0
0.12929964065551758
0.0
0.24679994583129883
0.1872999668121338
==

This makes me wonder if it's actually returning the nearest results... I'll try to get a localized example of this working.

from rtree.

virtuald avatar virtuald commented on August 24, 2024

Ok, so you're using a MinMaxPriorityQueue underneath the hood, and the iterator returns results in no particular order --- so, therefore, your original comment on the code was correct. Very interesting.

It makes sense to me why it's done this way. However, it would be nice to have a version of the nearest method that does return them in sorted order. Presumably could just add a method that uses a different type of container to hold the results.

from rtree.

davidmoten avatar davidmoten commented on August 24, 2024

from rtree.

davidmoten avatar davidmoten commented on August 24, 2024

0.5.8 has the fix.

On 26 March 2015 at 07:28, Dave Moten [email protected] wrote:

Hi Dustin

Thanks for that, I hadn't noticed the documentation on the iterator saying
no particular order (perhaps I noticed first time around!). I think I
should modify the use of that queue so that on completion I don't use the
iterator but rather poll the queue which should return in order. That
should fix things. I'll raise an issue on github and we can continue
conversation there so rtree watchers can be aware of issue.

Dave

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.