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

Building an envelope object of a particular size in java?

我有许多具有不同坐标的点对象 (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