geemap学习笔记031:使用Earth Engine数据--FeatureCollection

发布时间:2023年12月21日

前言

本节将会详细的介绍一下Earth Engine数据类型FeatureCollection的加载、创建、Filtering、可视化等等。

1 导入库并显示地图

import ee
import geemap
ee.Initialize()

2 加载FeatureCollection

Map = geemap.Map()
fc = ee.FeatureCollection('TIGER/2016/Roads') #加载Roads FeatureCollection
Map.setCenter(-73.9596, 40.7688, 12)
Map.addLayer(fc, {}, 'Census roads')
Map

fc.limit(3) #只取前三个属性

3 创建FeatureCollection

features = [
    ee.Feature(ee.Geometry.Rectangle(30.01, 59.80, 30.59, 60.15), {'name': 'Voronoi'}),
    ee.Feature(ee.Geometry.Point(-73.96, 40.781), {'name': 'Thiessen'}),
    ee.Feature(ee.Geometry.Point(6.4806, 50.8012), {'name': 'Dirichlet'}),
]  #创建3个Feature
fromList = ee.FeatureCollection(features) #将其转为FeatureCollection

4 Filtering FeatureCollection

Map = geemap.Map()
states = ee.FeatureCollection('TIGER/2018/States')
feat = states.filter(ee.Filter.eq('NAME', 'Texas')) #筛选States属性中NAME为Texas的Feature
Map.addLayer(feat, {}, 'Texas')
Map.centerObject(feat)
Map
texas = feat.first() #虽然feat中只有一个Feature,但是依旧是FeatureCollection
texas.toDictionary()
Map = geemap.Map()
states = ee.FeatureCollection('TIGER/2018/States')
fc = states.filter(ee.Filter.inList('NAME', ['California', 'Oregon', 'Washington']))  #以列表的形式获取多个Feature
Map.addLayer(fc, {}, 'West Coast')
Map.centerObject(fc)
Map
region = Map.user_roi
if region is None:
    region = ee.Geometry.BBox(-88.40, 29.88, -77.90, 35.39)

fc = ee.FeatureCollection('TIGER/2018/States').filterBounds(region) #以指定区域的形式
Map.addLayer(fc, {}, 'Southeastern U.S.')
Map.centerObject(fc)

5 可视化FeatureCollection

Map = geemap.Map(center=[40, -100], zoom=4)
states = ee.FeatureCollection("TIGER/2018/States")
image = ee.Image().paint(states, 0, 3) #这一行直接是将矢量转为栅格了啊
Map.addLayer(image, {'palette': 'red'}, "US States")
Map
Map = geemap.Map(center=[40, -100], zoom=4)
states = ee.FeatureCollection("TIGER/2018/States")
style = {'color': '0000ffff', 'width': 2, 'lineType': 'solid', 'fillColor': 'FF000080'} #设置填充颜色、线的颜色、填充颜色
Map.addLayer(states.style(**style), {}, "US States") #矢量显示
Map

后记

大家如果有问题需要交流或者有项目需要合作,可以加Q Q :504156006详聊,加好友请留言“CSDN”,谢谢。

文章来源:https://blog.csdn.net/qq_41951977/article/details/135045391
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。