gee学习2数据获取、数据筛选、创建地理要素

gee学习2 gee数据使用

运行ee前先运行进行初始化

geemap.ee_initialize()

一、图层加载

gee中的图像数据有两种一种是image,另一种是imagecollection.
###图像的id获取方法
可以在https://developers.google.com/earth-engine/datasets/中点击图像后复制
在这里插入图片描述
此外也可以直接在Map中
在这里插入图片描述
在这里直接搜索数据后获取。
知道影像ID或部分知道的画可以用下面的方法加载影像

from geemap.datasets import DATA
Map = geemap.Map(center=[40, -100], zoom=4)
dataset = ee.Image(DATA.USGS_GAP_CONUS_2011)#可以先写前面几个字母再按tab键选择
Map.addLayer(dataset, {}, 'GAP CONUS')
Map
from geemap.datasets import get_metadata
get_metadata(DATA.USGS_GAP_CONUS_2011)#获取元数据

image的加载方法

image 指的是单个的图像

Map = geemap.Map(center=[21.79, 70.87], zoom=3)
image = ee.Image('USGS/SRTMGL1_003')
vis_params = {
    'min': 0,
    'max': 6000,
    'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],
    #"bands": ["B3", "B2", "B1"],需要添加波段数据
}
Map.addLayer(image, vis_params, 'SRTM')
Map

如果想看影像信息

image.getInfo()

gee.Map()的用法参考https://ipyleaflet.readthedocs.io/en/latest/api_reference/map.html

添加图层:
Map.addLayer(ee_object, vis_params={}, name=None, shown=True, opacity=1.0)
ee_object (Collection|Feature|Image|MapId): The object to add to the map.
vis_params (dict, optional): The visualization parameters. Defaults to {}.
name (str, optional): The name of the layer. Defaults to ‘Layer N’.
shown (bool, optional): A flag indicating whether the layer should be on by default. Defaults to True.
opacity (float, optional): The layer’s opacity represented as a number between 0 and 1. Defaults to 1.
通过vis_params可以调整最大、最小值,颜色显示、波段显示等。

imagecollection的加载方法

imagecollection指的是图像集

collection = ee.ImageCollection('COPERNICUS/S2_SR')
Map = geemap.Map()
collection = ee.ImageCollection('COPERNICUS/S2_SR')
image = collection.median()#获取所有图像的平均像元值

vis = {
    'min': 0.0,
    'max': 3000,
    'bands': ['B4', 'B3', 'B2'],
}

Map.setCenter(83.277, 17.7009, 12)
Map.addLayer(image, vis, 'Sentinel-2')
Map

查看collection的方法可以用collection.size().getInfo()方法,运行速度取决于图像集的大小。

二 图像筛选

载入本地shape文件

Map = geemap.Map()
data = r"C:\Users\lenovo\geelearn\geemap-master\examples\data\countries.shp"
fc = geemap.shp_to_ee(data)
Map.addLayer(fc,{},"Countries")
Map

定义地图中心至区域中心

Map.CenterObject()

筛选

Map = geemap.Map()
collection = (
    ee.ImageCollection('COPERNICUS/S2_SR')
    .filterDate('2021-01-01', '2022-01-01')  #按日期筛选
    .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 5))  #按属性,这里是用云量筛选
    .filterBounds(fc)
)
image = collection.median() #筛选后的数据进行平均

vis = {
    'min': 0.0,
    'max': 3000,
    'bands': ['B8', 'B4', 'B3'],
}

Map.setCenter(83.277, 17.7009, 12)
Map.addLayer(image, vis, 'Sentinel-2')
Map

.filterBounds()方法可以筛选指定区域的数据

更多筛选参数可查看https://developers.google.com/earth-engine/apidocs/ee-filter

Map上画的矢量存在user_roi里,可以直接通过.user_roi方法调用。

查看影响分辨率

image.projection().nominalScale().getInfo()

列表里筛选

fc.filter(ee.Filter.inList('ISO_A3',['USA','CAN','MEX']]

边界裁剪

image = collection.median().clipToCollection(china)

添加不同地理元素

Map = geemap.Map()

point = ee.Geometry.Point([1.5, 1.5])

lineString = ee.Geometry.LineString([[-35, -10], [35, -10], [35, 10], [-35, 10]])

linearRing = ee.Geometry.LinearRing(
    [[-35, -10], [35, -10], [35, 10], [-35, 10], [-35, -10]]
)

rectangle = ee.Geometry.Rectangle([-40, -20, 40, 20])

polygon = ee.Geometry.Polygon([[[-5, 40], [65, 40], [65, 60], [-5, 60], [-5, 60]]])

Map.addLayer(point, {}, 'Point')
Map.addLayer(lineString, {}, 'LineString')
Map.addLayer(linearRing, {}, 'LinearRing')
Map.addLayer(rectangle, {}, 'Rectangle')
Map.addLayer(polygon, {}, 'Polygon')
Map
Map = geemap.Map()

point = ee.Geometry.Point([1.5, 1.5])

lineString = ee.Geometry.LineString(
    [[-35, -10], [35, -10], [35, 10], [-35, 10]], None, False
)

linearRing = ee.Geometry.LinearRing(
    [[-35, -10], [35, -10], [35, 10], [-35, 10], [-35, -10]], None, False
)

rectangle = ee.Geometry.Rectangle([-40, -20, 40, 20], None, False)

polygon = ee.Geometry.Polygon(
    [[[-5, 40], [65, 40], [65, 60], [-5, 60], [-5, 60]]], None, False
)

Map.addLayer(point, {}, 'Point')
Map.addLayer(lineString, {}, 'LineString')
Map.addLayer(linearRing, {}, 'LinearRing')
Map.addLayer(rectangle, {}, 'Rectangle')
Map.addLayer(polygon, {}, 'Polygon')
Map

如果想获得image的所有字段可以用
1.

props = geemap.image_props(image)
props.getInfo()
image.toDictionary().getInfo()
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值