溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

matplotlib Basemap中如何加載shp文件

發(fā)布時間:2021-12-02 17:57:07 來源:億速云 閱讀:1038 作者:小新 欄目:大數(shù)據(jù)

小編給大家分享一下matplotlib Basemap中如何加載shp文件,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

matplotlib是python中的一個畫圖插件;

matplotlib支持二維圖的效果,也支持三維圖的效果,在大數(shù)據(jù)的制作中,可以以地圖為底,在旁邊加上柱狀圖的效果,達(dá)到一個三維立體的效果,python現(xiàn)成的庫有很多,這在開發(fā)中就比較方便,可以直接import進(jìn)來使用。

matplotlib的Basemap中包含解析常用的shp格式矢量數(shù)據(jù),通過讀取shp文件,可以很方便的在Basemap上進(jìn)行畫圖。
下邊是根據(jù)Basemap的一個例子,說明如何讀取shp,并將shp里的數(shù)據(jù)畫在地圖上:

#引用相應(yīng)的類庫

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap as Basemap
# 設(shè)置地圖的坐標(biāo)系和坐標(biāo)顯示范圍
m = Basemap(llcrnrlon=-100.,llcrnrlat=0.,urcrnrlon=-20.,urcrnrlat=57.,
           projection='lcc',lat_1=20.,lat_2=40.,lon_0=-60.,
           resolution ='l',area_thresh=1000.)
fig=plt.figure()
# 讀取shp文件,注意第二個參數(shù)是shp文件在地圖里的名稱,接下來要用的.
shp_info = m.readshapefile('huralll020','hurall',drawbounds=False)
print(shp_info)
#在地圖中找到shp文件,讀取shp文件中的屬性
names = []
for shapedict in m.hurall_info:
   cat = shapedict['CATEGORY']
   name = shapedict['NAME']
   if cat in ['H4','H5'] and name not in names:
       if name != 'NOT NAMED':  names.append(name)
print(names)
print(len(names))
# 根據(jù)屬性,在地圖上畫圖
for shapedict,shape in zip(m.hurall_info,m.hurall):
   name = shapedict['NAME']
   cat = shapedict['CATEGORY']
   if name in names:
       xx,yy = zip(*shape)
       # plot為在地圖上畫圖
       if cat in ['H4','H5']:
           m.plot(xx,yy,linewidth=1.5,color='r')
       elif cat in ['H1','H2','H3']:
           m.plot(xx,yy,color='k')
# 在地圖上畫其他輔助要素,國界,經(jīng)緯度線等
m.drawcoastlines()
m.drawcountries()
m.drawmapboundary(fill_color='#99ffff')
m.fillcontinents(color='#cc9966',lake_color='#99ffff')
m.drawparallels(np.arange(10,70,20),labels=[1,1,0,0])
m.drawmeridians(np.arange(-100,0,20),labels=[0,0,0,1])
#設(shè)置圖的標(biāo)題
plt.title('Atlantic Hurricane Tracks (Storms Reaching Category 4, 1851-2004)')
plt.show()

matplotlib Basemap中如何加載shp文件

看完了這篇文章,相信你對“matplotlib Basemap中如何加載shp文件”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI