Comments (9)
I didn't quite understand what you are trying to do and what the problem was. Can you make a failing unit test please that demonstrates the problem. The test should be as succinct as possible focusing on the unexpected behaviour, not your use case. Thanks.
from rtree.
Rectangle mbb1 = Geometries.rectangleGeographic(72.96089172363281,19.17504474158168,72.96230792999268,19.190122840904767);
Rectangle mbb2 = Geometries.rectangleGeographic(72.96083271503448,19.173942709431888,72.96088099479675,19.174720466220187);
RTree<String, Rectangle> tree = RTree.create();
Map<String, Rectangle> nameByBoundingBox = new HashMap();
tree = tree.add("bb1", mbb1);
tree = tree.add("bb2", mbb2);
nameByBoundingBox.put("bb1", mbb1);
nameByBoundingBox.put("bb2", mbb2);
Map<String, String> pairs = new HashMap<>();
for(Map.Entry<String, Rectangle> entry : nameByBoundingBox.entrySet()) {
tree.search(entry.getValue(), new Func2<Rectangle, Rectangle, Boolean>() {
public Boolean call(Rectangle g, Rectangle r) {
// find those items which are within 5 metres
return 0.0 <= g.distance(r) && g.distance(r) <= 5.0;
}
})
.forEach((Entry<String, Rectangle> rectangle) -> {
// don't pair up with itself
if(!rectangle.value().equals(entry.getKey())) {
pairs.put(entry.getKey(), rectangle.value());
}
});
// remove this node from rtree so that its not paired up again
tree = tree.delete(entry.getKey(), nameByBoundingBox.get(entry.getKey()));
}
So I am basically looking to pair up those rectangles which are within 5 metres distance. I expect that for every iteration of for loop, number of times 'call' is invoked is number of times items left in rtree. So if we start with 2 rectangles in rtree, for first entry 'call' is called 2 times. Then I remove that entry using 'delete' method. So now 1 item is left. So for second entry, 'call' is invoked 1 time. So total 3 times 'call' must be invoked. But I observe that 'call' is invoked only twice.
from rtree.
Thanks but please isolate further. I want to see one call to search that doesn't give what you expect or a call to delete that doesn't give you what you expect.
from rtree.
So I have structured code a bit. I wanted to modify a counter inside 'call' method which I could then apply assert on. But it seems its not possible. So what I have done is that I have put a print out statement inside 'call'. I expect "Inside call" to be printed 3 times, but you would see only 2 times, and each time g and r are similar to each other, meaning 'call' is not invoked for comparing different g and r.
PS: I have changed criteria in 'call' and then used assert on pairs.
class Test {
public static void main(String[] args) {
Rectangle mbb1 = Geometries.rectangleGeographic(72.96089172363281, 19.17504474158168, 72.96230792999268, 19.190122840904767);
Rectangle mbb2 = Geometries.rectangleGeographic(72.96083271503448, 19.173942709431888, 72.96088099479675, 19.174720466220187);
RTree<String, Rectangle> tree = RTree.create();
Map<String, Rectangle> nameByBoundingBox = new HashMap();
tree = tree.add("bb1", mbb1);
tree = tree.add("bb2", mbb2);
nameByBoundingBox.put("bb1", mbb1);
nameByBoundingBox.put("bb2", mbb2);
Map<String, String> pairs = new HashMap<>();
for (Map.Entry<String, Rectangle> entry : nameByBoundingBox.entrySet()) {
tree.search(entry.getValue(), new Func2<Rectangle, Rectangle, Boolean>() {
public Boolean call(Rectangle g, Rectangle r) {
System.out.println("Inside call");
return 0.0 <= g.distance(r) && g.distance(r) <= 5000.0;
}
})
.forEach((Entry<String, Rectangle> rectangle) -> {
// don't pair up with itself
if (!rectangle.value().equals(entry.getKey())) {
pairs.put(entry.getKey(), rectangle.value());
}
});
// remove this node from rtree so that its not paired up again
tree = tree.delete(entry.getKey(), nameByBoundingBox.get(entry.getKey()));
}
Assert.equals(1, pairs.size());
}
}
Please let me know if you need more inputs or action on my side.
from rtree.
Hi, I'm trying to avoid some diagnostic work here. If there is a problem with the library then one call to tree.search
or tree.delete
is doing the wrong thing. Can you step through this three times yourself to see when something unexpected happens and then isolate so you have one tree object that shows the problem. No loops, just add and delete stuff from a tree and show it ends up in an unexpected state.
from rtree.
So I removed delete part and loop, and now my code is:
tree.search(nameByBoundingBox.get("bb1"), new Func2<Rectangle, Rectangle, Boolean>() {
public Boolean call(Rectangle g, Rectangle r) {
// find those items which are within 5 metres
System.out.println("Inside call");
return 0.0 <= g.distance(r) && g.distance(r) <= 5000.0;
}
})
.forEach((Entry<String, Rectangle> rectangle) -> {
// don't pair up with itself
if (!rectangle.value().equals("bb1")) {
pairs.put("bb1", rectangle.value());
}
});
When I run this code, 'call' is still invoked only once, even though there are 2 rectangles in tree.
I also output tree image at start and end, and both are same, as below.
I don't see any modification in tree.
from rtree.
Another observation I made. With following code,
tree.search(nameByBoundingBox.get("bb1"), 5000.0)
.forEach((Entry<String, Rectangle> rectangle) -> {
// don't pair up with itself
System.out.println("Inside foreach");
if (!rectangle.value().equals("bb1")) {
pairs.put("bb1", rectangle.value());
}
});
I see 'Inside foreach' printed twice, as expected. So only when I pass callback function to search method, code is not working as expected.
from rtree.
Wait a second, you shouldn't expect the call to be made once for every item in the tree. If it always did then it would be a pretty useless index wouldn't it! The distance check might be made on a bounding box around two items. If it fails then the distance check will fail for the two items as well and the check doesn't need to be made on them individually. If there is a problem here you need to show me via the results of the search not the number of times the distance check is called.
from rtree.
Closing as non-issue.
from rtree.
Related Issues (20)
- 0.8.7 version method add in RTree HOT 1
- How can I use R-tree and R*-tree to store roads information and use circle to search point nearest roads?
- How to serialize all geometry? HOT 1
- How to add the count of data points and their linear sum for each MBR HOT 1
- Rtree can't insert anything HOT 2
- The unit of Circle radius is in meter? HOT 2
- Question: how to find overlapping circles? HOT 4
- How to do an incremental knn search? HOT 5
- Pre conditions failing in Rectangle Implementation HOT 2
- Honour minChildren with delete operation HOT 1
- Is the unit of the parameter radius in CircleDouble. create (x, y, radius) in meters? What other unit is it? HOT 2
- Difference between LineDouble and LineFloat
- Is there a way to have sampled results over a geographical search ? HOT 3
- Incorrect result for horizontal line search HOT 4
- Rxjava2 version available? HOT 2
- Would you plan to provide a method that deletes entries according to a value? HOT 2
- rtree2 HOT 2
- [Question] A R-Tree search performance question HOT 7
- Propose to store the geographic rectangles in Integer rather than in Float
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rtree.