PostgreSQL , postgis , 栅格 , 波段 , st_value , raster , 优化 , st_intersects , gist 索引 , arcgis
栅格数据是由点阵组成的图像化数据,点阵具备空间属性(边界)。点阵由像素组成,所以每个像素也具备空间属性,同时每个像素内填充数值,数值可以代表温度、灰度、颜色系数、属性、湿度等等。
<a href="https://github.com/digoal/blog/blob/master/201802/20180226_06_pic_002.png" target="_blank"></a>
每个栅格中可以有多个波段,每个波段可以代表一个图层,多个波段可以组合叠加计算。

使用栅格数据,可以实现具备空间、业务属性的数据分析,可视化等。
例如热力图、绿化率图、道路、温度分布等等。
arcgis栅格数据组织形式:
由于栅格数据可大可小,当提取某个像素的VALUE时,可能会有一定的性能问题。
<a href="https://postgis.net/docs/RT_ST_Value.html">https://postgis.net/docs/RT_ST_Value.html</a>
当栅格文件非常大时,st_value可能要执行很长时间,虽然只提取一个像素的值。(此性能与栅格文件本身的数据组织,检索方法有关。)
<a href="http://postgis.net/docs/RT_ST_SetValue.html">http://postgis.net/docs/RT_ST_SetValue.html</a>
可以从arcgis或postgis的手册中,学习栅格的知识。
<a href="http://resources.arcgis.com/zh-cn/help/main/10.2/#/na/009t00000004000000/">http://resources.arcgis.com/zh-cn/help/main/10.2/#/na/009t00000004000000/</a>
<a href="http://resources.arcgis.com/zh-cn/help/main/10.2/index.html#//009t00000007000000">http://resources.arcgis.com/zh-cn/help/main/10.2/index.html#//009t00000007000000</a>
1、切割raster,将一个大的raster,切割为若干小的raster
2、边界转geometry, 建立边界的表达式索引
3、判断输入的geometry point是否与被查询raster相交(st_intersects),相交则求st_value,否则不计算st_value
4、当然,还有一种优化方法是对栅格文件本身建立较好的数据模型,便于快速检索。这种方法对业务透明
优化思路:
1、降低计算量,使用切割的方法。
2、降低计算量或IO放大,使用表达式索引。
3、降低精度,对raster进行分层,类似这样的思路
<a href="https://stackoverflow.com/questions/31799824/optimizing-st-intersects-in-postgresqlpostgis">https://stackoverflow.com/questions/31799824/optimizing-st-intersects-in-postgresqlpostgis</a>
<a href="http://postgis.17.x6.nabble.com/raster-loading-and-ST-Value-performance-td4999924.html">http://postgis.17.x6.nabble.com/raster-loading-and-ST-Value-performance-td4999924.html</a>
<a href="http://postgis.17.x6.nabble.com/ST-value-slow-td5010865.html">http://postgis.17.x6.nabble.com/ST-value-slow-td5010865.html</a>
<a href="http://resources.arcgis.com/zh-cn/help/main/10.2/#/na/009t00000005000000/">http://resources.arcgis.com/zh-cn/help/main/10.2/#/na/009t00000005000000/</a>
<a href="http://postgis.net/docs/manual-2.4/RT_reference.html">http://postgis.net/docs/manual-2.4/RT_reference.html</a>
<a href="https://github.com/digoal/blog/blob/master/201711/20171122_03.md">《PostgreSQL multipolygon 空间索引查询过滤精简优化 - IO,CPU放大优化》</a>
<a href="https://github.com/digoal/blog/blob/master/201710/20171005_01.md">《PostgreSQL 空间切割(st_split, ST_Subdivide)功能扩展 - 空间对象网格化 (多边形GiST优化)》</a>
<a href="https://github.com/digoal/blog/blob/master/201710/20171004_01.md">《PostgreSQL 空间st_contains,st_within空间包含搜索优化 - 降IO和降CPU(bound box) (多边形GiST优化)》</a>