bbox function to class
This commit is contained in:
parent
fe7fccf0ea
commit
a7d3e652a0
@ -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())
|
||||
Loading…
x
Reference in New Issue
Block a user