具有空间数据的java四叉树

zbwhf8kr  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(269)

我在github上使用ryan pelletier的java简单四叉树实现的四叉树来读取纬度和经度的空间数据,而它们没有被插入到树中。这是我的数据:

-73.807029724121094,40.699657440185547

这是四叉树类的搜索函数

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;
    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题