读取Geotiff栅格文件赋值给点

 python3.8安装rasterio库遇到几个问题,

1、rasterio库依赖GDAL库,

2、rasterio库对numpy库版本有要求。

直接安装GDAL库会编译要安装vc 2005那个,4G大小,太大了,需要直接下载wheel,

 在https://www.lfd.uci.edu/~gohlke/pythonlibs/下载

  • rasterio‑1.2.10‑cp38‑cp38‑win_amd64.whl
  • GDAL‑3.4.3‑cp38‑cp38‑win_amd64.whl

 另外numpy版本升级到1.22.3,否则会提示np错误。

import rasterio as rio##要安装GDAL库
import pandas as pd
import os

shotfile=r'E:\prc\python\多因素量化难度\炮点.xlsx'
filesave=os.path.splitext(shotfile)[0]
rasterfile=r'E:\prc\python\多因素量化难度\dem.tif'
shotdata=pd.read_excel(shotfile,usecols=[0,1,2,3])###只读取线号,点号,x,y坐标
shotdata['高程']=5000
rast=rio.open(rasterfile)##读取栅格图像
temp_r=rast.read(1)##读取1波段
for i in range(len(shotdata)):
    x=shotdata['x'][i]
    y=shotdata['y'][i]
    rowindex,colindex=rast.index(x,y)##匹配index
    shotdata.iat[i,4]=temp_r[rowindex,colindex]##高程赋值
shotdata.to_excel(filesave+'_高程赋值.xlsx',index=False,encoding='gbk')   #############不带索引

下图为实际高程与dem赋值高程的对比,整体趋势一致,局部有差异。

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值