2014-01-22 5 views
0

Java Spatial Index Library을 사용하려고 시도하지만로드하려면 examples을 가져올 수 없습니다.TIntProcedure를 확인할 수 없습니다.

package net.sourceforge.jsi.examples; 

import gnu.trove.*; 

import java.util.ArrayList; 
import java.util.List; 

import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 

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

public class Contains { 
    private static final Logger log = LoggerFactory.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), 
    }; 

    // 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 { 
     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); 

    List<Integer> ids = myProc.getIds(); 

    for (Integer id : ids) { 
     log.info(rects[id].toString() + " was contained"); 
    } 

    // Actually that was a really long winded (and inefficient) way of 
    // printing out the rectangles. Would be better to use an anonymous 
    // class to just do the printing inside the execute method. That is 
    // what the NearestN class does. 
    } 
} 

TIntProceduregnu trove 패키지로 나타나지만 :

이클립스 케플러의 예제에서 다음 파일을 열려고

는 이클립스에 대한 TIntProcedure가 해결 될 수 없다는 불평 TIntProcedure 인터페이스는 실제로 gnu.trove.procedure에 정의되어 있으며 gnu.trove에 정의되어 있지 않습니다.

내가 잘못 사용하고 있습니까 TIntProcedure? Eclipse는 SaveToListProcedure 선언과 함께 문제가 없지만 si.contains(new Rectangle(-0.5f, -0.5f, 1.5f, 0.5f), myProc) 경고가 표시됩니다. 나는 이클립스가 잘못된 오류를 던지는 경우 단지보고, 어쨌든 프로젝트를 실행하려고했으나 그것으로 오류 아웃 : main이 정의된다

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

    at net.sourceforge.jsi.examples.Contains.main(Contains.java:18) 

라인 (18)입니다.

답변

2

JSI는 Trove 2.0.2를 사용하고 있습니다. 3.x까지 TIntProcedure를 해당 패키지로 옮기지 않았습니다. 패키지를 다운 그레이드하면 명시 적으로 나를 위해 일했습니다.

+0

죄송합니다. 답변을 놓치 셨습니다. 도와 주셔서 감사합니다! –

0

maven으로 빌드하지 않은 경우 현재 trove4j 버전 2.0.2가 필요합니다. JSI (버전 1.1)의 다음 버전은 3.0.3 버전 (master 브랜치는 얼마 전에 업데이트 됨)에 의존 할 것이다. R tree library + how to run

Aled :

는 또한 JSI 예제를 실행에 대한 자세한 지침은이 질문에 대한 내 대답에서 사용할 수 있습니다주의.