使用 Basemap 获取城市地图的最佳方式?
Best way to get a map of a city using Basemap?
我正在尝试使用 Basemap 显示城市的地图,例如 python 中的旧金山。我尝试了以下方法:
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
# llcrnrlat,llcrnrlon,urcrnrlat,urcrnrlon
# are the lat/lon values of the lower left and upper right corners
# of the map.
# lat_ts is the latitude of true scale.
# resolution = 'c' means use crude resolution coastlines.
m = Basemap(projection='merc',llcrnrlat=37.79,urcrnrlat=37.81,\
llcrnrlon=-122.42,urcrnrlon=-122.4,lat_ts=20,resolution='c')
m.drawcoastlines()
m.fillcontinents(color='coral',lake_color='aqua')
# draw parallels and meridians.
m.drawparallels(np.arange(-90.,91.,30.))
m.drawmeridians(np.arange(-180.,181.,60.))
m.drawmapboundary(fill_color='aqua')
plt.title("Mercator Projection")
plt.show()
然而,这不起作用,只是在地图原本的位置显示蓝色。那么如何使用 python 获取旧金山地图?
你的坐标一定是错误的:它显示蓝色是因为你正在放大某个地方的海洋。
另外,这段代码只会绘制海岸线as explained in the documentation. To get the map of a city, you actually need to load the corresponding data using one of the available back-ends. For instance, you could query the data from a API service such as ArcGIS, etc, with the corresponding method。
我正在尝试使用 Basemap 显示城市的地图,例如 python 中的旧金山。我尝试了以下方法:
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
# llcrnrlat,llcrnrlon,urcrnrlat,urcrnrlon
# are the lat/lon values of the lower left and upper right corners
# of the map.
# lat_ts is the latitude of true scale.
# resolution = 'c' means use crude resolution coastlines.
m = Basemap(projection='merc',llcrnrlat=37.79,urcrnrlat=37.81,\
llcrnrlon=-122.42,urcrnrlon=-122.4,lat_ts=20,resolution='c')
m.drawcoastlines()
m.fillcontinents(color='coral',lake_color='aqua')
# draw parallels and meridians.
m.drawparallels(np.arange(-90.,91.,30.))
m.drawmeridians(np.arange(-180.,181.,60.))
m.drawmapboundary(fill_color='aqua')
plt.title("Mercator Projection")
plt.show()
然而,这不起作用,只是在地图原本的位置显示蓝色。那么如何使用 python 获取旧金山地图?
你的坐标一定是错误的:它显示蓝色是因为你正在放大某个地方的海洋。
另外,这段代码只会绘制海岸线as explained in the documentation. To get the map of a city, you actually need to load the corresponding data using one of the available back-ends. For instance, you could query the data from a API service such as ArcGIS, etc, with the corresponding method。