2015-02-17 43 views
0

我有許多點對象(n)與各種座標。 我有一個座標代理。在java中構建特定大小的包絡對象?

我想查找點a的某個距離內的所有點並將它們放入列表中。

public class Agent { 
    private Context<Object> context; 
    private Geography<Object> geography; 
    ... 

public Agent(Context<Object> context, Geography<Object> geography) { 
    this.context = context; 
    this.geography = geography; 
    } 

    ... 

public void step() { 

    //gets the coordinates of the agent, calls them coord 
    Context context = ContextUtils.getContext(this); 
    Geography<Agent> geography = (Geography)context.getProjection("Geography"); 
    Geometry geom = geography.getGeometry(this); 
    Coordinate coord = geom.getCoordinates()[0]; 

    //creates a list of called points 
    List<Object> points = new ArrayList<Object>(); 

    //creates an envelope object and creates envelope dimensions 
    Envelope envelope = new Envelope((coord.x + 0.0001, coord.y + 0.0001, coord.x - 0.001, coord.y - 0.001); 

    //for all objects within the envelope, if they are of the specific class type, add them to the list 
    for(Object obj: geography.getObjectsWithin(envelope, Specific.class)) { 
     trees.add(tree); 
    } 

    System.out.println("The number of objects in the envelope is : " + trees.size()); 

我的問題是:當我使用這些尺寸(在上面的代碼中)時,我在信封中得到了1342個對象。這大概是一個非常小的信封,應該包含最多200-300個信封。爲什麼這麼大?

這可能是我沒有正確創建信封。有誰知道更多關於如何指定這些信封尺寸的細節?

回答

1

你instanciate你的Envelope錯了,它不是Envelope(minX, minY, maxX, maxY)而是Envelope(minX, maxX, minY, maxY)

而且在Envelope構造函數,它會自動檢查是否minX真的是最小的速滑運動員的肌肉minXmaxX否則將交換minXmaxX。構造函數其實Envelope(x1, x2, y1, y2)

Envelope文檔here

看看