R:WMS 地图未显示

R: WMS map not showing up

我有这个 WMS 图层:

http://apps.ecmwf.int/wms/?token=public&version=1.3.0&request=GetMap&layers=composition_bbaod550

我想将它添加到传单地图,但它没有显示。 这是我的代码:

library("leaflet")
library("sp")

leaflet() %>% addTiles() %>% setView(0, 50, zoom = 1) %>%
  addWMSTiles("http://apps.ecmwf.int/wms/?token=public&version=1.3.0&request=GetMap", 
  layers = "composition_bbaod550", 
  options = WMSTileOptions(format = "image/png", transparent = TRUE))

我做错了什么?

编辑#1:

这是来自开发者控制台的网络请求的样子

编辑#2:

这是我根据 IvanSanchez 的建议编写的代码。如您所见,建议的方法没有解决问题

library("leaflet")
library("sp")

leaflet() %>% addTiles() %>% setView(0, 50, zoom = 1) %>%
  addWMSTiles("http://apps.ecmwf.int/wms/", 
  layers = "composition_bbaod550", 
  options = WMSTileOptions(token = "public",
                           srs = "EPSG:4326",
                           format = "image/png", 
                           transparent = TRUE))

不要在基础 WMS URL 中包含 versionrequest 参数。这些是由 Leaflet 在内部添加的。 Leaflet 需要 base WMS URL,如 http://leafletjs.com/examples/wms/wms.html.

中所述

所以不用

  addWMSTiles("http://apps.ecmwf.int/wms/?token=public&version=1.3.0&request=GetMap", 

  addWMSTiles("http://apps.ecmwf.int/wms/?token=public&", 

此外,引用自 Leaflet WMS tutorial

L.TileLayer.WMS has extra options, which can be found in Leaflet’s API documentation. Any option not described there will be passed to the WMS server in the getImage URLs.

所以你实际上可以做到

  addWMSTiles("http://apps.ecmwf.int/wms/", 
  layers = "composition_bbaod550", 
  options = WMSTileOptions(token = "public", format = "image/png", transparent = TRUE))

如果失败,请在网络浏览器中使用开发者控制台(按 F12)并查看网络请求。对 WMS 的请求是什么样的?


编辑:

经过一点点调试,似乎 WMS 服务器正在响应:

<!DOCTYPE ServiceExceptionReport SYSTEM "/static/frontend/contrib/exception_1_1_1.dtd">

<ServiceExceptionReport version="1.1.1">
<ServiceException code='InvalidSRS'><![CDATA[
Unsupported projection 'EPSG:3857'
]]>

</ServiceException>
</ServiceExceptionReport>

这意味着 WMS 服务器无法输出适合 Leaflet 默认地图投影的图像。

如果您想使用此 WMS 服务器,您必须从其 GetCapabilities 文档中查看支持的地图投影列表,并使用 Proj4Leaflet 使地图使用与默认投影不同的投影。

请阅读:

很抱歉没有直接的答案;您将需要做一些工作并了解投影。

如果我们如下向WMS服务发出GetCapabilities请求,我们可以看到支持的最高WMS版本是1.1.1。所以你的 GetMap 请求 version=1.3.0 WMS 服务可能会出错。

http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities&

当我查看响应时,它似乎有一些错误,事实上,当我检查我的 XML 编辑器时,有很多错误(错误太多以至于日志超出了此答案中允许的字符限制).

WMS 配置错误:

System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Attribute "xlink:execution" is not allowed to appear in element "OnlineResource".
Start location: 44:17
End location: 44:54

System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Unexpected element "SRS". The content of the parent element type must match "(Name?,Title,Abstract?,KeywordList?,SRS*,LatLonBoundingBox?,BoundingBox*,Dimension*,Extent*,Attribution?,AuthorityURL*,Identifier*,MetadataURL*,DataURL*,FeatureListURL*,Style*,ScaleHint?,Layer*)".
Start location: 97:8
End location: 97:11

System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Unexpected element "SRS". The content of the parent element type must match "(Name?,Title,Abstract?,KeywordList?,SRS*,LatLonBoundingBox?,BoundingBox*,Dimension*,Extent*,Attribution?,AuthorityURL*,Identifier*,MetadataURL*,DataURL*,FeatureListURL*,Style*,ScaleHint?,Layer*)".
Start location: 122:10
End location: 122:13

System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Attribute "multipleValues" is not allowed to appear in element "Extent".
Start location: 137:60
End location: 137:78

System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Unexpected element "SRS". The content of the parent element type must match "(Name?,Title,Abstract?,KeywordList?,SRS*,LatLonBoundingBox?,BoundingBox*,Dimension*,Extent*,Attribution?,AuthorityURL*,Identifier*,MetadataURL*,DataURL*,FeatureListURL*,Style*,ScaleHint?,Layer*)".
Start location: 273:10
End location: 273:13

System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Attribute "multipleValues" is not allowed to appear in element "Extent".
Start location: 288:60
End location: 288:78

System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Unexpected element "SRS". The content of the parent element type must match "(Name?,Title,Abstract?,KeywordList?,SRS*,LatLonBoundingBox?,BoundingBox*,Dimension*,Extent*,Attribution?,AuthorityURL*,Identifier*,MetadataURL*,DataURL*,FeatureListURL*,Style*,ScaleHint?,Layer*)".
Start location: 393:10
End location: 393:13

...

SRS / LatLonBoundingBox / BoundingBox 部分应如下所示(结构,而非内容):

<SRS>CRS:84</SRS>
<SRS>EPSG:27700</SRS>
<SRS>EPSG:3034</SRS>
<SRS>EPSG:3413</SRS>
<SRS>EPSG:3857</SRS>
<SRS>EPSG:4258</SRS>
<SRS>EPSG:4326</SRS>
<SRS>EPSG:900913</SRS>
<LatLonBoundingBox minx="-10.8018" miny="49.5889" maxx="3.92104" maxy="61.1359" />
<BoundingBox SRS="CRS:84"
            minx="-10.8018" miny="49.5889" maxx="3.92104" maxy="61.1359" />
<BoundingBox SRS="EPSG:27700"
            minx="-235677" miny="-34616" maxx="827937" maxy="1.28234e+006" />
<BoundingBox SRS="EPSG:3034"
            minx="2.5664e+006" miny="2.55843e+006" maxx="3.67848e+006" maxy="3.94271e+006" />
<BoundingBox SRS="EPSG:3413"
            minx="1.79406e+006" miny="-3.77262e+006" maxx="3.43831e+006" maxy="-2.09742e+006" />
<BoundingBox SRS="EPSG:3857"
            minx="-1.20245e+006" miny="6.37538e+006" maxx="436488" maxy="8.6571e+006" />
<BoundingBox SRS="EPSG:4258"
            minx="-10.8018" miny="49.5889" maxx="3.92104" maxy="61.1359" />
<BoundingBox SRS="EPSG:4326"
            minx="-10.8018" miny="49.5889" maxx="3.92104" maxy="61.1359" />
<BoundingBox SRS="EPSG:900913"
            minx="-10.8018" miny="49.5889" maxx="3.92104" maxy="61.1359" />

所以服务肯定没有配置正确,这可能是您遇到任何问题的根本原因。