码迷,mamicode.com
首页 > 其他好文 > 详细

Rtree实现多维空间搜索

时间:2017-06-01 16:51:31      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:rtree 多维空间搜索

    好的,现在有这么一个需求。你所开发的应用的数据库中有全市所有饭店的经纬度坐标,现在你在某地定位了一个坐标,应用如何给你找出最近的饭店。多维空间搜索,使用RTree。这里只推荐已有的实现了RTree的jar包。

maven项目,可下载jar包,并且这是一个简单的例子:https://github.com/aled/jsi-examples

在线API:http://jsi.sourceforge.net/apidocs/index.html 


下面附上自己很low的测试代码:

net.sf.jsi.examples;

gnu.trove.procedure.TIntProcedure;
net.sf.jsi.Point;
net.sf.jsi.Rectangle;
net.sf.jsi.SpatialIndex;
net.sf.jsi.rtree.RTree;

TestRTree {
    run() {
        Point point = Point(, );
        Rectangle[] rectangle = Rectangle[];
        rectangle[] = Rectangle(, , , );
        rectangle[] = Rectangle(, , , );
        rectangle[] = Rectangle(-, -, -, -);
        rectangle[] = Rectangle(-, -, -, -);
        SpatialIndex si = RTree();
        si.init();
        (i = ; i < rectangle.; i++) {
            si.add(rectangle[i], i);
        }
        si.nearestN(point, TIntProcedure() {
            execute(i) {
                System..println(+ i + + [i] + + [i].distance());
                ;
            }
        }, , Float.);

    }

    main(String[] args) {
        TestRTree().run();
    }
}


本文出自 “12571026” 博客,请务必保留此出处http://12581026.blog.51cto.com/12571026/1931233

Rtree实现多维空间搜索

标签:rtree 多维空间搜索

原文地址:http://12581026.blog.51cto.com/12571026/1931233

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!