Google Earth Engine(GEE)——让点的个数等于number返回的布尔类型值为真?

简介: Google Earth Engine(GEE)——让点的个数等于number返回的布尔类型值为真?

   问题是这样的,有时候我们明明看到结果是一致的,但是为啥运算出来的东西却不一样呢?我们可以具体看看到底是为啥,有朋友闻到了这样的问题,我们可以具体看看这个问题:

这个结果是 True 我该怎么做?

修正前的代码:

var points=ee.Geometry.MultiPoint([[35.13382554493316, 42.01690078898458],
 [35.127720870209764, 42.023546081055784]])
Map.addLayer(points)
var p=points.coordinates().size()
print(p)
print(p==ee.Number(2))

image.png

这里我们所需要用到的就是我么判断是否相等的算法,具体算法见如下

ee.Algorithms.IsEqual(left, right)

Returns whether two objects are equal.返回两个对象是否相等。

Arguments:

left (Object, default: null)

right (Object, default: null)

Returns: Boolean

修正后代码:

var points=ee.Geometry.MultiPoint([[35.13382554493316, 42.01690078898458],
 [35.127720870209764, 42.023546081055784]])
Map.addLayer(points)
var p=points.coordinates().size()
print(p)
var ff= ee.Algorithms.IsEqual(p,ee.Number(2))
print(ff)

image.png

这里还有一种方式:

getInfo(callback)

Retrieves the value of this object from the server.

If no callback function is provided, the request is made synchronously. If a callback is provided, the request is made asynchronously.

The asynchronous mode is preferred because the synchronous mode stops all other code (for example, the EE Code Editor UI) while waiting for the server. To make an asynchronous request, evaluate() is preferred over getInfo().

Returns the computed value of this object.

Arguments:

this:computedobject (ComputedObject):

The ComputedObject instance.

callback (Function, optional):

An optional callback. If not supplied, the call is made synchronously.

Returns: Object

getInfo(callback)

从服务器上检索此对象的值。

如果没有提供回调函数,请求是同步进行的。如果提供了一个回调函数,请求是异步进行的。

异步模式是首选,因为同步模式在等待服务器时停止所有其他代码(例如,EE代码编辑器用户界面)。为了进行异步请求,evaluate()比getInfo()更适合。

返回这个对象的计算值。

参数。

this:computedobject (ComputedObject)。

计算对象的实例。

callback(函数,可选)。

一个可选的回调。如果不提供,调用将同步进行。

返回。对象

var points=ee.Geometry.MultiPoint([[35.13382554493316, 42.01690078898458],
 [35.127720870209764, 42.023546081055784]])
Map.addLayer(points)
var s1=ee.Number(points.coordinates().size())
print(s1.eq(ee.Number(2)))
print(s1.eq(ee.Number(2))==1)
print(s1.eq(ee.Number(2)).getInfo()==1)

结果:

image.png

当然除了用上面判断是否相等之外,还可以使用下面的函数来进行判断:条件,真假的情况是什么都可以的。

ee.Algorithms.If(condition, trueCase, falseCase)

Selects one of its inputs based on a condition, similar to an if-then-else construct.

Arguments:

condition (Object, default: null):

The condition that determines which result is returned. If this is not a boolean, it is interpreted as a boolean by the following rules:

  • Numbers that are equal to 0 or a NaN are false.
  • Empty strings, lists and dictionaries are false.
  • Null is false.
  • Everything else is true.

trueCase (Object, default: null):

The result to return if the condition is true.

falseCase (Object, default: null):

The result to return if the condition is false.

Returns: Object

这里还有一种情况,就是当我们反映真假得时候,我们可以用到0和1而不是true和法拉瑟,其实很简单。

var points=ee.Geometry.MultiPoint([[35.13382554493316, 42.01690078898458],
 [35.127720870209764, 42.023546081055784]])
Map.addLayer(points)
var s1=ee.Number(points.coordinates().size())
print('s1', s1)
print('s1.eq(ee.Number(2))', s1.eq(ee.Number(2)))
print('s1.eq(ee.Number(3))', s1.eq(ee.Number(3)))


image.png


相关文章
|
1月前
|
数据可视化 定位技术 Sentinel
如何用Google Earth Engine快速、大量下载遥感影像数据?
【2月更文挑战第9天】本文介绍在谷歌地球引擎(Google Earth Engine,GEE)中,批量下载指定时间范围、空间范围的遥感影像数据(包括Landsat、Sentinel等)的方法~
1153 1
如何用Google Earth Engine快速、大量下载遥感影像数据?
|
1月前
|
机器学习/深度学习 算法 数据可视化
基于Google Earth Engine云平台构建的多源遥感数据森林地上生物量AGB估算模型含生物量模型应用APP
基于Google Earth Engine云平台构建的多源遥感数据森林地上生物量AGB估算模型含生物量模型应用APP
148 0
|
1月前
GEE——Google dynamic world中在影像导出过程中无法完全导出较大面积影像的解决方案(投影的转换)EPSG:32630和EPSG:4326的区别
GEE——Google dynamic world中在影像导出过程中无法完全导出较大面积影像的解决方案(投影的转换)EPSG:32630和EPSG:4326的区别
59 0
|
1月前
|
SQL Oracle 关系型数据库
实时计算 Flink版产品使用合集之使用JDBC方式读取Oracle的number类型时,通过什么方式进行映射
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
实时计算 Flink版产品使用合集之使用JDBC方式读取Oracle的number类型时,通过什么方式进行映射
|
1月前
|
存储 编解码 数据可视化
Google Earth Engine获取随机抽样点并均匀分布在栅格的不同数值区中
【2月更文挑战第14天】本文介绍在谷歌地球引擎(Google Earth Engine,GEE)中,按照给定的地表分类数据,对每一种不同的地物类型,分别加以全球范围内随机抽样点自动批量选取的方法~
315 1
Google Earth Engine获取随机抽样点并均匀分布在栅格的不同数值区中
|
1月前
|
存储
TS 自定义结构Long与number类型相互转换
TS 自定义结构Long与number类型相互转换
|
1月前
|
API Go 网络架构
GEE Colab——如何从本地/Google云盘/Google Cloud Storage (GCS)上传和下载
GEE Colab——如何从本地/Google云盘/Google Cloud Storage (GCS)上传和下载
150 4
|
1月前
|
机器学习/深度学习 存储 人工智能
GEE Colab——初学者福音快速入门 Google Colab(Colaboratory)
GEE Colab——初学者福音快速入门 Google Colab(Colaboratory)
109 3
|
1月前
|
Python
GEE—关于RSEI生态遥感指数中出现的问题 Layer error: Image.rename: The number of names (1) must match the number of..
GEE—关于RSEI生态遥感指数中出现的问题 Layer error: Image.rename: The number of names (1) must match the number of..
62 0
|
1月前
|
数据处理
Google Earth Engine(GEE)——sentinel-1数据处理过程中出现错误Dictionary does not contain key: bucketMeans
Google Earth Engine(GEE)——sentinel-1数据处理过程中出现错误Dictionary does not contain key: bucketMeans
45 0