博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
RTree算法Java实现 JSI RTree Library的调用实例 标签:jsi-rtree-library
阅读量:5152 次
发布时间:2019-06-13

本文共 2136 字,大约阅读时间需要 7 分钟。

1. [代码]jsi-rtree-library     

/**
 * 
 */
package com.mycompany.project;
 
//package net.sourceforge.jsi.examples;
 
import java.util.ArrayList;
import java.util.List;
 
import org.apache.log4j.Logger;
 
//import org.slf4j.*;
import com.infomatiq.jsi.*;
 
import gnu.trove.*;
 
import com.infomatiq.jsi.Rectangle;
import com.infomatiq.jsi.rtree.RTree;
 
public class Contains
{


    private static Logger logger = Logger.getLogger(Contains.class);
     
    public static void main(String[] args)
    {

        new Contains().run();
    }
 
    private void run()
    {

        // Create and initialize an rtree
        SpatialIndex si = new RTree();
        si.init(null);
 
        // We have some points or rectangles in some other data structure.
        // The rtree can handle millions of these.
        Rectangle[] rects = new Rectangle[] { new Rectangle(0, 0, 0, 0),
                new Rectangle(0, 1, 0, 1), new Rectangle(1, 0, 1, 0),
                new Rectangle(1, 1, 1, 1), 
                new Rectangle(0.0f, 0.25f, 0.5f, 0.75f),
                };
 
        // Add our data to the rtree. Every time we add a rectangle we give it
        // an ID. This ID is what is returned by querying the rtree. In this
        // example we use the array index as the ID.
        for (int i = 0; i < rects.length; i++)
        {

            si.add(rects[i], i);
        }
 
        // Now see which of these points is contained by some
        // other rectangle. The rtree returns the results of a query
        // by calling the execute() method on a TIntProcedure.
        // In this example we want to save the results of the query
        // into a list, so that's what the execute() method does.
        class SaveToListProcedure implements TIntProcedure
        {
http://www.huiyi8.com/bgm/
            private List<Integer> ids = new ArrayList<Integer>();
 
            @Override
            public boolean execute(int id)
            {

                ids.add(id);
                return true;
            };
 
            private List<Integer> getIds()
            {

                return ids;
            }
        }
        ;
 
        SaveToListProcedure myProc = new SaveToListProcedure();
        si.contains(new Rectangle(-0.5f, -0.5f, 1.5f, 0.5f), myProc);
 
         
        SaveToListProcedure insectMyProc = new SaveToListProcedure();
        si.intersects(new Rectangle(-0.5f, -0.5f, 1.5f, 0.5f), insectMyProc);
         
        List<Integer> intersectIds = insectMyProc.getIds();
         
        for (Integer integer : intersectIds)
        {

            logger.info(rects[integer].toString() + "was intersected!");
        }
         
    }
}

转载于:https://www.cnblogs.com/xkzy/p/3915025.html

你可能感兴趣的文章
神经网络可以拟合任意函数的视觉证明A visual proof that neural nets can compute any function...
查看>>
人脸识别必读的N篇文章
查看>>
testbench——文件读入输出
查看>>
我理解的objective-C内存管理
查看>>
java-多态的向上向下转型
查看>>
STL:原地归并排序模板(InplaceMergeSort)
查看>>
uva1252
查看>>
C++ 引用
查看>>
Storm starter - Overview
查看>>
linux ftp、sftp、telnet服务开通、更改Orale最大连接数
查看>>
POJ3304(KB13-C 计算几何)
查看>>
Web Worker javascript多线程编程(二)
查看>>
ajaxUploadFile在IE9等IE浏览器,上传变json下载的问题解决(SpringMVC + ajaxUploadFile)...
查看>>
虚拟机Vmware安装CentOS7.x
查看>>
android-检测耳机的插入和拔出动作
查看>>
关于Bin文件的解析
查看>>
mysql参数优化
查看>>
three.js中合并多个BufferGeometry类型的模型
查看>>
什么是编程范式
查看>>
linux虚拟化课堂总结图2019_4_23
查看>>