format#
- geetools.ee_string.StringAccessor.format(template)#
Format a string with a dictionary.
Replace the keys in the string using the values provided in the dictionary. Follow the same pattern: value format as Python string.format method.
- Numbers and Dates can be formatted using formatters:
ee.Number - formatters: https://developers.google.com/earth-engine/apidocs/ee-number-format. - how to: %{formatter} - example: “%.2f” (converts 3.1415 -> 3.14)
ee.Date - formatters: https://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html - how to: %t{formatter} - example: “%tyyyy-MM-dd” (converts 1577836800000 -> 2020-01-01) - Dates in the template can be
ee.Date -> ee.Date(‘2020-01-01’)
ee.Number (milliseconds) -> 1577836800000
ee.String -> “2020-01-01”
- Parameters:
template (dict | ee.Dictionary) – A dictionary with the values to replace.
- Returns:
The formatted string.
- Return type:
Examples
import ee, geetools from geetools.utils import initialize_documentation initialize_documentation() s = ee.String("{greeting} developer, pi={number%.2f} start={start%tyyyy-MM-dd} end={end%tdd MMM yyyy}") s = s.geetools.format({"greeting": "Hello", "number": 3.1415, "start": 1577836800000, "end": "2021-01-01"}) s.getInfo()
'Hello developer, pi=3.14 start=2020-01-01 end=01 Jan 2021'