Code Monkey home page Code Monkey logo

Comments (11)

davidmoten avatar davidmoten commented on August 24, 2024 1

Once you've created an RTree loading one by one from your txt file you then use the Serializers.write example to write the tree to a binary (flatbuffers) file. You can then load an RTree from that file later in the blink of an eye using Serializers.read.

from rtree.

davidmoten avatar davidmoten commented on August 24, 2024

Just use the method RTree.nearest. you're right I should put an example in
the README, thanks.

On Wed, 18 May 2016 21:15 starryskyWW [email protected] wrote:

Thanks for your sharing.
I have many points which records latitude and longitude. I want to know
whether this code support K-nn query for each point?
I don't read relevant message except

As of 0.7.5 this library does not depend on guava (>2M) but rather depends
on guava-mini (11K). The nearest search used to depend on
MinMaxPriorityQueue from guava but now uses a backport of Java 8
PriorityQueue inside a custom BoundedPriorityQueue class that gives about
1.7x the throughput as the guava class.

But there is no specific example for k-nn query.
Thanks so much.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#48

from rtree.

wweichn avatar wweichn commented on August 24, 2024

Thanks for your prompt reply. By the way, I want to ask something which concerns about loading data. I'm not quite clear about the use of class serializer.
I have a .txt file which records lots of location coordinates, the first column records latitude and the second column records corresponding longitude. I want to load these data at one time to build a r-tree, because it's quite time-consuming to add these points one by one. Some issues asked by others and the README.md indicated that serializer can achieve this .
But I don't know how to use this.
image
For the .txt file, I creat an inputstream like the following
image
But I thought I might be wrong to the processing of the data.
Thanks so much. This code is powerful.

from rtree.

wweichn avatar wweichn commented on August 24, 2024

Thanks for your kind explanation. There is another problem,
when I add rtree-0.7.5 version dependency in my pom.xml, there is no mistake for the code
List<Entry<String, Point>> list = new ArrayList<Entry<String, Point>>();
list.add(new Entry<String,Point>(String.valueOf(i),Point.create(Float.parseFloat(s[0]),Float.parseFloat(s[1]))));
But once I change to rtree-0.8-RC1
There is error hints that The method create(double, double) from the type Point is not visible
And when I type Point. in the second situation, there is not any hint for the method in the Point class.
I don't know why. Because the content of the Point class doesn't change in two versions.

from rtree.

davidmoten avatar davidmoten commented on August 24, 2024

Use Geometries.point instead.

from rtree.

wweichn avatar wweichn commented on August 24, 2024

Thanks. And if I want to search the points inside a specific circle which is defined by a specific point and radius, what can I do?
It seems like the search(point,Distance) will return all points inside a rectangle whose minimum bounding rectangles are within Distance from the given point. And I think maybe this will miss some points.
And I don't know whether it's right to write as
Point location = p1; (p1 is the heart of the circle)
String result = tree.search(location)
// filter on the exact distance from the centre of the GeoCircle
.filter(new Func1<Entry<String,Point>, Boolean>() {
Position from = Position.create(location.y(), location.x());
@Override
public Boolean call(Entry<String,Point> entry) {
Position centre = Position.create(entry.value().lat, entry.value().lon);
return from.getDistanceToKm(centre) < from.value().radiusKm;' }
I just made some small changes in the LatLongExampleTest.testSearchLatLongCircles().
I think if this can be realized,it would be very good. Thanks so much .
Thanks so much.

from rtree.

wweichn avatar wweichn commented on August 24, 2024

After I used Geometries.point
there is another problem for the code new Entry<String,Point>(String.valueOf(i),Geometries.point(Float.parseFloat(s[0]),Float.parseFloat(s[1])))
It said that Cannot instantiate the type Entry<String,Point>
And I tried Entry.entry(String.valueOf(i),Geometries.point(Float.parseFloat(s[0]),Float.parseFloat(s[1])))
It still doesn't work. It said that The method entry(String, Point) is undefined for the type Entry
I am sorry to occupy your time.

from rtree.

davidmoten avatar davidmoten commented on August 24, 2024

Entries.entry (examples are on the README).

from rtree.

davidmoten avatar davidmoten commented on August 24, 2024

For the circle search you need to make sure the initial search is big enough not to miss any then filter on exact distance. Boils down to some simple geometry. Watch out though because when you do search(point, distance) the distance unit will be degrees so you pick a large enough degrees value to cover the radius that you know in km, then filter in km as you were.

from rtree.

davidmoten avatar davidmoten commented on August 24, 2024

See worked example mentioned in README:

https://github.com/davidmoten/rtree#another-lat-long-example-searching-geo-circles-

from rtree.

eadwright avatar eadwright commented on August 24, 2024

Also remember the geographic distortion with latitude, a circle of radius 1 degree on the Earth's surface some distance from the equator will be "taller" in terms of km north-south than east-west. If accurate distance tests are needed they should be performed (as suggested) on the subset of results returned by the tree.

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.