Skip to content
Rodrigo E. Principe edited this page Oct 25, 2018 · 17 revisions

This is the most important module of the package. It is divided in the following scopes:

NOTE: In all examples it's assumed that the module is imported at first:

var tools = require('users/fitoprincipe/geetools:tools');

string

format(string)

Format a string using curly brackets.

var string = ee.String('Hello {name}')
var formatted = tools.string.format(string, {name: 'Rodrigo'})
print('Formatted string', formatted)

https://code.earthengine.google.com/f827a5c9d39252fb8895bef5eede52c1


number

random(start, end, type)

Make a random number from start to end. Argument type can be float or int

trimDecimals(places)

Trim decimals from a float number n places


list

sequence(start, end, step)

Make a sequence from start to end each step. Similar to ee.List.sequence but with the difference that the remaining last is included.

var seq = tools.list.sequence(0, 21, 2)
print(seq) // [0,2,4,6,8,10,12,14,16,18,20,21]
var ee_seq = ee.List.sequence(0, 21, 2)
print(ee_seq) // [0,2,4,6,8,10,12,14,16,18,20]

removeDuplicates(list)

Remove duplicated items

intersection(list1, list2)

Return the intesection between list1 and list2


dictionary

extractList(dictionary, list)

Extract values from a dictionary that match keys from the given list

var list = ['a', 'c']
var dict = {a: 1, b:2, c:3}
var values = tools.dictionary.extractList(dict, list)
print(values) // [1, 3]

https://code.earthengine.google.com/e6200496f6089e6cd4eab8d7f009668a


geometry

maskInside(geometry)

Mask pixels inside a geometry. It return a function to map over an ImageCollection.

var i = ee.Image.random(1)
var masked = tools.geometry.maskInside(geometry)(i)
Map.addLayer(masked, {}, 'maskInside')

// over a collection
var col = ee.ImageCollection('collectionID')
var masked_col = col.map(tools.geometry.maskInside(geometry))

https://code.earthengine.google.com/e9eb4aba7465abfbdbfaeb45bd404b1f

paint(geometry, options)

Paints geometries. Similar to ee.Image.paint but with some differences. Argument options must be an object with none, one or more of the following:

  • fillColor
  • borderColor
  • border (border's thickness)
  • idFld (field that contains a numeric property)

https://code.earthengine.google.com/87c00a8b9796d601553051c84652694f


feature

gets(feature, properties)

Similar to ee.Feature.get but can retrieve many properties at once and return them as a list

reduce(options)

Reduce properties with a reducer. It returns a function to map over a FeatureCollection

Argument options:

  • reducer: defaults to mean
  • properties: properties to aggregate with reducer. Defaults to all properties
  • name: name for the resulting property. Defaults to reduction
var a = ee.Feature(null, {
  "forest_area": 100,
  "desert_area": 50,
  "something_else": 1000
})
var options = {
  reducer: 'sum',
  properties: ['forest_area', 'desert_area'],
  name: 'areas'
}
var areas = tools.feature.reduce(options)(a)
print(areas)

https://code.earthengine.google.com/5df3d3f037f8ea5a9a176f84a6f3121d


image

getValue(image, point, scale)

Get image band's values from point at certain scale. Return a ee.Dictionary

replaceBand(image, replace_band, add_band)

Replace an image band with another band. Arguments:

  • replace_band: the name of the band to replace (str)
  • add_band: the band that will replace the replace_band (one band ee.Image)

addSuffix(suffix, bands)

Add a suffix to the specified bands.

addPrefix(prefix, bands)

Add a prefix to the specified bands.


map

addImageCollection(collection, options)

Adds all images from an ee.ImageCollection to the Map. Argument options:

  • vis: visualization parameters (for all images)
  • active: true make layers to be active when added. Defaults to false for speed reasons
  • label: name for layers. It can be a property name, or one of:
    • system_date: the name will be the date of the image
    • system_id: the name will be the id of the image (default)

https://code.earthengine.google.com/b7b4f2db8faa0a9926caf5e033598a2a

removeLayer(name)

Remove a layer from the Map by its name.

Clone this wiki locally