python實(shí)現(xiàn)3D地圖可視化
基于python代碼的3D地圖可視化,供大家參考,具體內(nèi)容如下
介紹
使用Python對地圖進(jìn)行3D可視化。以地圖為地圖,可以在三維空間對軌跡、點(diǎn)進(jìn)行可視化。
庫
我們使用了多個(gè)庫:
1.gdal;
主要是用于讀取地圖信息,這個(gè)庫在GIS中很常用,使用C++代碼編寫的,如果安裝不了需要在pypi里面找一下對應(yīng)的資源。
2.opencv;
很常用的圖像處理庫。
3.matplotlib;
常用的可視化庫
結(jié)果
廢話不多說直接上結(jié)果:


代碼
直接上代碼,代碼很簡單。
from osgeo import gdal
import cv2
gdal.UseExceptions()
ds = gdal.Open('E:/Pythoncode/讀取地理信息/無標(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 plt
nrows, ncols = elevationr.shape
elevation= 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 incorrect
x0, dx, dxdy, y0, dydx, dy = ds.GetGeoTransform()
x1 = x0 + dx * ncols
y1 = y0 + dy * nrows
plt.imshow(elevation, cmap='gist_earth', extent=[x0, x1, y1, y0])
plt.show()
from PIL import Image
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure()
ax = Axes3D(fig)
img = Image.open('E:/Pythoncode/讀取地理信息/無標(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()
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 詳解python 利用echarts畫地圖(熱力圖)(世界地圖,省市地圖,區(qū)縣地圖)
- python使用pyecharts庫畫地圖數(shù)據(jù)可視化的實(shí)現(xiàn)
- Python學(xué)習(xí)之用pygal畫世界地圖實(shí)例
- python實(shí)現(xiàn)Pyecharts實(shí)現(xiàn)動態(tài)地圖(Map、Geo)
- 使用Python實(shí)現(xiàn)畫一個(gè)中國地圖
- Python地圖繪制實(shí)操詳解
- 代碼分析Python地圖坐標(biāo)轉(zhuǎn)換
- 利用python繪制中國地圖(含省界、河流等)
- 如何利用Python快速繪制海報(bào)級別地圖詳解
相關(guān)文章
python實(shí)現(xiàn)順時(shí)針打印矩陣
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)順時(shí)針打印矩陣,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-03-03
python中復(fù)數(shù)的共軛復(fù)數(shù)知識點(diǎn)總結(jié)
在本篇內(nèi)容里小編給大家整理的是關(guān)于python中復(fù)數(shù)的共軛復(fù)數(shù)知識點(diǎn)總結(jié),有需要的朋友們可以學(xué)習(xí)下。2020-12-12
Python 正則表達(dá)式實(shí)現(xiàn)計(jì)算器功能
本篇文章主要介紹了Python 正則表達(dá)式實(shí)現(xiàn)計(jì)算器功能的示例。具有很好的參考價(jià)值。下面跟著小編一起來看下吧2017-04-04

