备注
Go to the end 下载完整的示例代码。
在任意投影上复制WMSG拼贴地图数据#
此示例在两个不同的投影上显示来自Web地图切片服务的影像,其中一个投影不是由该服务提供的。
此结果还可以交互式地平移和缩放。
示例WMSG层是2012年4月9天和2012年10月13天内采样的数据的单一组合,显示了地球的夜间情况。它不会随着时间的推移而变化。
该图像由美国国家海洋和大气管理局(NOAA)运营的Suomi国家极轨合作伙伴关系(Suomi NPP)气象卫星收集。

/xpy/lib/python3.13/site-packages/owslib/wmts.py:861: FutureWarning: Truth-testing of elements was a source of confusion and will always return True in future versions. Use specific 'len(elem)' or 'elem is not None' test instead.
if current and current.text == 'true':
/xpy/lib/python3.13/site-packages/owslib/wmts.py:658: RuntimeWarning: TileMatrixLimits with tileMatrix "1" already exists
warnings.warn(msg, RuntimeWarning)
/xpy/lib/python3.13/site-packages/owslib/wmts.py:658: RuntimeWarning: TileMatrixLimits with tileMatrix "2" already exists
warnings.warn(msg, RuntimeWarning)
/xpy/lib/python3.13/site-packages/owslib/wmts.py:658: RuntimeWarning: TileMatrixLimits with tileMatrix "3" already exists
warnings.warn(msg, RuntimeWarning)
/xpy/lib/python3.13/site-packages/owslib/wmts.py:658: RuntimeWarning: TileMatrixLimits with tileMatrix "4" already exists
warnings.warn(msg, RuntimeWarning)
/xpy/lib/python3.13/site-packages/owslib/wmts.py:658: RuntimeWarning: TileMatrixLimits with tileMatrix "5" already exists
warnings.warn(msg, RuntimeWarning)
/xpy/lib/python3.13/site-packages/owslib/wmts.py:658: RuntimeWarning: TileMatrixLimits with tileMatrix "6" already exists
warnings.warn(msg, RuntimeWarning)
/xpy/lib/python3.13/site-packages/owslib/wmts.py:861: FutureWarning: Truth-testing of elements was a source of confusion and will always return True in future versions. Use specific 'len(elem)' or 'elem is not None' test instead.
if current and current.text == 'true':
/xpy/lib/python3.13/site-packages/owslib/wmts.py:658: RuntimeWarning: TileMatrixLimits with tileMatrix "1" already exists
warnings.warn(msg, RuntimeWarning)
/xpy/lib/python3.13/site-packages/owslib/wmts.py:658: RuntimeWarning: TileMatrixLimits with tileMatrix "2" already exists
warnings.warn(msg, RuntimeWarning)
/xpy/lib/python3.13/site-packages/owslib/wmts.py:658: RuntimeWarning: TileMatrixLimits with tileMatrix "3" already exists
warnings.warn(msg, RuntimeWarning)
/xpy/lib/python3.13/site-packages/owslib/wmts.py:658: RuntimeWarning: TileMatrixLimits with tileMatrix "4" already exists
warnings.warn(msg, RuntimeWarning)
/xpy/lib/python3.13/site-packages/owslib/wmts.py:658: RuntimeWarning: TileMatrixLimits with tileMatrix "5" already exists
warnings.warn(msg, RuntimeWarning)
/xpy/lib/python3.13/site-packages/owslib/wmts.py:658: RuntimeWarning: TileMatrixLimits with tileMatrix "6" already exists
warnings.warn(msg, RuntimeWarning)
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
def plot_city_lights():
# Define resource for the NASA night-time illumination data.
base_uri = 'https://map1c.vis.earthdata.nasa.gov/wmts-geo/wmts.cgi'
layer_name = 'VIIRS_CityLights_2012'
# Create a Cartopy crs for plain and rotated lat-lon projections.
plain_crs = ccrs.PlateCarree()
rotated_crs = ccrs.RotatedPole(pole_longitude=120.0, pole_latitude=45.0)
fig = plt.figure()
# Plot WMTS data in a specific region, over a plain lat-lon map.
ax = fig.add_subplot(1, 2, 1, projection=plain_crs)
ax.set_extent([-6, 3, 48, 58], crs=ccrs.PlateCarree())
ax.coastlines(resolution='50m', color='yellow')
ax.gridlines(color='lightgrey', linestyle='-')
# Add WMTS imaging.
ax.add_wmts(base_uri, layer_name=layer_name)
# Plot WMTS data on a rotated map, over the same nominal region.
ax = fig.add_subplot(1, 2, 2, projection=rotated_crs)
ax.set_extent([-6, 3, 48, 58], crs=ccrs.PlateCarree())
ax.coastlines(resolution='50m', color='yellow')
ax.gridlines(color='lightgrey', linestyle='-')
# Add WMTS imaging.
ax.add_wmts(base_uri, layer_name=layer_name)
plt.show()
if __name__ == '__main__':
plot_city_lights()
Total running time of the script: (0 minutes 17.340 seconds)
Gallery generated by Sphinx-Gallery
_