R树库+如何运行

时间:2013-01-10 05:41:18

标签: java r

我有一个简单的问题

我想使用java netbeans(用于测试)运行R树的代码

现在我找到了这个R树https://sourceforge.net/projects/jsi/

的库

我能够添加库。但那又怎么样?我如何实际运行查询和插入..etc ??

任何人都可以帮助我。我是初学者

请帮忙

全部谢谢

2 个答案:

答案 0 :(得分:1)

以下是文件NearestN.java的摘录。还有Contains.java

package net.sourceforge.jsi.examples;

import org.slf4j.*;
import com.infomatiq.jsi.*;
import gnu.trove.*;

import com.infomatiq.jsi.Rectangle;
import com.infomatiq.jsi.rtree.RTree;

public class NearestN {
  private static final Logger log = LoggerFactory.getLogger(NearestN.class);

  public static void main(String[] args) {
    new NearestN().run();
  }

  private class NullProc implements TIntProcedure {
    public boolean execute(int i) {
      return true;
    }
  }

  private void run() {
    int rowCount = 1000;
    int columnCount = 1000;
    int count = rowCount * columnCount;
    long start, end;

    log.info("Creating " + count + " rectangles");
    final Rectangle[] rects = new Rectangle[count];
    int id = 0;
    for (int row = 0; row < rowCount; row++)
      for (int column = 0; column < rowCount; column++) {
        rects[id++] = new Rectangle(row, column, row+0.5f, column+0.5f); //
    }

    log.info("Indexing " + count + " rectangles");
    start = System.currentTimeMillis();
    SpatialIndex si = new RTree();
    si.init(null);
    for (id=0; id < count; id++) {
      si.add(rects[id], id);
    }

    final Point p = new Point(36.3f, 84.3f);
    log.info("Querying for the nearest 3 rectangles to " + p);
    si.nearestN(p, new TIntProcedure() {
      public boolean execute(int i) {
        log.info("Rectangle " + i + " " + rects[i] + ", distance=" + rects[i].distance(p));
        return true;
      }
    }, 3, Float.MAX_VALUE);
}

希望能帮助你一点点。

答案 1 :(得分:0)

moskito-x发布的代码来自jith-examples repo,由github托管。

您应该能够使用以下命令运行示例(在Linux上):

git clone https://github.com/aled/jsi-examples.git
cd jsi-examples
mvn package
cd target
unzip jsi-examples-1.0.0-SNAPSHOT-jar-with-dependencies.jar
java -cp .:./classes net.sourceforge.jsi.examples.Contains

源代码应该是自我解释的。

ALED。