toposhirt/topologytool.py
2026-01-31 18:38:07 -08:00

48 lines
1.6 KiB
Python

from country_iso2ify import get_resolver
import pycountry
from country_bounding_boxes import country_subunits_by_iso_code
class Topology:
def __init__(self,
country=None,
iso_country=None,
subregion=None,
linemap_size=(800,800),
linemap_rows=30,
linemap_cols=30,
linemap_width=1.0,
linemap_roundcap=True,
linemap_transparent=False
):
self.country = country
self.iso_country = iso_country
self.subregion = subregion
self.linemap_size = linemap_size
self.linemap_rows = linemap_rows
self.linemap_cols = linemap_cols
self.linemap_width = linemap_width
self.linemap_roundcap = linemap_roundcap
self.linemap_transparent = linemap_transparent
if self.country is None and self.iso_country is None:
self.country = "Switzerland"
if self.country is None:
self.iso_country = pycountry.countries.get(alpha_2=self.iso_country)
return
if self.iso_country is None:
self.iso_country = get_resolver.resolve(self.country)
return
def list_subunits(self):
countries = country_subunits_by_iso_code(self.iso_country)
print("Country is [{}] iso code is [{}]".format(self.country, self.iso_country))
item = None
if countries:
for item in countries:
print("Subunit of [{}]: [{}]".format(self.country, item.subunit))