zoukankan      html  css  js  c++  java
  • RTree算法Java实现 JSI RTree Library的调用实例 标签:jsi-rtree-library

    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/clxgt/窗帘效果图
                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!");
            }
             
        }
    }

  • 相关阅读:
    n个元素进栈,有几种出栈方式
    The following IP can be used to access Google website
    一个未排序整数数组,有正负数,重新排列使负数排在正数前面,并且要求不改变原来的 相对顺序 比如: input: 1,7,-5,9,-12,15 ans: -5,-12,1,7,9,15 要求时间复杂度O(N),空间O(1) 。
    当今世界最受人们重视的十大经典算法
    指针
    变量作用域和生存期
    一篇文章搞清spark内存管理
    Spark的Shuffle是怎么回事
    一篇文章搞清spark任务如何执行
    scala这写的都是啥?一篇文章搞清柯里化
  • 原文地址:https://www.cnblogs.com/xkzy/p/3920044.html
Copyright © 2011-2022 走看看