在ArcMap或各類前端地圖框架(Leaflet.js、OpenLayers.js、ArcGIS Javascript等)中都需要加載WMTS或ArcGIS Rest服務,但所有的地圖顯示的原理基本上都是通過坐標和每張瓦片的分辨率來計算行列號的,但WMTS服務標准中其實是沒有分辨率Resolution這個參數的,他只給出了比例尺“ScaleDenominator”這個值,需要用戶根據這個比例尺自己計算出分辨率。(參考下圖,為同一個瓦片服務的Rest服務和WMTS服務)
REST:http://basemap.nationalmap.gov/arcgis/rest/services/USGSTopo/MapServer
但在ArcGIS Rest服務中你會發現服務的Lod信息里是同時給出了比例尺“Scale”和分辨率“Resolution”值了的。有心讀者讀到這里和看到下面的圖片時,應該會有兩個疑惑。
- Resolution和Scale的計算公式是什么?
- 為什么同一份已經切好了的瓦片,在ArcGIS Rest服務和WMTS服務的比例尺不一樣?
一、Scale和 Resolution的計算公示
案例一:如果地圖的坐標單位是米,dpi為96
參考: https://blog.csdn.net/redsky200905/article/details/84369213
1英寸=2.54厘米;
1英寸=96像素;
最終換算的單位是米;
如果當前地圖比例尺為1:125000000,則代表圖上1米實地125000000米;
米和像素間的換算公式:
1英寸=0.0254米=96像素
1像素=0.0254/96 米
則根據1:125000000比例尺,圖上1像素代表實地距離是 125000000*0.0254/96 = 33072.9166666667米。
以上圖第0級為例,比例尺為 Scale=591657527.591555,Resolution=156543.03392800014
591657527.591555*0.0254/96 =156,542.7208419323
591657527.591555*0.0254000508/96 =156,543.0339273739
我們這個換算結果和切片的結果略微有0.07米的誤差。這個誤差產生的原因是英寸換算厘米的參數決定的,server使用的換算參數1英寸約等於0.0254000508米。
關於1英寸單位換算有以下文獻說明
參考:http://scienceworld.wolfram.com/physics/Inch.html
An nonmetric unit of length, originally defined as the lengths of three "average size" barleycorns laid end-to-end, but now more rationally defined as 2.54 cm. An older definition no longer used was 1 meter= 39.37 inches, giving 2.54000508 cm/inch.
12 inches are called 1 foot.
案例二:如果地理坐標系是wgs84,地圖的單位是度,dpi為96
Server中度和米之間的換算參數: 1 度約等於 111194.872221777 米
接下來就需要進行度和像素間的換算:
當比例尺為1:64000000米時,相當於1像素 = 64000000*0.0254000508/96 = 16933.3672米,再將米轉換為度 16933.3672/ 111194.872221777 = 0.1522855043731385 度
因此當地圖單位為度時,近似計算在1:64000000 對應的Resolution為0.1522855043731385度。
二、WMTS服務中的Scale和ArcGIS Rest服務中不一樣的原因
最核心的原因是因為DPI計算方式不一樣!!!
WMTS assumes a DPI 90.7 instead of 96 as is clearly documented in the WMTSCapabilities document which states,
"The tile matrix set that has scale values calculated based on the dpi defined by OGC specification (dpi assumes 0.28mm as the physical distance of a pixel)."
0.28 mm per pixel = 0.0110236 inches per pixel or 90.71446714322 pixels per inch.
If you replace 96 in the equation above with 90.71428571429 you'll get the ScaleDenominator value so ESRI used a different conversion constant. After a little research I learned that
1 in = 2.54 cm (I thought this was an approximation but it's by definition)
Since there are 25.4 mm in one inch then 25.4 / .28 = 90.71428571429 DPI which is the value we're after for DPI. Here is a site which confirms this calculation.
繼續以第一圖為例:
559082264.0285016 * 0.00028 = 156,543.0339279804,這樣計算的結果就和ArcGIS Rest中的差不多保持一致了。
參考文獻: