当前位置:网站首页>GEE(6):设置计算数值/影像保留小数位数
GEE(6):设置计算数值/影像保留小数位数
2022-07-16 06:12:00 【BetterQ.】
对于数字和影像有时需要对结果保留N位小数,数字和影像保留小数位数的方法不同,下面分别对其介绍。
在GEE中ee.Number的API,其中有一个方法 format(),它就是设置数字格式的。
比如上面的需求就是 ee.Number(10.123456789).format('%.3f’)。需要注意的是这里返回的是一个字符串,如果后续还有其他计算需要使用ee.Number.parse()来转换。
1. 数字:
//假设计算结果为a为小数
var a = 1.23456789;
//想要对计算结果保留三位小数,此时转换结果为字符串类型
var b = ee.Number(a).format('%.3f');
print(b);
//可以用ee.Number.parse()将其转换为Number类型
var c = ee.Number.parse(b);
var d = c.add(3);
print(c,d);
.
.
2. 影像
如果是对影像计算,想要将其保留n位小数的计算结果,比如计算得到的NDVI,想要对结果保留5位小数,可以采取将其想扩大一定的倍数,再转化为整数,再除以该倍数。
示例:
//影像保留5位小数
//比如原始影像计算结果为img
var img = ee.Image.constant(1.23456789);
Map.addLayer(img, {
}, "img");
//1.23456789×100000=123456.789,转为整数型为:123456
//123456÷100000=1.23456
var newImg = img.multiply(100000).toInt().divide(100000);
Map.addLayer(newImg, {
}, "newImg");
这里先对影像扩大100000倍,将其转为INT型,再除以100000,从而得到想要的结果。
边栏推荐
- Design of hydrogen monitoring and alarm system based on single chip microcomputer (0492)
- IDEA集成Gerrit插件
- SQL statement
- I "bring salt" for tdengine! "High price" to recruit photographed developers
- 前 K 个高频元素问题
- 用训练集去重构权重空间的几何形态
- Kaldi source code installation
- In depth learning (2020 Li Hongyi) learning records
- Methods and extensions of array objects, extension methods of strings, and traversal of arrays in ES6
- 基于单片机的氢气监测系统设计(#0491)
猜你喜欢

Ziguang Tongchuang FPGA development jump pit Guide (V) -- DDR3 controller IP simulation

Altium designer schematic generation PCB

IO会一直占用CPU吗?一个很好的关于并发/并行系统的问题(转)

全网首发独发:如何避免因为调用了没有实现的类方法而造成APP崩溃

直线上最多的点数问题

Codeforces Global Round 21 B. NIT Destroys the Universe

Design of intelligent speech recognition Bluetooth headset based on wtk6900h speech recognition single chip

5. Redis architecture design to usage scenario - storage principle - data type infrastructure

Codeforces Round #803 (Div. 2) A. XOR Mixup

压力测试工具(常用)和sendfile的过程
随机推荐
I "bring salt" for tdengine! "High price" to recruit photographed developers
用swift5 新写一个app需要用到需要考虑的
网络安全实验:防火墙技术
angr原理与实践(一)——原理
Nc16857 [noi1999] birthday cake
关于mock第三方调用
altium designer怎么添加元件库
二进制搭建 Kubernetes
Codeforces Round #803 (Div. 2) D. Fixed Point Guessing
基于单片机的蓝牙电子秤系统设计(#0493)
Solve the problem of Vue multi-level route cache invalidation solve the problem of multi-level route cache based on keep alive Vue keep alive cache invalidation Vue element admin multi-level route cac
【Leetcode】2115. Find All Possible Recipes from Given Supplies
求数据流中的中位数问题
Interview reply 2 (summarize the bad answers in the interview)
Points clés pour la mise à niveau du firmware d'aegnus air820ug
Codeforces Round #803 (Div. 2) A. XOR Mixup
WWDC22 - In App Purchase 更新总结
How about the income of increased life insurance? Can it be a pension financial product?
指针常量与常量指针
Is there a trap for Huatai Securities to open an account? Is it safe to open an account online?