energy_methods.country_boundaries#

Read, select and export country polygons, with explicit coordinate systems.

class energy_methods.country_boundaries.CountryBoundary(code: 'str', name: 'str', geometry: 'Polygon | MultiPolygon', aliases: 'tuple[str, ...]' = ())[source]#

Bases: object

Parameters:
  • code (str)

  • name (str)

  • geometry (Polygon | MultiPolygon)

  • aliases (tuple[str, ...])

code: str#
name: str#
geometry: Polygon | MultiPolygon#
aliases: tuple[str, ...] = ()#
class energy_methods.country_boundaries.CountrySelection(countries, source='caller-provided polygons')[source]#

Bases: object

Selected countries in EPSG:4326, including all supplied islands and holes.

Parameters:
countries: tuple[CountryBoundary, ...]#
source: str = 'caller-provided polygons'#
property geometry: Polygon | MultiPolygon[source]#
property codes: tuple[str, ...]#
energy_methods.country_boundaries.polygons(geometry)[source]#

Polygon parts, preserving holes; useful for outlines and plotting paths.

Parameters:

geometry (Polygon | MultiPolygon)

Return type:

tuple[Polygon, …]

energy_methods.country_boundaries.load_country_boundaries(path, countries, *, code_field='ADM0_A3', name_field='ADMIN', crs=None)[source]#

Select exact case-insensitive names or codes from .shp or RFC 7946 GeoJSON.

Natural Earth ADM0_A3/ADMIN are defaults; ISO_A2/ISO_A3 and their _EH variants, NAME and NAME_LONG are aliases. No fuzzy matching; unknown/ambiguous names fail. Shapefiles require .prj unless crs is supplied. Projected inputs are transformed to longitude/latitude with always_xy=True. GeoJSON defaults to RFC 7946 WGS84 and rejects legacy embedded CRS unless explicitly overridden. Invalid or unsplit antimeridian polygons fail rather than silently changing country topology. Only selected records are transformed and validated.

Parameters:
  • path (Path)

  • countries (str | Sequence[str])

  • code_field (str)

  • name_field (str)

  • crs (str | None)

Return type:

CountrySelection

energy_methods.country_boundaries.write_country_boundaries(selection, path)[source]#

Export selected complete contours as GeoJSON or .shp with CRS companions.

No simplification or mainland-only filtering. Shapefile outputs include .shp/.shx/.dbf/.prj/.cpg; keep all five together when moving the file.

Parameters:
Return type:

Path