python栅格数据出图可视化

更新时间:2023-06-23 06:20:58 阅读: 评论:0

python栅格数据出图可视化
import numpy as np
s as ccrshard是什么意思
import cartopy.mpl.ticker as cticker
import matplotlib.pyplot as plt
import cartopy.feature as cfeature
from mpl_toolkits.bamap import Bamap学英文最好方法
import cartopy.io.shapereader as shpreader
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
from matplotlib import rcParams
from osgeo import gdal
import matplotlib.patches as mpatches
config ={"font.family":'Times New Roman',"font.size":18,"mathtext.fontt":'stix'}
rcParams.update(config)
#------------------------------读取栅格------------------------
def Read_Tiif(fileName):
#输⼊信息,⽂件名
工业区英文
#输出信息,data_array,im_bands,im_geotrans,im_proj
#分别是,矩阵数据,波段数,放射变换矩阵信息,投影信息
datat = gdal.Open(fileName)
if datat ==None:
print(fileName+"⽂件⽆法打开")
return
im_width = datat.RasterXSize #栅格矩阵的列数
im_height = datat.RasterYSize #栅格矩阵的⾏数
im_bands = datat.RasterCount #波段数
if im_bands <1:
print("影像没有可使⽤数据!")
return
im_data = datat.ReadAsArray(0,0,im_width,im_height)#获取数据
im_geotrans = datat.GetGeoTransform()#获取仿射矩阵信息
im_proj = datat.GetProjection()#获取投影信息
if im_bands ==1:
data_array =  im_data[0:im_height,0:im_width]#获取第Band_num波段
if im_bands >1:
dog days
data_array =  im_data[:,0:im_height,0:im_width]#获取第Band_num波段
return data_array,im_width,im_height,im_bands,im_geotrans,im_proj
#-----------函数:添加指北针--------------
def add_north(ax, labelsize=16, loc_x=0.1, loc_y=0.85, width=0.04, height=0.13, pad=0.14):
"""
画⼀个⽐例尺带'N'⽂字注释
主要参数如下
:param ax: 要画的坐标区域 Axes实例 a()获取即可
:param labelsize: 显⽰'N'⽂字的⼤⼩
:
param loc_x: 以⽂字下部为中⼼的占整个ax横向⽐例
:param loc_y: 以⽂字下部为中⼼的占整个ax纵向⽐例
:param width: 指南针占ax⽐例宽度
:param height: 指南针占ax⽐例⾼度
:param pad: ⽂字符号占ax⽐例间隙
:return: None
"""
minx, maxx = ax.get_xlim()
miny, maxy = ax.get_ylim()
ylen = maxy - miny
xlen = maxx - minx
goldbach conjecture
left =[minx + xlen*(loc_x - width*.5), miny + ylen*(loc_y - pad)]
right =[minx + xlen*(loc_x + width*.5), miny + ylen*(loc_y - pad)]
top =[minx + xlen*loc_x, miny + ylen*(loc_y - pad + height)]
center =[minx + xlen*loc_x, left[1]+(top[1]- left[1])*.4]
triangle = mpatches.Polygon([left, top, right, center], color='k')
<(s='N',
x=minx + xlen*loc_x,
y=miny + ylen*(loc_y - pad + height),
correct是什么意思fontsize=labelsize,
horizontalalignment='center',
verticalalignment='bottom')
ax.add_patch(triangle)
## 数据读⼊
input_file = r'D:\exe\anaconda\file\make_map\PT_1981_08_05.tif'
data_array,im_width,im_height,im_bands,im_geotrans,im_proj = Read_Tiif(input_file)
left_lon,width_res,uperlat,heigh_res = im_geotrans[0], im_geotrans[1], im_geotrans[3],im_geotrans[5]
#lon = np.linspace(left_lon,24,25) * im_width
lon = np.arange(im_width)* width_res + left_lon
lat = np.arange(im_height)* heigh_res + uperlat
## 位势⾼度
learn的用法
data_array = data_array
成人英语怎么说
data_array[np.where(data_array >1)]= np.nan
data_array[np.where(data_array <-1)]= np.nan
data_array = anspo(1,0)
#hgt = HGT[:,:,5,:]
HHGT = data_array
[LON,LAT]= np.meshgrid(lon,lat)
LON = anspo(1,0)
LAT = anspo(1,0)
#print(U.variables.keys())
#创建画布
fig = plt.figure(figsize=(12,8))
ax=plt.axes(projection=ccrs.PlateCarree(central_longitude=85))
# 标注坐标轴
leftlon, rightlon, lowerlat, upperlat =(89,127,25,55)
img_extent =[leftlon, rightlon, lowerlat, upperlat]
ax.t_extent([leftlon, rightlon, lowerlat, upperlat], crs=ccrs.PlateCarree())
ax.t_xticks([90,95,100,105,110,115,120,125], crs=ccrs.PlateCarree())
ax.t_yticks([25,30,35,40,45,50,55], crs=ccrs.PlateCarree())
#zero_direction_label⽤来设置经度的0度加不加E和W
lon_formatter = LongitudeFormatter(zero_direction_label=Fal)
考研准考证号查询lat_formatter = LatitudeFormatter()
ax.xaxis.t_major_formatter(lon_formatter)
ax.yaxis.t_major_formatter(lat_formatter)
ax.t_title('Nei Meng SSM(v)',loc='center',fontsize =20)
# 加载中国地图
china = shpreader.Reader(r'D:\exe\anaconda\file\make_map\shp\shp\neimengg.dbf').geometries()
#绘制中国国界省界九段线等等
ax.add_geometries(china, ccrs.PlateCarree(),facecolor='none', edgecolor='black',zorder =1)
# 绘制风场和位势图
urf(LON[:],LAT[:],HHGT[:],100,cmap='gist_rainbow',transform=ccrs.PlateCarree(),extend='both')
#urf(LON[:],LAT[:],HHGT[:],40,cmap='gist_rainbow',transform=ccrs.PlateCarree(),extend='both')#其中100是颜⾊的变化区间数⽬#Q = ax.quiver(LON[:], LAT[:], UUwnd[:], VVwnd[:], color='black',width=0.0018,scale=100,headwidth=4,transform=ccrs.PlateCarree())    # position=fig.add_axes([0.2, 0.1, 0.5, 0.03])#位置[左,下,右,上]
value_min = np.min(HHGT)
value_max = np.max(HHGT)
add_north(ax)
lorbar(cf,orientation='vertical',shrink=0.92,aspect=20,fraction=.03,pad=0.01)
#lorbar(cf,orientation='vertical',shrink=0.92,aspect=20,fraction=.03,pad=0.01)
#cbar = lorbar(cf,orientation='horizontal',fraction=0.07, pad=0.05)
angel意思
lorbar)
plt.savefig(r'D:\exe\anaconda\file\make_map\plot33.png',dpi=800)
plt.show()

本文发布于:2023-06-23 06:20:58,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/1019070.html

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

标签:矩阵   信息   绘制   中国   经度   坐标   度加
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图