目录
Image中的projection(),reproject()
Image.unitScale()、Image.cast()
Image的表达式计算:Image.expression()
土地利用数据集:ESA/GLOBCOVER_L4_200901_200912_V2_3
里面有这两个波段landcover和qa
Image.get()
Image.clip()
注意:clip是作用在Image上的,不能作用在ImageCollection上
var sichuan = ee.FeatureCollection("users/lcljv1066965/test/sichuan"),
dem = ee.Image("USGS/SRTMGL1_003");
print("dem",dem)
print("sichuan",sichuan)
var sichuan_dem = dem.clip(sichuan)
Map.setCenter(106.8, 29.3,5)
Map.addLayer(sichuan_dem,{min:0,max:2000})
Image.select()
提取出想要的波段
var img_cover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3");
print(img_cover)
print(img_cover.select('landcover'))
Image.addBands()
添加波段
var img_cover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3");
print(img_cover)
var band1=img_cover.select('landcover')
var band2=img_cover.select('qa')
print(band1.addBands(band2))
Image中的projection(),reproject()
var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT");
var img = ee.Image(l8.filterBounds(ee.Geometry.Point(106.4958, 29.5856)).first())
print(img)
print(img.select('B1').projection())//这里直接img.projection()会报错
var img_reproject = img.reproject('EPSG:3857',null,100)//重投影为3857,重采样为100m
print(img_reproject)
print(img_reproject.projection())//这里直接img.projection()不会报错
Map.setCenter(106.58365, 29.56972,15)
Map.addLayer(img,{"bands":["B5","B4","B3"],"min":10586,"max":18154},'30m')
Map.addLayer(img_reproject,{"bands":["B5","B4","B3"],"min":10586,"max":18154}, '100m')
Image.unitScale()、Image.cast()
- Image.unitScale():栅格的归一值化--将给定区间内的数值范围转换为0-1的区间内。此算法总是生成浮点像素。
- Image.cast():强制转换数据类型
var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT");
var img=l8.first().select(['B3','B4','B5'])
var img_unitScale=img.unitScale(0,32628)//使输入值的范围[低,高]变为[0,1]。此算法总是生成浮点像素。
var img_cast = img.cast({'B3':'long','B4':'double','B5':'float'},['B3','B4','B5'])
//img.cast() 将图像的部分或全部带区强制转换为指定类型
print(img,img_unitScale,img_cast)
Image.set()、Image.setMulti()
var modis = ee.ImageCollection("MODIS/006/MOD09A1");
var img=modis.first()
print(img)
print(img.set('createDate',2020).setMulti({'author':'lijiang', 'age':'22'}))
Image.remap()
var img_cover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3");
var Old_Id = ee.List([11,14,20,30,40,50,60,70,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230])
var New_Id = ee.List([0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 7, 8])
var Land_Cover = img_cover.select('landcover');
var Land_Remap = Land_Cover.remap(Old_Id,New_Id,8,'landcover')
print(Land_Cover,Land_Remap)
Map.setCenter(102.919, 30.199,6)
Map.addLayer(Land_Cover)
Map.addLayer(Land_Remap,{"palette":["f1ff27","35ce48","07fff3","f017ff","e78845","250bff","ffffff","ffffff"]},
'remaped')
Image的比较筛选:
var night_Light = ee.ImageCollection("NOAA/DMSP-OLS/NIGHTTIME_LIGHTS"),
sichuan = ee.FeatureCollection("users/lcljv1066965/test/sichuan");
var img_night_Light =night_Light.select('stable_lights').first().clip(sichuan);
var urban = img_night_Light.gte(2)//筛选夜晚灯光亮度值>=2
Map.centerObject(sichuan);
Map.addLayer(urban, {"opacity":0.33,"bands":["stable_lights"],"palette":["171801","fbff0f"]}, 'Nighttime Light');
Image的数学运算:Image.add() 等等
var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT");
var img = l8.filterBounds(ee.Geometry.Point(106.5749, 29.5588)).first()
var B5 = ee.Image(img.select('B5'))
var B4 = ee.Image(img.select('B4'))
var NDVI = B5.subtract(B4).divide(B5.add(B4))//NDVI计算可用函数计算 也可map表达式
Map.centerObject(NDVI)
Map.addLayer(NDVI,{"min":-1,"max":1,"palette":["0f01e2","ff9d93","fff707","11ff2e","04ce14"]})
Image的表达式计算:Image.expression()
var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT");
var img = l8.filterBounds(ee.Geometry.Point(106.5749, 29.5588)).first()
var evi = img.expression(
'2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))', {
'NIR': img.select('B5'),
'RED': img.select('B4'),
'BLUE': img.select('B2')
});
Map.centerObject(evi)
Map.addLayer(evi,{"min":-1,"max":1,"palette":["0f01e2","ff9d93","fff707","11ff2e","04ce14"]})