空間插值,這是通過離散點表徵區域特徵值的一種方式,空間插值具體的概念及原理請自己百度。實驗中對某一時刻的數據進行插值,我們可以使用ArcMap中的工具進行手動處理。但是項目中使用的空間插值,如對每分鐘/小時/天的AQI數據進行插值,就不可能手動進行處理了,這時需要考慮開發插值服務解決問題。
空間插值屬於GIS的範圍,GIS中常見的解決方案包括開源和商業,其中GDAL和ArcGIS分別是各自的優秀代表,下面就對GDAL和ArcGIS空間插值進行說明。
1、GDAL空間插值(以python爲例https://gdal.org/python/)
(1)GDAL中進行空間插值的函數是 Grid,下面是官網對其介紹:
Grid(destName, srcDS, **kwargs)
Create raster from the scattered data.
Arguments are :
destName --- Output dataset name
srcDS --- a Dataset object or a filename
Keyword arguments are :
options --- return of gdal.GridOptions(), string or array of strings
other keywords arguments of gdal.GridOptions()
If options is provided as a gdal.GridOptions() object, other keywords are ignored.
它的參數包括:
destName:輸出數據集(一般爲tif文件)的路徑(包括文件名);
srcDS:輸入數據集對象或文件名稱,可以使用OpenEx打開geojson格式的數據,或使用Open打開shapefile或直接輸入shapefile路徑;
**kwargs:插值參數,可以使用 key = value 關鍵字參數的形式進行設置,也可以使用 option = GridOptions()的形式進行一次性設置,
(2)下面對GridOptions的內容進行說明:
GridOptions(options=[], format=None, outputType=GDT_Unknown, width=0, height=0, creationOptions=None, outputBounds=None, outputSRS=None, noData=None, algorithm=None, layers=None, SQLStatement=None, where=None, spatFilter=None, zfield=None, z_increase=None, z_multiply=None, callback=None, callback_data=None)
Create a GridOptions() object that can be passed to gdal.Grid()
Keyword arguments are :
options --- can be be an array of strings, a string or let empty and filled from other keywords.
format --- output format ("GTiff", etc...)
outputType --- output type (gdal.GDT_Byte, etc...)
width --- width of the output raster in pixel
height --- height of the output raster in pixel
creationOptions --- list of creation options
outputBounds --- assigned output bounds: [ulx, uly, lrx, lry]
outputSRS --- assigned output SRS
noData --- nodata value
algorithm --- e.g "invdist:power=2.0:smoothing=0.0:radius1=0.0:radius2=0.0:angle=0.0:max_points=0:min_points=0:nodata=0.0"
layers --- list of layers to convert
SQLStatement --- SQL statement to apply to the source dataset
where --- WHERE clause to apply to source layer(s)
spatFilter --- spatial filter as (minX, minY, maxX, maxY) bounding box
zfield --- Identifies an attribute field on the features to be used to get a Z value from. This value overrides Z value read from feature geometry record.
z_increase --- Addition to the attribute field on the features to be used to get a Z value from. The addition should be the same unit as Z value. The result value will be Z value + Z increase value. The default value is 0.
z_multiply - Multiplication ratio for Z field. This can be used for shift from e.g. foot to meters or from elevation to deep. The result value will be (Z value + Z increase value) * Z multiply value. The default value is 1.
callback --- callback method
callback_data --- user data for callback
GridOptions中的參數,需要以 key=value 關鍵字參數的形式進行設置,基本的參數包括:
format(輸出文件格式)、outputType(輸出數據類型,如字節GDT_Byte、32位浮點型gdal.GDT_Float32等)、width和height(輸出柵格寬度和高度)、outputBounds(插值範圍)、outputSrs(輸出座標系)、noData(沒有值的標記)、algorithm(插值算法,下面會做詳細介紹)、SQLStatement(通過sql語句對輸入數據進行過濾)、where(通過條件對參與插值的數據進行過濾)、zfield(插值字段。如aqi、co等)、z_increase和z_multiply()對插值字段進行處理的算子),callback(插值完成後的回調函數)、callback_data(回調函數的用戶數據)。
(3)插值算法
最常用的是 反距離權重算法,下面對該算法的參數進行說明:
'invdist:power=3.6:smoothing=0.2:radius1=0.0:radius2=0.0:angle=0.0:max_points=0:min_points=0:nodata=0.0'
invdist表示算法名稱 - 反距離權重,即距離越近權重越大,對待計算的網格影像越大;
power 距離對權重的影響程度)(數字表示指數),默認值爲2, 值越大表示距離越近的點對插值的影響程指數倍增;對於該參數的設置,若點較密集且均勻分佈,則值設置在2以下,若點相對較少且分佈不均,則爲了保障插值效果,可將參數設置在3以上;
smoothing 平滑係數,默認爲0,數值越大表示越平滑,同時精度也會越低。
radius1 表示橢圓x軸方向上的半徑;
radius2 表示橢圓y軸方向上的半徑;
angle 表示橢圓旋轉的弧度;
max_points 表示參與插值的最大點數,默認值0表示搜索到多少就是多少;
min_points 表示參與插值的最小點數,默認值0表示搜索到多少就是多少;
nodata 對nodata的填充值。
2、ArcGIS空間插值(以ArcPy爲例說明)
下次再進行補充...