GEE python:按照矢量中的几何位置、属性名称和字符串去筛选矢量集合

本文涉及的产品
函数计算FC,每月15万CU 3个月
简介: GEE python:按照矢量中的几何位置、属性名称和字符串去筛选矢量集合

要按照矢量中的几何位置去筛选矢量集合,您可以使用空间查询或选择工具。以下是一些示例:

  1. 空间查询工具:许多GIS软件都具有空间查询工具,可帮助您筛选矢量。您可以使用矩形选择工具、圆形选择工具或多边形选择工具选择特定区域的矢量。还可以使用空间查询语言(例如SQL)编写复杂的查询来识别满足特定条件的矢量,例如在指定距离内的点或多边形。
  2. 编写自定义脚本或程序:如果您需要更复杂的筛选,可以编写自定义脚本或程序来筛选矢量。可以使用Python、C ++或其他编程语言来构建您的脚本或程序,以根据坐标、属性或其他条件筛选矢量。
  3. 使用地图编辑器:一些GIS软件具有地图编辑器,其中包括选择和编辑矢量的工具。这些工具可帮助您在地图上选择特定区域的矢量,并进行编辑或删除。

无论您选择哪种方法,都应该先确定筛选条件,然后使用适当的工具来筛选矢量集合。

安装地球引擎API和geemap

安装地球引擎的Python API和geemap。geemap Python包是建立在ipyleaflet和folium包之上的,它实现了几个与地球引擎数据层交互的方法,比如Map.addLayer()、Map.setCenter()和Map.centerObject()。下面的脚本检查geemap包是否已经安装。如果没有,它将安装geemap,它会自动安装其依赖项,包括earthengine-api、folium和ipyleaflet。

Installs geemap package

import subprocess
try:
    import geemap
except ImportError:
    print('Installing geemap ...')
    subprocess.check_call(["python", '-m', 'pip', 'install', 'geemap'])
import ee
import geemap

函数:

ee.Filter.contains(leftField, rightValue, rightField, leftValue, maxError)

Creates a unary or binary filter that passes if the left geometry contains the right geometry (empty geometries are not contained in anything).

这里需要明确的一点就是这里的Filed就是我们集合中的属性名称,value就是值,这里一般会设定,按照名称或者是属性值的后缀来筛选

Arguments:

leftField (String, default: null):

A selector for the left operand. Should not be specified if leftValue is specified.

rightValue (Object, default: null):

The value of the right operand. Should not be specified if rightField is specified.

rightField (String, default: null):

A selector for the right operand. Should not be specified if rightValue is specified.

leftValue (Object, default: null):

The value of the left operand. Should not be specified if leftField is specified.

maxError (ErrorMargin, optional):

The maximum reprojection error allowed during filter application.

Returns: Filter

代码:

# Add Earth Engine dataset
HUC10 = ee.FeatureCollection("USGS/WBD/2017/HUC10")
HUC08 = ee.FeatureCollection('USGS/WBD/2017/HUC08')
roi = HUC08.filter(ee.Filter.eq('name', 'Pipestem'))
Map.centerObject(roi, 10)
Map.addLayer(ee.Image().paint(roi, 0, 3), {}, 'HUC08')
# select polygons intersecting the roi
roi2 = HUC10.filter(ee.Filter.contains(**{'leftValue': roi.geometry(), 'rightField': '.geo'}))
Map.addLayer(ee.Image().paint(roi2, 0, 2), {'palette': 'blue'}, 'HUC10')
roi3 = HUC10.filter(ee.Filter.stringContains(**{'leftField': 'huc10', 'rightValue': '10160002'}))
print(roi3.getInfo())
Map.addLayer(roi3)

结果:

