栅格处理(杂):添加空间索引显著加快矢量定位及运算

这几天在处理格网内点统计(面上的点),缓冲区内统计等,会遇到特别慢的情况,这时候对点图层添加==空间索引==(几秒完成)之后,再进行处理,从几十分钟的操作降至十几秒。

空间索引是一种允许有效访问空间对象的数据结构。这是空间数据库常用的技术。如果没有索引,任何对特征的搜索都需要对数据库中的每条记录进行“顺序扫描”,从而导致处理时间更长。在空间索引构建过程中,最小外接矩形作为对象的近似。跨商业和开源数据库的各种类型的空间索引产生可衡量的性能差异。空间索引技术在时间关键型应用程序和空间大数据处理中发挥着核心作用。

小数据影响不大,主要是量大些的数据

  1. 如果是使用==ArcGIS或Pro==,使用Add Spatial Index工具完成快速定位和汇总统计。描述:Adds a spatial index to a shapefile, file geodatabase, or enterprise geodatabase feature class. Use this tool to either add a spatial index to a shapefile or feature class that does not already have one or to re-create an existing spatial index。ArcGIS uses spatial indexes to quickly locate features in feature classes. Identifying a feature, selecting features by pointing or dragging a box, and panning and zooming all require ArcMap to use the spatial index to locate features.
  2. 如果是使用==QGIS==,工具名称是创建空间索引(Create Spatial Index)
  3. 如果使用==Geopandas==,它也提供了基于树结构的索引,构建索引的时间基本上为0ns,在使用空间连接的时候会用到,但通常geopandas在执行空间连接时,会自动构建所需的索引。
1
2
3
4
5
6
>>> df = gpd.read_file("..shp")
>>> df.has_sindex
False
>>> rst.sindex
>>> rst.has_sindex
True

更多比较,可以查看ref