toDictionary#

geetools.ee_feature_collection.FeatureCollectionAccessor.toDictionary(keyColumn='system:index', selectors=[])#

Convert to Dictionary.

Parameters:
  • keyColumn (str | ee.String) – the column to use as keys. Must contain unique values, if not it will fail.

  • selectors (list | ee.List) – a list of properties to add in the output. If the list is empty all properties will be added.

Return type:

a ee.Dictionary with values of keyColumn as keys and ee.Dictionary as values. The output will look like

Examples

import ee, geetools
from geetools.utils import initialize_documentation
import json

initialize_documentation()

# Extracting the first 3 countries from the FAO GAUL dataset.
# and transform them into dictionary
countries = (
    ee.FeatureCollection("FAO/GAUL/2015/level0")
    .select(["ADM0_NAME", "ADM0_CODE"])
    .limit(3)
    .geetools.toDictionary()
)

print(json.dumps(countries.getInfo(), indent=2))
{
  "00000000000000000003": {
    "ADM0_CODE": 2647,
    "ADM0_NAME": "Montenegro",
    "system:index": "00000000000000000003"
  },
  "0000000000000000000c": {
    "ADM0_CODE": 2648,
    "ADM0_NAME": "Serbia",
    "system:index": "0000000000000000000c"
  },
  "0000000000000000002e": {
    "ADM0_CODE": 74,
    "ADM0_NAME": "South Sudan",
    "system:index": "0000000000000000002e"
  }
}