iso code from country name
This commit is contained in:
parent
329500f1ed
commit
d5daa80b02
@ -7,7 +7,31 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
import time
|
import time
|
||||||
|
import pycountry
|
||||||
|
from country_bounding_boxes import country_subunits_by_iso_code
|
||||||
|
from country_iso2ify import get_resolver
|
||||||
|
|
||||||
|
resolver = get_resolver()
|
||||||
|
|
||||||
|
|
||||||
|
def get_mainland_bbox(country_name):
|
||||||
|
# Returns the main continental/primary bounding box
|
||||||
|
iso_code = resolver.resolve(country_name)
|
||||||
|
countries = country_subunits_by_iso_code(iso_code)
|
||||||
|
logging.debug("Country is [{}] iso code is [{}]".format(country_name,iso_code))
|
||||||
|
# The library is designed to return the main body of the country
|
||||||
|
# in the first result or by filtering for largest area.
|
||||||
|
item = None
|
||||||
|
if countries:
|
||||||
|
for item in countries:
|
||||||
|
logging.debug(item.subunit+str(item.bbox))
|
||||||
|
item = None
|
||||||
|
countries = country_subunits_by_iso_code(iso_code)
|
||||||
|
if countries:
|
||||||
|
for item in countries:
|
||||||
|
if item.subunit == country_name:
|
||||||
|
return item.bbox
|
||||||
|
return None
|
||||||
|
|
||||||
class Timerlog:
|
class Timerlog:
|
||||||
|
|
||||||
@ -60,7 +84,7 @@ parser.add_argument(
|
|||||||
"--country",
|
"--country",
|
||||||
dest='country',
|
dest='country',
|
||||||
metavar='country',
|
metavar='country',
|
||||||
default='United States',
|
default='US',
|
||||||
action='store',
|
action='store',
|
||||||
help="country to get topo image for")
|
help="country to get topo image for")
|
||||||
|
|
||||||
@ -101,4 +125,8 @@ logging.debug(t.end().report())
|
|||||||
logging.debug("Country is [{}]".format(args.country))
|
logging.debug("Country is [{}]".format(args.country))
|
||||||
logging.debug("Region is [{}]".format(args.region))
|
logging.debug("Region is [{}]".format(args.region))
|
||||||
|
|
||||||
|
iso_code = resolver.resolve(args.country)
|
||||||
|
logging.debug("iso_code for [{}] is [{}]".format(args.country, iso_code))
|
||||||
|
|
||||||
|
bbox=get_mainland_bbox(args.country)
|
||||||
|
logging.debug("BBOX is [{}]".format(bbox))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user