1

我有一个简单的问题

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

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

我能够添加库。但是然后呢??我如何实际运行查询和插入..等?

谁能帮我解决这个问题。我是初学者

请帮忙

谢谢大家

4

2 回答 2

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);
}

希望对您有所帮助。

于 2013-01-10T06:39:45.920 回答
0

moskito-x 发布的代码来自托管在 github 上的 jsi-examples 存储库。

您应该能够使用以下命令(在 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

源代码应该是不言自明的。

阿莱德。

于 2013-01-10T22:56:37.037 回答