给出利用landsat影像计算evi的代码
时间: 2023-03-31 17:01:23 浏览: 74
以下是利用Landsat影像计算EVI的代码:
```python
import rasterio
import numpy as np
# 读取红、近红波段的数据
with rasterio.open('landsat.tif') as src:
red = src.read(4)
nir = src.read(5)
# 计算EVI
G = 2.5
L = 1
C1 = 6
C2 = 7.5
EVI = G * ((nir - red) / (nir + C1 * red - C2)) + L
# 将EVI保存为GeoTIFF文件
with rasterio.open('evi.tif', 'w', **src.profile) as dst:
dst.write(EVI.astype(rasterio.float32), 1)
```
希望对您有所帮助!
相关问题
给出利用landsat影像计算ndvi的代码
以下是利用Landsat影像计算NDVI的Python代码示例:
```python
import rasterio
import numpy as np
# 打开Landsat影像文件
with rasterio.open('landsat.tif') as src:
# 读取红波段和近红外波段数据
red = src.read(4)
nir = src.read(5)
# 计算NDVI
ndvi = np.where((nir+red) == ., , (nir-red)/(nir+red))
# 将NDVI写入新的GeoTIFF文件
profile = src.profile
profile.update(dtype=rasterio.float32, count=1)
with rasterio.open('ndvi.tif', 'w', **profile) as dst:
dst.write(ndvi.astype(rasterio.float32), 1)
```
这段代码使用了rasterio库来读取和写入GeoTIFF格式的影像文件,计算NDVI的公式为(NIR-Red)/(NIR+Red),其中NIR为近红外波段,Red为红波段。最后将NDVI结果写入新的GeoTIFF文件中。
请给出在GEE中计算EVI的代码
以下是在GEE中计算EVI的代码:
```javascript
// Load the Landsat 8 surface reflectance collection.
var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterDate('2019-01-01', '2019-12-31')
.filterBounds(geometry);
// Define the EVI function.
var evi = function(image) {
var nir = image.select('B5');
var red = image.select('B4');
var blue = image.select('B2');
var evi = nir.subtract(red).divide(nir.add(red.multiply(6)).subtract(blue.multiply(7.5)).add(1));
return image.addBands(evi.rename('EVI'));
};
// Apply the EVI function to the collection.
var eviCollection = collection.map(evi);
// Select and display the EVI band of the first image in the collection.
var eviImage = eviCollection.first().select('EVI');
Map.addLayer(eviImage, {min: -1, max: 1, palette: ['blue', 'white', 'green']}, 'EVI');
```