forked from fitoprincipe/geetools-code-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools
71 lines (60 loc) · 2.42 KB
/
tools
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*********************************
* Some tools
* Author: Rodrigo E. Principe
* License: Apache 2.0
* email: [email protected]
* page: https://github.com/fitoprincipe/geetools-code-editor/wiki
**********************************/
var helpersJS = require('users/fitoprincipe/geetools:helpers_js')
var string = require('users/fitoprincipe/geetools:_tools/string').string
var date = require('users/fitoprincipe/geetools:_tools/date').date
var collection = require('users/fitoprincipe/geetools:_tools/collection').collection
var geometry = require('users/fitoprincipe/geetools:_tools/geometry').geometry
var image = require('users/fitoprincipe/geetools:_tools/image').image
var imageCollection = require('users/fitoprincipe/geetools:_tools/imagecollection').imageCollection
var map = require('users/fitoprincipe/geetools:_tools/map').map
var number = require('users/fitoprincipe/geetools:_tools/number').number
var featureCollection = require('users/fitoprincipe/geetools:_tools/featurecollection').featureCollection
var feature = require('users/fitoprincipe/geetools:_tools/feature').feature
var list = require('users/fitoprincipe/geetools:_tools/list').list
var dictionary = require('users/fitoprincipe/geetools:_tools/dictionary').dictionary
// INTERNAL
exports.get_options = helpersJS.get_options
/** MISC */
// UUID4
// from https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript#answer-21963136
var uuid4 = helpersJS.uuid4
exports.uuid4 = uuid4
// COMPUTE BITS
var computeQAbits = function(start, end, newName) {
var pattern = ee.Number(0)
start = ee.Number(start).toInt()
end = ee.Number(end).toInt()
newName = ee.String(newName)
var seq = ee.List.sequence(start, end)
var patt = seq.iterate(
function(element, ini) {
ini = ee.Number(ini)
var bit = ee.Number(2).pow(ee.Number(element));
return ini.add(bit)
}, pattern)
patt = ee.Number(patt).toInt()
var wrap = function(image) {
var good_pix = image.select([0], [newName]).bitwiseAnd(patt).rightShift(start);
return good_pix.toInt()
}
return wrap
}
exports.computeQAbits = computeQAbits
exports.geometry = geometry
exports.string = string
exports.image = image
exports.map = map
exports.number = number
exports.feature = feature
exports.list = list
exports.dictionary = dictionary
exports.featureCollection = featureCollection
exports.imageCollection = imageCollection
exports.collection = collection
exports.date = date