python实现3D地图可视化
3d地图实景地图基于python代码的3D地图可视化,供⼤家参考,具体内容如下
介绍
使⽤Python对地图进⾏3D可视化。以地图为地图,可以在三维空间对轨迹、点进⾏可视化。
我们使⽤了多个库:
1.gdal;主要是⽤于读取地图信息,这个库在GIS中很常⽤,使⽤C++代码编写的,如果安装不了需要在pypi⾥⾯⼀下对应的资源。
2.opencv;很常⽤的图像处理库。
3.matplotlib;常⽤的可视化库
结果
废话不多说直接上结果:
代码
直接上代码,代码很简单。
from osgeo import gdal
import cv2
gdal.UseExceptions()
ds = gdal.Open('E:/Pythoncode/读取地理信息/⽆标题.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= ([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/读取地理信息/⽆标题.tif')
xx=[]
yy=[]
colall=[]
x = img.size[0]
y = img.size[1]
for i in range(x):
for j in range(y):
r = pixel((i, j))[0])[2:]
b = pixel((i, j))[1])[2:]
g = pixel((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()
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。