Skip to content

pycensus.census.countries.chile.utils

Small stateless helpers shared by every Chile census source module.

Technical aspects

Resolves a region given as a name, or a 1/2-digit CUT code (INE's ArcGIS service returns REGION as an unpadded string, e.g. "8" not "08"), to this module's canonical zero-padded 2-digit code -- and back to the raw unpadded string the FeatureServer's where clause expects.

region_code(region)

Normalize a region name or CUT code (padded or not) to a canonical 2-digit code.

Parameters:

Name Type Description Default
region

Region name (e.g. "Biobio", "Región del Biobío"), or a CUT code as str or int (e.g. "8", "08", 8).

required

Returns:

Type Description
str

Canonical zero-padded 2-digit region code (e.g. "08").

Raises:

Type Description
ValueError

If region does not resolve to a known Chile region.

region_api_code(region)

Return the unpadded numeric-string form INE's ArcGIS service stores in REGION.

Parameters:

Name Type Description Default
region

Region name or CUT code (see :func:region_code).

required

Returns:

Type Description
str

Unpadded region code as used in the FeatureServer's REGION field

str

(e.g. "8", not "08").