首页 > 解决方案 > 具有空间数据的四叉树

问题描述

我正在使用由Ryan Pelletier 在 Github 上的 java-simple-quadtree 实现的四叉树来读取纬度和经度的空间数据,并且它们没有被插入到树中。这是我的数据:

-73.807029724121094,40.699657440185547

这是 QuadTree 类的搜索功能

private List<RectangleObject> search(List<RectangleObject> rectangleObjects, RectangleObject rectangleObject){

        rectangleObjects.addAll(this.rectangleObjects);

        int index = getChildIndexRectangleBelongsIn(rectangleObject);
        //if the search area does not fit into any of the children perfectly
        if(index == QuadTree.THIS_QUADTREE || this.children[0] == null){
            //add anything that is on this QuadTree, may need to recurse down and add more
            if(this.children[0] != null){
                //for each of the children, if the search area overlaps with the child area, search the child
                for(int i = 0; i < this.children.length; i++){
                    if(GeometryUtil.rectangleObjectsOverlap(new SearchRectangleObject(Double.valueOf(this.children[i].getX()), Double.valueOf(this.children[i].getY()),Double.valueOf(this.children[i].getW()), Double.valueOf(this.children[i].getH())), rectangleObject)){
                        this.children[i].search(rectangleObjects, rectangleObject);
                    }
                }
            }
        }else if(this.children[index] != null){
            //search area is in one of the children totally, but we still can't exclude the objects on this node, because that search area could include one
            this.children[index].search(rectangleObjects, rectangleObject);
        }
        return rectangleObjects;
    }

标签: javaspatialquadtree

解决方案


推荐阅读