python實(shí)現(xiàn)3D地圖可視化
基于python代碼的3D地圖可視化,供大家參考,具體內(nèi)容如下
介紹
使用Python對(duì)地圖進(jìn)行3D可視化。以地圖為地圖,可以在三維空間對(duì)軌跡、點(diǎn)進(jìn)行可視化。
庫(kù)
我們使用了多個(gè)庫(kù):
1.gdal;主要是用于讀取地圖信息,這個(gè)庫(kù)在GIS中很常用,使用C++代碼編寫(xiě)的,如果安裝不了需要在pypi里面找一下對(duì)應(yīng)的資源。
2.opencv;很常用的圖像處理庫(kù)。
3.matplotlib;常用的可視化庫(kù)
結(jié)果
廢話不多說(shuō)直接上結(jié)果:
代碼
直接上代碼,代碼很簡(jiǎn)單。
from osgeo import gdalimport cv2gdal.UseExceptions()ds = gdal.Open(’E:/Pythoncode/讀取地理信息/無(wú)標(biāo)題.tif’)bandg = ds.GetRasterBand(1)elevationg = bandg.ReadAsArray()bandr = ds.GetRasterBand(2)elevationr = bandr.ReadAsArray()bandb = ds.GetRasterBand(3)elevationb = bandb.ReadAsArray()import matplotlib.pyplot as pltnrows, ncols = elevationr.shapeelevation= cv2.merge([elevationg,elevationr,elevationb])## I’m making the assumption that the image isn’t rotated/skewed/etc. # This is not the correct method in general, but let’s ignore that for now# If dxdy or dydx aren’t 0, then this will be incorrectx0, dx, dxdy, y0, dydx, dy = ds.GetGeoTransform()x1 = x0 + dx * ncolsy1 = y0 + dy * nrowsplt.imshow(elevation, cmap=’gist_earth’, extent=[x0, x1, y1, y0])plt.show()from PIL import Imagefrom mpl_toolkits.mplot3d import Axes3Dimport matplotlib.pyplot as pltfig = plt.figure()ax = Axes3D(fig)img = Image.open(’E:/Pythoncode/讀取地理信息/無(wú)標(biāo)題.tif’)xx=[]yy=[]colall=[]x = img.size[0]y = img.size[1]for i in range(x): for j in range(y): r = hex(img.getpixel((i, j))[0])[2:] b = hex(img.getpixel((i, j))[1])[2:] g = hex(img.getpixel((i, j))[2])[2:] if len(r) == 1: r = ’0’ + r if len(b) == 1: b = ’0’ + b if len(g) == 1: g = ’0’ + g col = ’#’ + r + b + g colall.append(col) xx.append(x0 + dx * i) yy.append(y0 + dy * j) # col = ’#FF00FF’ax.scatter(xx, yy, 5, c=colall, alpha=0.5)plt.show()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. PHP防XSS 防SQL注入的代碼2. idea設(shè)置自動(dòng)導(dǎo)入依賴(lài)的方法步驟3. 淺談SpringMVC jsp前臺(tái)獲取參數(shù)的方式 EL表達(dá)式4. python pymysql鏈接數(shù)據(jù)庫(kù)查詢(xún)結(jié)果轉(zhuǎn)為Dataframe實(shí)例5. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)6. IDEA版最新MyBatis程序配置教程詳解7. 使用Python和百度語(yǔ)音識(shí)別生成視頻字幕的實(shí)現(xiàn)8. 教你如何寫(xiě)出可維護(hù)的JS代碼9. idea不能自動(dòng)補(bǔ)全yml配置文件的原因分析10. xml中的空格之完全解說(shuō)
