其他
rgee学习笔记之Image(一)
rgee学习笔记之Image(一)
前面学习了一些入门小实例,接下来对Image进行详细学习
进行实例练习前先启动rgee
library(rgee)
ee_Initialize()
后面是详细的章节学习:
Image Overview
# 创建一个值为1的连续图像
# Create a constant Image with a pixel value of 1
image1 <- ee$Image(1)
print(image1, type = "json")
print(image1, type = "simply")
print(image1, type = "ee_print")
Map$addLayer(image1)
Image Visualization
Landsat8 标准假彩色合成显示:
# Simple RGB Vizualization -Landsat
image <- ee$Image("LANDSAT/LC8_L1T_TOA/LC80440342014077LGN00")
vizParams <- list(
min = 0,
max = 0.5,
bands = c("B5", "B4", "B3"),
gamma = c(0.95, 1.1, 1)
)
Map$setCenter(-122.1899, 37.5010, 10)
Map$addLayer(image, vizParams)
计算NDWI 提取NDWI>0.4的区域 制作缓冲区(缓冲区半径以米为单位) 多图层显示 一个“Landsat 8”图层 一个“NDWI”图层
# Simple Single-Band Vizualization
ndwi <- image$normalizedDifference(c("B3", "B5"))
ndwiViz <- list(
min = 0.5,
max = 1,
palette = c("00FFFF", "0000FF")
)
## Masking
ndwiMasked <- ndwi$updateMask(ndwi$gte(0.4))
## Produce an RGB layers.
imageRGB <- image$visualize(
list(
bands = c("B5", "B4", "B3"),
max = 0.5
)
)
ndwiRGB <- ndwiMasked$visualize(
list(
min = 0.5,
max = 1,
palette = c("00FFFF", "0000FF")
)
)
# Mosaic the visualization layers and display( or export).
roi <- ee$Geometry$Point(c(-122.4481, 37.7599))$buffer(20000)
Map$centerObject(image$clip(roi))
Map$addLayer(
eeObject = image$clip(roi),
visParams = vizParams,
name = "Landsat 8"
) +
Map$addLayer(
eeObject = ndwiMasked$clip(roi),
visParams = ndwiViz,
name = "NDWI"
)
Image information and metadata
获取影像的信息和元数据。
获取影像的波段名称:
# Load an Landsat8 Image - San Francisco, California.
image <- ee$Image("LANDSAT/LC8_L1T/LC80440342014077LGN00")
# Get Band names of an ee$Image
bandNames <- image$bandNames()
ee_help(bandNames)
cat("Band names: ", paste(bandNames$getInfo(), collapse = " "))
上面的代码运行到ee_help
会报错:
报错怎么办呢?是无法运行了吗?
ee_help
在rgee中的作用是启动rgee的帮助,rgee的帮助和R语言中的帮助不太一样,rgee中的帮助无法直接通过?+函数的方式调用,而是需要使用ee_help
。
这个ee_help
报错是无法识别这个bandNames的情况,那么如何方便快捷的使用ee_help
呢?
有办法!Rstudio里面,Tools- Modify Keyboard Shortcuts
给ee_help
指定个快捷键就好了嘛
把鼠标光标放置到有疑问的地方,按下键盘F3(前面我给ee_help
指定的快捷键)
就可以看到ee_help的结果啦:
查看影像空间参考
b1proj <- image$select("B1")$projection()$getInfo()
cat("Band 1 projection: ")
cat("type: ", b1proj$type)
cat("crs: ", b1proj$crs)
cat("geotransform: ", paste0(b1proj$transform, " "))
影像分辨率、云量、元数据等
scale:分辨率 CLOUD_COVER:云量
b1scale <- image$select("B1")$projection()$nominalScale()
cat("Band 1 scale: ", b1scale$getInfo())
b8scale <- image$select("B8")$projection()$nominalScale()
cat("Band 8 scale: ", b8scale$getInfo())
properties <- image$propertyNames()$getInfo()
cat("Metadata properties: \n-", paste0(properties, collapse = "\n- "))
cloudiness <- image$get("CLOUD_COVER")$getInfo()
cat("CLOUD_COVER: ", cloudiness)
影像时间
eedate_to_rdate
简单粗暴的命名,就是GEE里面的时间转到R里面
iso_date <- eedate_to_rdate(image$get("system:time_start"))
iso_timestamp <- eedate_to_rdate(
ee_date = image$get("system:time_start"),)
cat("ISO Date: ", as.character(iso_date))
cat("Timestamp : ", format(iso_timestamp, scientific = FALSE))
本篇笔记到此结束,这一部分主要是rgee中Image的展示,以及元数据等基本影像信息的获取
更多rgee资料请关注#rgee