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

我可能没有正确创建信封。有谁知道如何指定这些信封尺寸的详细信息?

最佳答案

您实例化了Envelope错误,这不是Envelope(minX, minY, maxX, maxY)而是Envelope(minX, maxX, minY, maxY)

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

看看Envelope文档here

10-07 21:56