hdx.api.locations

[view_source]

Locations in HDX

Locations Objects

class Locations()

[view_source]

Methods to help with countries and continents

validlocations

@classmethod
def validlocations(cls, configuration=None) -> List[Dict]

[view_source]

Read valid locations from HDX

Arguments:

  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.

Returns:

  • List[Dict] - A list of valid locations

set_validlocations

@classmethod
def set_validlocations(cls, locations: ListTuple[Dict]) -> None

[view_source]

Set valid locations using list of dictionaries of form {'name': 'zmb', 'title', 'Zambia'}

Arguments:

  • locations ListTuple[Dict] - List of dictionaries of form {'name': 'zmb', 'title', 'Zambia'}

Returns:

None

get_location_from_HDX_code

@classmethod
def get_location_from_HDX_code(cls, code: str, locations: Optional[ListTuple[Dict]] = None, configuration: Optional[Configuration] = None) -> Optional[str]

[view_source]

Get location from HDX location code

Arguments:

  • code str - code for which to get location name
  • locations Optional[ListTuple[Dict]] - Valid locations list. Defaults to list downloaded from HDX.
  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.

Returns:

  • Optional[str] - location name or None

get_HDX_code_from_location

@classmethod
def get_HDX_code_from_location(cls, location: str, locations: Optional[ListTuple[Dict]] = None, configuration: Optional[Configuration] = None) -> Optional[str]

[view_source]

Get HDX code for location

Arguments:

  • location str - Location for which to get HDX code
  • locations Optional[ListTuple[Dict]] - Valid locations list. Defaults to list downloaded from HDX.
  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.

Returns:

  • Optional[str] - HDX code or None

get_HDX_code_from_location_partial

@classmethod
def get_HDX_code_from_location_partial(cls, location: str, locations: Optional[ListTuple[Dict]] = None, configuration: Optional[Configuration] = None) -> Tuple[Optional[str], bool]

[view_source]

Get HDX code for location

Arguments:

  • location str - Location for which to get HDX code
  • locations Optional[ListTuple[Dict]] - Valid locations list. Defaults to list downloaded from HDX.
  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.

Returns:

Tuple[Optional[str], bool]: HDX code and if the match is exact or (None, False) for no match