前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >算一个NDVI

算一个NDVI

作者头像
一个有趣的灵魂W
发布2020-09-15 12:19:36
3720
发布2020-09-15 12:19:36
举报
文章被收录于专栏:一个有趣的灵魂W

GDAL算NDVI,其实本质就是转换成数组,按NDVI算法计算,在绘图的时候出了点小问题,一般如果要在python上绘制一下,最好把NDVI的值拉伸到8bit,这样可以直观的看到,但如果你要继续处理,最好还是按照原本的计划将它保留:

from osgeo import gdal_array as ga

import gdal, ogr, os, osr

import numpy as np

b3=r'D:\宁波四明山\aod-ningbo\imagery\2016-\1\LC08_L1TP_118039_20170824_20170912_01_T1_B4.TIF'

b4=r'D:\宁波四明山\aod-ningbo\imagery\2016-\1\LC08_L1TP_118039_20170824_20170912_01_T1_B5.TIF'

arr=ga.LoadFile(b3)

arr1=ga.LoadFile(b4)

ga.numpy.seterr(all="ignore")

ndvi=((arr1-arr)*1.0)/((arr1+arr)*1.0)

ndvi1=ga.numpy.nan_to_num(ndvi)

target=r'D:\Temp\ndvi1.tif'

out=ga.SaveArray(ndvi1,target,format = "GTiff",prototype = b4)

out=None

如果是arcpy,那就更方便了:

from arcpy import env

from arcpy.sa import*

arcpy.CheckOutExtension("spatial")

env.workspace = r'C:\Your\workspace'

input = r'C:\Your\raster.tif'

result = "outputName.tif"

# You may need to change the band combinations.

# This is for 4-band NAIP imagery or Landsat TM.

NIR = input + "\Band_4"

Red = input + "\Band_3"

NIR_out = "NIR.tif"

Red_out = "Red.tif"

arcpy.CopyRaster_management(NIR,NIR_out)

arcpy.CopyRaster_management(Red, Red_out)

Num = arcpy.sa.Float(Raster(NIR_out) - Raster(Red_out))

Denom = arcpy.sa.Float(Raster(NIR_out) + Raster(Red_out))

NIR_eq = arcpy.sa.Divide(Num, Denom)

NIR_eq.save(result)

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-05-27,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 一个有趣的灵魂W 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档