iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 27
1
AI & Data

30天精通GIS資料分析-使用Python系列 第 27

Day27 計算NDVI

昨天使用的Rasterio是一個方便的工具,它主要是包了一些GDAL等等的GIS套件,
使用GIS資料分析,當然一定會接觸到GDAL,GDAL Geospatial Data Abstraction Library可以說是始祖,Rasterio建構於它之上讓資料分析更加方便。

持續Rasterio的主題,今天要測試的項目是NDVI。
大綱:

  • NDVI
  • NDVI計算: rasterio, numpy

NDVI

NDVI是常態化植生指標參考wiki常態化差值植生指標,計算方式是利用紅光與近紅外光波段,代表植物生長與覆蓋的指數,其數值愈大表示植物生長愈多。
公式:
https://ithelp.ithome.com.tw/upload/images/20181111/20107816tfuXryBeN2.png

https://ithelp.ithome.com.tw/upload/images/20181111/20107816hPk2rvpANE.png

NIR為近紅外光反射;RED為紅光反射,NDVI之值介於-1到1之間。 當RED=0時,有最大值1;反之,當NIR=0時,有最小值-1。
(取自wiki常態化差值植生指標Calculate NDVI & Extract Spectra Using Masks in Python - Flightline Data | NSF NEON | Open Data to Understand our Ecosystems)

NDVI計算: rasterio, numpy

讀取影像

import rasterio
src=rasterio.open('data/rasterio/data/test.tif')

然後,取得波段:

b1, b2, b3, b4 = src.read()

波段計算,我們使用numpy

import numpy
ndvi = numpy.zeros(b1.shape)
ndvi = (b1-b2)/(b1+b2)

展示成果

import matplotlib.pyplot as plt
from rasterio import plot
%matplotlib inline
plot.show(ndvi)

https://ithelp.ithome.com.tw/upload/images/20181111/20107816zXs0MWveIK.png

後記

計算NDVI需要NIR為近紅外光反射的影像,如果需要影像可以使用USGS的Landsat影像:

EarthExplorer - Home


上一篇
Day26 網格資料的處理-Rasterio初探
下一篇
Day28 20米DEM資料處理
系列文
30天精通GIS資料分析-使用Python30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言