2013-08-22 21 views
1

我一直在按照用户pelson的指示创建一个填充了国家形状的地图。现在(Fill countries in python basemap带html区域链接的cartopy国家地图

我是把这个一步,创建一个HTML网站像这样的好奇: http://www.ethnologue.com/region/NEU 我不需要那些花哨的弹出窗口,但每个国家的链接(http://www.w3schools.com/tags/att_area_href.asp)将是真正的好。 是否可以用cartopy创建这些坐标列表? 我正在寻找一个完全自动的脚本来生成一个静态的html文件。

回答

3

是的,这是绝对有可能的,但是如果你正在制作基于网络的地图,那么可能值得你看看D3.js(具体来说,地图见这个优秀教程http://bost.ocks.org/mike/map/)。

对于cartopy而言,我将一步步地介绍它,因为它是matplotlib和cartopy中转换系统的一个很好的演练。

首先,我们可以得到一个数字任意点的像素坐标:

import matplotlib.pyplot as plt 
import cartopy.crs as ccrs 

ax = plt.axes(projection=ccrs.PlateCarree()) 
ax.set_global() 
ax.coastlines() 

# Define a transformation which takes latitude and longitude values, 
# and returns pixel coordinates. 
ll_to_pixel = ccrs.Geodetic()._as_mpl_transform(ax) 

# We need to call draw to ensure that the axes location has been defined 
# fully. 
plt.draw() 

# Now lets figure out the pixel coordinate of Sydney. 
x_pix, y_pix = ll_to_pixel.transform_point([151.2111, -33.8600]) 

# We can even plot these pixel coordinates directly with matplotlib. 
plt.plot(x_pix, y_pix, 'ob', markersize=25, transform=None) 

plt.savefig('figure_1.png', dpi=plt.gcf().get_dpi()) 
plt.show() 

Sydney in pixel coordinates

现在我们要编写代码来生成区域地图,我会在必要的信息已经提前写下了全部评论(< 80行)。我已经发布了这个作为要点(https://gist.github.com/pelson/6308997),以便你可以检查出来,如果你喜欢,可以试试看。现场演示结果:https://rawgithub.com/pelson/6308997/raw/map.html

相关问题