Basics Tutorial python: python achieve 3D map visualization

This article explain to you the python achieve 3D map visualization, the paper sample code described in great detail, has a certain reference value, small partners who are interested can refer to
based 3D map python code visualization, for your reference, details are as follows

Introduction

Using Python on the map for 3D visualization. Map-map may be visualized trace points in three dimensional space.

Storehouse

We used multiple libraries:

1.gdal;
mainly used for reading the map information, the library is very commonly used in GIS, code written in C ++, if you can not find what the installation requires a corresponding resource in pypi inside.

2.opencv;
very common image processing library.

3.matplotlib;
common visualization library

result

Ado directly on the results: Here Insert Picture Description
Here Insert Picture Description
Code

Directly on the code, the code is very simple.

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()

I write to you, for everyone to recommend a very wide python learning resource gathering, click to enter , there is a senior programmer before learning to share

Experience, study notes, there is a chance of business experience, and for everyone to carefully organize a python to combat zero-based item of information,

Python day to you on the latest technology, prospects, learning to leave a message of small details

Published 57 original articles · won praise 25 · views 70000 +

Guess you like

Origin blog.csdn.net/haoxun11/article/details/105129217