Modules
geocode
- class geocode.Geocoder(cache_dir: Path | None = None, gmaps_key_file: Path | None = None, proxies: Dict | None = None, ssl_verify: bool = True)[source]
Bases:
object
Geocode addresses, postcodes, LLSOAs or Constituencies or reverse-geocode latitudes and longitudes.
- force_setup(ngeso_setup=True, cpo_setup=True, ons_setup=True, eurostat_setup=True)[source]
Download all data and setup caches.
- geocode(entity_ids, entity, **kwargs)[source]
Geocode a selection of GSP regions, llsoa boundaries, constituencies, LADs, postcodes or addresses to latitudes and longitudes.
- Parameters:
entity_ids (iterable of strings) – The specific entities to Geocode.
entity (string) – Specify the entity type to Geocode from i.e., lad or postcode.
**kwargs – Options to pass to the underlying geocode method.
- geocode_constituency(constituencies)[source]
Function to geocode a collection of constituencies into latlons.
- Parameters:
constituencies (iterable of strings) – Specific constituencies to geocode to latlons
- geocode_llsoa(llsoa_boundaries)[source]
Function to geocode a collection of llsoa boundaries into latlons.
- Parameters:
llsoa_boundaries (iterable of strings) – Specific llsoa boundaries to geocode to latlons
- geocode_local_authority(lads)[source]
Function to geocode a collection of LADs (Local Authority Districts) into latlons.
- Parameters:
lads (iterable of strings) – Specific LADs to geocode to latlons
- geocode_postcode(postcodes, method='cpo')[source]
Function to geocode a collection of postcodes into latlons.
- Parameters:
postcodes (iterable of strings) – Specific postcodes to geocode to latlons
- get_dno_regions()[source]
Get the DNO License Area Boundaries from the ESO Data Portal.
- Returns:
`dno_regions` (dict) – Dict whose keys are the region IDs and whose values are a tuple containing: (region_boundary, region_bounds). The region boundary is a Shapely Polygon/MultiPolygon and the bounds are a tuple containing (xmin, ymin, xmax, ymax).
`dno_names` (dict) – Dict whose keys are the region IDs and whose values are a tuple containing: (Name, LongName).
- get_llsoa_boundaries()[source]
Load the LLSOA boundaries, either from local cache if available, else fetch from raw API (England and Wales) and packaged data (Scotland).
- reverse_geocode(latlons, entity, **kwargs)[source]
Reverse geocode a set of latitudes and longitudes to either GSP regions or llsoa boundaries.
- Parameters:
latlons (list of tuples) – A list of tuples containing (latitude, longitude).
entity (string) – Specify the entity type to Geocode from i.e., gsp or llsoa.
**kwargs – Options to pass to the underlying reverse-geocode method.
- reverse_geocode_gsp(latlons, **kwargs)[source]
Function to reverse geocode a collection of latlons into gsp regions.
- Parameters:
latlons (iterable of strings) – Specific latlons to geocode to gsp regions.
**kwargs – Options to pass to the underlying reverse_geocode_gsp method.
- reverse_geocode_llsoa(latlons, dz=True)[source]
Function to reverse geocode a collection of latlons into llsoa boundaries.
- Parameters:
latlons (iterable of strings) – Specific latlons to geocode to llsoa boundaries.
dz (Boolean) – Indication whether to consider datazones
- reverse_geocode_nuts(latlons: List[Tuple[float, float]], level: Literal[0, 1, 2, 3], year: Literal[2003, 2006, 2010, 2013, 2016, 2021] = 2021) List[str] [source]
Function to reverse geocode a collection of latlons into NUTS boundaries.
- Parameters:
latlons (iterable of strings) – Specific latlons to geocode to llsoa boundaries.
level (int) – Specify the NUTS level, must be one of [0,1,2,3].
year (int) – Specify the year of NUTS regulation, must be one of [2003,2006,2010,2013,2016,2021], defaults to 2021.