2013-01-10 44 views

回答

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

希望可以幫助您一點點。

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 

的源代碼應該有希望是自解釋的。

Aled。