{‘type’: ‘FeatureCollection’, ‘columns’: {‘areaacres’: ‘String’, ‘areasqkm’: ‘String’, ‘gnis_id’: ‘String’, ‘huc10’: ‘String’, ‘humod’: ‘String’, ‘hutype’: ‘String’, ‘loaddate’: ‘String’, ‘metasource’: ‘String’, ‘name’: ‘String’, ‘shape_area’: ‘String’, ‘shape_leng’: ‘String’, ‘sourcedata’: ‘String’, ‘sourcefeat’: ‘String’, ‘sourceorig’: ‘String’, ‘states’: ‘String’, ‘system:index’: ‘String’, ‘tnmid’: ‘String’},。。。。

代码:

# Add Earth Engine dataset
# Select North Dakota and South Dakota
fc = ee.FeatureCollection('TIGER/2018/States') \
    .filter(ee.Filter.Or(
        ee.Filter.eq('STUSPS', 'ND'),
        ee.Filter.eq('STUSPS', 'SD'),
    ))
image = ee.Image().paint(fc, 0, 2)
# Map.setCenter(-99.844, 37.649, 5)
Map.centerObject(fc, 6)
Map.addLayer(image, {'palette': 'FF0000'}, 'TIGER/2018/States')

ee.Filter.stringContains(leftField, rightValue, rightField, leftValue)

Creates a unary or binary filter that passes if the left operand, a string, contains the right operand, also a string.

Arguments:

leftField (String, default: null):

A selector for the left operand. Should not be specified if leftValue is specified.

rightValue (Object, default: null):

The value of the right operand. Should not be specified if rightField is specified.

rightField (String, default: null):

A selector for the right operand. Should not be specified if rightValue is specified.

leftValue (Object, default: null):

The value of the left operand. Should not be specified if leftField is specified.

Returns: Filter

ee.Filter.stringStartsWith(leftField, rightValue, rightField, leftValue)

Creates a unary or binary filter that passes if the left operand, a string, starts with the right operand, also a string.

Arguments:

leftField (String, default: null):

A selector for the left operand. Should not be specified if leftValue is specified.

rightValue (Object, default: null):

The value of the right operand. Should not be specified if rightField is specified.

rightField (String, default: null):

A selector for the right operand. Should not be specified if rightValue is specified.

leftValue (Object, default: null):

The value of the left operand. Should not be specified if leftField is specified.

Returns: Filter

按照字符串去筛选:

# Add Earth Engine dataset
#!/usr/bin/env python
"""Select by strings
"""
# Select states with "A" in its name
fc = ee.FeatureCollection('TIGER/2018/States') \
    .filter(ee.Filter.stringContains('STUSPS', 'A'))
image = ee.Image().paint(fc, 0, 2)
Map.centerObject(fc, 6)
Map.addLayer(image, {'palette': 'FF0000'}, '*A*')
# Select states its name starting with 'A'
fc = ee.FeatureCollection('TIGER/2018/States') \
    .filter(ee.Filter.stringStartsWith('STUSPS', 'A'))
image = ee.Image().paint(fc, 0, 2)
Map.addLayer(image, {'palette': '0000FF'}, 'A*')
相关实践学习
【AI破次元壁合照】少年白马醉春风,函数计算一键部署AI绘画平台
本次实验基于阿里云函数计算产品能力开发AI绘画平台,可让您实现“破次元壁”与角色合照,为角色换背景效果,用AI绘图技术绘出属于自己的少年江湖。
从 0 入门函数计算
在函数计算的架构中,开发者只需要编写业务代码,并监控业务运行情况就可以了。这将开发者从繁重的运维工作中解放出来,将精力投入到更有意义的开发任务上。
相关文章
|
3天前
|
Java 数据处理 索引
(Pandas)Python做数据处理必选框架之一!(二):附带案例分析;刨析DataFrame结构和其属性;学会访问具体元素;判断元素是否存在;元素求和、求标准值、方差、去重、删除、排序...
DataFrame结构 每一列都属于Series类型,不同列之间数据类型可以不一样,但同一列的值类型必须一致。 DataFrame拥有一个总的 idx记录列,该列记录了每一行的索引 在DataFrame中,若列之间的元素个数不匹配,且使用Series填充时,在DataFrame里空值会显示为NaN;当列之间元素个数不匹配,并且不使用Series填充,会报错。在指定了index 属性显示情况下,会按照index的位置进行排序,默认是 [0,1,2,3,...] 从0索引开始正序排序行。
44 0
|
21天前
|
Python
Python中的f-string:更优雅的字符串格式化
Python中的f-string:更优雅的字符串格式化
205 100
|
21天前
|
开发者 Python
Python中的f-string:高效字符串格式化的利器
Python中的f-string:高效字符串格式化的利器
249 99
|
24天前
|
Python
Python中的f-string:更优雅的字符串格式化
Python中的f-string:更优雅的字符串格式化
|
24天前
|
开发者 Python
Python f-strings:更优雅的字符串格式化技巧
Python f-strings:更优雅的字符串格式化技巧
|
24天前
|
开发者 Python
Python f-string:高效字符串格式化的艺术
Python f-string:高效字符串格式化的艺术
|
3天前
|
存储 Java 索引
(Python基础)新时代语言!一起学习Python吧!(二):字符编码由来;Python字符串、字符串格式化;list集合和tuple元组区别
字符编码 我们要清楚,计算机最开始的表达都是由二进制而来 我们要想通过二进制来表示我们熟知的字符看看以下的变化 例如: 1 的二进制编码为 0000 0001 我们通过A这个字符,让其在计算机内部存储(现如今,A 字符在地址通常表示为65) 现在拿A举例: 在计算机内部 A字符,它本身表示为 65这个数,在计算机底层会转为二进制码 也意味着A字符在底层表示为 1000001 通过这样的字符表示进行转换,逐步发展为拥有127个字符的编码存储到计算机中,这个编码表也被称为ASCII编码。 但随时代变迁,ASCII编码逐渐暴露短板,全球有上百种语言,光是ASCII编码并不能够满足需求
25 3
|
24天前
|
机器学习/深度学习 数据采集 并行计算
多步预测系列 | LSTM、CNN、Transformer、TCN、串行、并行模型集合研究(Python代码实现)
多步预测系列 | LSTM、CNN、Transformer、TCN、串行、并行模型集合研究(Python代码实现)
199 2
|
存储 Python
Python中,集合(Set)
Python中,集合(Set)
134 1
|
存储 索引 Python
Python中的集合(Set)
Python中的集合(Set)
156 3

热门文章

最新文章

  • 1
    Python零基础爬取东方财富网股票行情数据指南
    46
  • 2
    解析Python爬虫中的Cookies和Session管理
    46
  • 3
    Python日志模块配置:从print到logging的优雅升级指南
    37
  • 4
    【可视化大屏】全流程讲解用python的pyecharts库实现拖拽可视化大屏的背后原理,简单粗暴!
    40
  • 5
    (Pandas)Python做数据处理必选框架之一!(二):附带案例分析;刨析DataFrame结构和其属性;学会访问具体元素;判断元素是否存在;元素求和、求标准值、方差、去重、删除、排序...
    44
  • 6
    (Pandas)Python做数据处理必选框架之一!(一):介绍Pandas中的两个数据结构;刨析Series:如何访问数据;数据去重、取众数、总和、标准差、方差、平均值等;判断缺失值、获取索引...
    72
  • 7
    (numpy)Python做数据处理必备框架!(二):ndarray切片的使用与运算;常见的ndarray函数:平方根、正余弦、自然对数、指数、幂等运算;统计函数:方差、均值、极差;比较函数...
    42
  • 8
    (numpy)Python做数据处理必备框架!(一):认识numpy;从概念层面开始学习ndarray数组:形状、数组转置、数值范围、矩阵...
    61
  • 9
    (Python基础)新时代语言!一起学习Python吧!(四):dict字典和set类型;切片类型、列表生成式;map和reduce迭代器;filter过滤函数、sorted排序函数;lambda函数
    32
  • 10
    (Python基础)新时代语言!一起学习Python吧!(三):IF条件判断和match匹配;Python中的循环:for...in、while循环;循环操作关键字;Python函数使用方法
    53
  • 推荐镜像

    更多