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>