Postgis 匯入大檔案的 raster

postgis 在 2.0 版以後支援的 raster 的格式,可以透過 raster2pgsql 來轉成 postgis format,但如果 raster 檔案很大,出現記憶體不足的問題時,如

$ psql -d vegetation -f twdtm_asterv2_30m-tm2_twd97.sql 

BEGIN
psql:twdtm_asterv2_30m-tm2_twd97.sql:2: NOTICE: CREATE TABLE will create implicit sequence "twdtm_asterv2_30m-tm2_twd97_rid_seq" for serial column "twdtm_asterv2_30m-tm2_twd97.rid"
psql:twdtm_asterv2_30m-tm2_twd97.sql:2: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "twdtm_asterv2_30m-tm2_twd97_pkey" for table "twdtm_asterv2_30m-tm2_twd97"
CREATE TABLE
psql:twdtm_asterv2_30m-tm2_twd97.sql:5: ERROR: out of memory
DETAIL: Cannot enlarge string buffer containing 1073741808 bytes by 8191 more bytes.
CONTEXT: COPY twdtm_asterv2_30m-tm2_twd97, line 1
psql:twdtm_asterv2_30m-tm2_twd97.sql:6: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:twdtm_asterv2_30m-tm2_twd97.sql:7: ERROR: current transaction is aborted, commands ignored until end of transaction block
ROLLBACK

此時可以啟用 tile 選項 (-t 寬x高) 來裁切成更小的 size ,如 100x100 就是切成寬 100 個、高 100 個小尺寸的 raster: (-s 3826 代表 EPSG:3826 座標系統, -I 代表建立空間索引, -Y 代表用 COPY 的方式取代 INSERT 的 SQL 指令匯入資料 

$ raster2pgsql -s 3826 -t 100x100 -I -Y twdtm_asterv2_30m-tm2_twd97.tif > twdtm.sql

參考資料:

http://postgis.refractions.net/docs/using_raster.xml.html

Comments

comments powered by Disqus