美文网首页webGIS
Rbush和strtree前端简单应用

Rbush和strtree前端简单应用

作者: polong | 来源:发表于2020-06-15 12:54 被阅读0次

        空间相交是gis中常用的功能,一般就是使用分析库进行相交就可以了,但是多数据时这样产生笛卡尔积计算效率低下,这时可以考虑使用索引,本文中要介绍的是r-tree的使用。

        R树是一棵平衡树。树上有两类结点:叶子结点和非叶子结点。每一个结点由若干个索引项构成。对于叶子结点,索引项形如(Index,Obj_ID)。其中,Index表示包围空间数据对象的最小外接矩形MBR,Obj_ID标识一个空间数据对象。对于一个非叶子结点,它的索引项形如(Index,Child_Pointer)。 Child_Pointer 指向该结点的子结点。Index仍指一个矩形区域,该矩形区域包围了子结点上所有索引项MBR的最小矩形区域。

        jsts的STRtree创建,插入数据,查询

    let strtree=new jsts.index.strtree.STRtree()
    const extent=item.getExtent()
    strtree.insert(new jsts.geom.Envelope(extent.xmin, extent.xmax, extent.ymin, extent.ymax), count)
    let re=strtree.query(new jsts.geom.Envelope(x, x+0.01, y, y+0.01))
    

        rbush的创建插入数据查询

    const  tree = new RBush();
    const extent=item.getExtent()
    const indexitem = {
          minX: extent.xmin,
          minY: extent.ymin,
          maxX: extent.xmax,
          maxY: extent.ymax,
          index:count
    };
    tree.insert(indexitem);
     let extent= {
          minX: x,
          minY: y,
          maxX: x+0.01,
          maxY: y+0.01
    }
    let mydata=tree.search(extent,test);
    

        两个索引的性能比较,224条相同的数据查询相同数据下rbush更高效一些

    RBush search STRtree search
    3.22ms 16.65ms

    rbush中递归查找相交的叶子节点或者包含节点部分

    search(bbox) {
            let node = this.data;
            const result = [];
    
            if (!intersects(bbox, node)) return result;
    
            const toBBox = this.toBBox;
            const nodesToSearch = [];
    
            while (node) {
                for (let i = 0; i < node.children.length; i++) {
                    const child = node.children[i];
                    const childBBox = node.leaf ? toBBox(child) : child;
    
                    if (intersects(bbox, childBBox)) {
                        if (node.leaf) result.push(child);
                        else if (contains(bbox, childBBox)) this._all(child, result);
                        else nodesToSearch.push(child);
                    }
                }
                node = nodesToSearch.pop();
            }
    
            return result;
    }
    

    参考资料:

    https://blog.csdn.net/cdl2008sky/article/details/18217327

    https://github.com/mourner/rbush

    https://github.com/bjornharrtell/jsts

    https://zhuanlan.zhihu.com/p/38597148

    https://www.cnblogs.com/yinchuanqi/p/5607696.html

    https://yq.aliyun.com/articles/322443

    https://blog.csdn.net/cdl2008sky/article/details/18217327

    https://www.cnblogs.com/naaoveGIS/p/6774549.html

    https://blog.csdn.net/dickwang1229/article/details/39160511

    https://www.jianshu.com/p/44d6281d1a01

    https://blog.csdn.net/wzf1993/article/details/79547037

    https://blog.csdn.net/MongChia1993/article/details/69941783#toc_6

    https://blog.csdn.net/chenyq2008/article/details/2140477

    https://www.cnblogs.com/arxive/p/8138586.html

    相关文章

      网友评论

        本文标题:Rbush和strtree前端简单应用

        本文链接:https://www.haomeiwen.com/subject/blvcxktx.html