python实现3d特效_python实现3D地图可视化

python实现3D地图可视化

发布时间:2020-08-23 08:41:48

来源:脚本之家

阅读:101

作者:机关枪小哥哥

基于python代码的3D地图可视化,供大家参考,具体内容如下

介绍

使用Python对地图进行3D可视化。以地图为地图,可以在三维空间对轨迹、点进行可视化。

我们使用了多个库:

1.gdal;主要是用于读取地图信息,这个库在GIS中很常用,使用C++代码编写的,如果安装不了需要在pypi里面找一下对应的资源。

2.opencv;很常用的图像处理库。

3.matplotlib;常用的可视化库

结果

废话不多说直接上结果:

e6062878ae0e29fdedea59001b8e54f4.png

123b2e3bce8a58cb1b5a1dcfbb5fdf75.png

代码

直接上代码,代码很简单。

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= 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/读取地理信息/无标题.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()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值