在java中构建特定大小的信封对象?

时间:2015-02-17 21:14:15

标签: java repast-simphony

我有许多带有各种坐标的点对象(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。为什么这么大?

我可能无法正确创建信封。有没有人更多地了解如何指定这些信封尺寸的详细信息?

1 个答案:

答案 0 :(得分:1)

您设置了Envelope错误,它不是Envelope(minX, minY, maxX, maxY)而是Envelope(minX, maxX, minY, maxY)

Envelope的构造函数中,它会自动检查minX是否真的是最小值minXmaxX,否则它将交换minX和{ {1}}。实际上构造函数是maxX

查看Envelope(x1, x2, y1, y2)文档here