From a7d3e652a063e45751baf3f3141b439c1c3e0c11 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 31 Jan 2026 19:02:11 -0800 Subject: [PATCH] bbox function to class --- topologytool.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/topologytool.py b/topologytool.py index 36aaf9c..05772ef 100644 --- a/topologytool.py +++ b/topologytool.py @@ -26,13 +26,16 @@ class Topology: self.linemap_width = linemap_width self.linemap_roundcap = linemap_roundcap self.linemap_transparent = linemap_transparent + if self.subregion is None: + self.subregion = self.country 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) + self.country = pycountry.countries.get(alpha_2=self.iso_country).name + self.subregion = self.country return if self.iso_country is None: - self.iso_country = get_resolver.resolve(self.country) + self.iso_country = get_resolver().resolve(self.country) return def list_subunits(self): @@ -43,5 +46,32 @@ class Topology: for item in countries: print("Subunit of [{}]: [{}]".format(self.country, item.subunit)) + def get_mainland_bbox(self): + countries = country_subunits_by_iso_code(self.iso_country) + print("bbox--Country is [{}] iso code is [{}]".format(self.country, self.iso_country)) + # The library is designed to return the main body of the country + # in the first result or by filtering for largest area. + item = None + countries = country_subunits_by_iso_code(self.iso_country) + if countries and self.subregion is None: + for item in countries: + print(self.subregion) + if item.subunit == self.subregion: + return item.bbox + else: + if countries: + for item in countries: + if item.subunit == self.subregion: + return item.bbox + return None - +if __name__ == "__main__": + topology = Topology(country="France") + topology.list_subunits() + print(topology.get_mainland_bbox()) + t2=Topology(country="United Kingdom",subregion="Wales") + t2.list_subunits() + print(t2.get_mainland_bbox()) + t3=Topology(iso_country="US") + t3.list_subunits() + print(t3.get_mainland_bbox()) \ No newline at end of file