0

我有许多具有各种坐标的点对象(n)。我有一个有坐标的代理。

我想找到点 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 个。为什么做这么大一个?

我可能没有正确创建信封。有谁知道更多关于如何指定这些信封尺寸的细节?

4

1 回答 1

1

你实例化你的Envelope错误,不是Envelope(minX, minY, maxX, maxY)但是Envelope(minX, maxX, minY, maxY)

并且在 的构造函数中Envelope,它会自动检查是否minX真的是最小的minXmaxX否则它会交换minXmaxX。构造函数实际上是Envelope(x1, x2, y1, y2)

看看这里Envelope的文档

于 2015-02-17T21:24:16.423 回答