Python Tutorial | The most standard way of calling maps (data provided by the National Bureau of Surveying and Mapping)

Sky Map is a comprehensive geographic information service website built by the National Geographic Information Bureau, and is the public version of the National Geographic Information Public Service Platform.
Compared with the commonly used Google Maps, Tencent Maps, Baidu Maps, Microsoft Maps, and Bing Maps, what is the difference between Sky Maps? Mainly reflected in the authority and accuracy of the data. The national boundaries and nine-dash lines published by Tiantu are accurate; in addition, only the coordinates of Tiantu images in China have no offset, and the coordinates of the other maps have been encrypted.
Cartopy is a Python-based mapping module, which provides the function of loading online maps, so how to add the function of calling the map service?
In fact, there have been related work in the early stage, but due to the upgrade of the Sky Map service, the original method is no longer applicable. Here is the latest calling method.

Ready to work

Website: Sky Map
First, you need to register an account, and then select Development Resources→Map API

Enter the console, click Create New Application, select the server side, so you can get a key

The map service of Tiandi adopts the OGC WMTS standard, but the method has not been tried successfully so far, so it adopts the form of XYZ Tiles.

Add calling method

Add the following code, pay attention to replace the'your_key' in the code with the key obtained before

import cartopy.io.img_tiles as cimgt
# Sky map vector
classTDT_vec(cimgt.GoogleWTS):
 def _image_url(self, tile):
  x, y, z = tile
  key ='your_key'
  url ='http://t0.tianditu.gov.cn/DataServer?T=vec_w&x=%s&y=%s&l=%s&tk=%s'%(x, y, z, key)return url

# Sky Map Remote Sensing
classTDT_img(cimgt.GoogleWTS):
 def _image_url(self, tile):
  x, y, z = tile
  key ='your_key'
  url ='http://t0.tianditu.gov.cn/DataServer?T=img_w&x=%s&y=%s&l=%s&tk=%s'%(x, y, z, key)return url

# Sky map topography
classTDT_ter(cimgt.GoogleWTS):
 def _image_url(self, tile):
  x, y, z = tile
  key ='your_key'
  url ='http://t0.tianditu.gov.cn/DataServer?T=ter_w&x=%s&y=%s&l=%s&tk=%s'%(x, y, z, key)return url

Call demo

1、 Vector base map, image base map, topographic base map

# Import module
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeat
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
from cartopy.mpl.ticker import LongitudeFormatter,LatitudeFormatter
import cartopy.io.shapereader as shpreader
import numpy as np

plt.rcParams['font.sans-serif']=['SimHei'] 
plt.rcParams['axes.unicode_minus']= False 

fig = plt.figure(figsize=(18,12))

ax = fig.add_subplot(1,3,1, projection=ccrs.PlateCarree())
ax.set_extent([118,122,28,32],crs=ccrs.PlateCarree())
request =TDT_vec()
ax.add_image(request,9)
ax.set_title('Sky map vector base map',fontsize=15)
gl = ax.gridlines(draw_labels=True, linewidth=1, color='k', alpha=0.5, linestyle='--')
gl.xlabels_top = gl.ylabels_right = False 
gl.xformatter = LONGITUDE_FORMATTER 
gl.yformatter = LATITUDE_FORMATTER

ax = fig.add_subplot(1,3,2, projection=ccrs.PlateCarree())
ax.set_extent([118,122,28,32],crs=ccrs.PlateCarree())
request =TDT_img()
ax.add_image(request,9)
ax.set_title('Sky map image base map',fontsize=15)
gl = ax.gridlines(draw_labels=True, linewidth=1, color='k', alpha=0.5, linestyle='--')
gl.xlabels_top = gl.ylabels_right = False 
gl.xformatter = LONGITUDE_FORMATTER 
gl.yformatter = LATITUDE_FORMATTER

ax = fig.add_subplot(1,3,3, projection=ccrs.PlateCarree())
ax.set_extent([118,122,28,32],crs=ccrs.PlateCarree())
request =TDT_ter()
ax.add_image(request,9)
ax.set_title('Sky map topographic base map',fontsize=15)
gl = ax.gridlines(draw_labels=True, linewidth=1, color='k', alpha=0.5, linestyle='--')
gl.xlabels_top = gl.ylabels_right = False 
gl.xformatter = LONGITUDE_FORMATTER 
gl.yformatter = LATITUDE_FORMATTER
plt.show()

2、 Basemaps at different levels

fig = plt.figure(figsize=(18,12))for i inrange(6,9):
 ax = fig.add_subplot(1,3, i-5, projection=ccrs.PlateCarree())
 ax.set_extent([120.4,122.1,30.6,32.1],crs=ccrs.PlateCarree())
 request =TDT_img()
 ax.add_image(request, i)
 ax.set_title('Level='+str(i),fontsize=15)
 gl = ax.gridlines(xlocs=np.arange(120.5,122.5,0.5),
      ylocs=np.arange(30,32.5,0.5),
      draw_labels=True,linewidth =0.5,color='k',
      alpha=0.5,linestyle='--')
 gl.xlabels_top = gl.ylabels_right = False
plt.show()

reference:

  1. https://my.oschina.net/u/4581316/blog/4396806
  2. http://bbs.06climate.com/forum.php?mod=viewthread&tid=89165

Recommended Posts

Python Tutorial | The most standard way of calling maps (data provided by the National Bureau of Surveying and Mapping)
python tutorial | The most standard map call method (data provided by the National Bureau of Surveying and Mapping)
python tutorial | The most standard map call method (data provided by the National Bureau of Surveying and Mapping)
python tutorial | The most standard map call method (data provided by the National Bureau of Surveying and Mapping)