当前位置:网站首页>Gee (6): set the number of decimal places reserved for the calculated value / image
Gee (6): set the number of decimal places reserved for the calculated value / image
2022-07-18 14:48:00 【BetterQ.】
For numbers and images, it is sometimes necessary to preserve the results N Decimal place , Numbers and images retain decimal places in different ways , Here are their introductions .
stay GEE in ee.Number Of API, There's a way format(), It is to set the number format .
For example, the above requirements are ee.Number(10.123456789).format('%.3f’). It should be noted that what is returned here is a string , If there are other calculations to be used later ee.Number.parse() To convert .
1. Numbers :
// Suppose the calculation result is a Is a decimal
var a = 1.23456789;
// Want to keep three decimal places for the calculation result , At this time, the conversion result is of string type
var b = ee.Number(a).format('%.3f');
print(b);
// It can be used ee.Number.parse() Convert it to Number type
var c = ee.Number.parse(b);
var d = c.add(3);
print(c,d);
.
.
2. image
If it is image calculation , Want to keep it n Calculation result of decimal places , For example, calculated NDVI, Want to keep the results 5 Decimal place , It can be expanded by a certain number of times , Then convert it to an integer , Divide by this multiple .
Example :
// Image retention 5 Decimal place
// For example, the calculation result of the original image is img
var img = ee.Image.constant(1.23456789);
Map.addLayer(img, {
}, "img");
//1.23456789×100000=123456.789, Convert to integer type as :123456
//123456÷100000=1.23456
var newImg = img.multiply(100000).toInt().divide(100000);
Map.addLayer(newImg, {
}, "newImg");
Here, first expand the image 100000 times , Turn it into INT type , Divided by 100000, To get the desired results .
边栏推荐
- STM32应用开发实践教程:具备交互功能的人机界面应用开发
- Kotlin | 为 Kotlin 编译器任务推出构建报告
- 二進制搭建 Kubernetes
- Get the file name and function name of the calling function through the decorator
- 408 day attendance Chapter 8 sorting in class code collection
- Simple function relation
- 全网首发独发:如何避免因为调用了没有实现的类方法而造成APP崩溃
- How to solve the problem of high concurrency? You will understand it completely after reading it.
- Network security experiment: firewall technology
- 关于mock第三方调用
猜你喜欢

Codeforces Global Round 21 C. Fishingprince Plays With Array

Remove the problem of repeated letters (the minimum sequence of different characters)

如何用常数时间插入、删除和获取随机元素

全排序问题

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

Design of combustible gas smoke system based on single chip microcomputer (0488)

Win11 system How to enable Net Framework 3.5?

Mitmproxy getting started installation

Wechat selection and voting of applet completion works applet graduation project (8) graduation project thesis template

STM32应用开发实践教程:具备交互功能的人机界面应用开发
随机推荐
2022年R2移动式压力容器充装试题及答案
Hal firmware library
小程序毕设作品之微信评选投票小程序毕业设计(8)毕业设计论文模板
Simple function relation
4. Redis architecture design to use scenarios - string, list, set, Zset, hash use scenarios
数百亿数据压缩至 600GB,TDengine 落地协鑫能科移动能源平台
How to choose databases and tables and newsql?
GEE(6):设置计算数值/影像保留小数位数
How does DMS empower database functions?
The first one in the whole network: how to avoid app crash due to calling unimplemented class methods
全排序问题
Conditional ternary operator...
Codeforces Round #803 (Div. 2) B. Rising Sand
Which securities company is good for opening an account for mobile stock speculation? Which is safer
二进制搭建 Kubernetes
Idea integration Gerrit plug-in
Design of Bluetooth electronic scale system based on MCU (0493)
408 day attendance Chapter 8 sorting in class code collection
How Altium designer adds a catalog
出海已成大势,技术如何赋能?| ArchSummit