/
country_basemaps.py
52 lines (44 loc) · 1.95 KB
/
country_basemaps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from geopy.geocoders import Nominatim
from mpl_toolkits.basemap import Basemap
def draw_latlon(llclat, urclat, llclon, urclon, rsphere=6371200, resolution='h', area_thresh=0.1, projection='merc'):
m = Basemap(llcrnrlat=llclat, urcrnrlat=urclat,
llcrnrlon=llclon, urcrnrlon=urclon,
rsphere=rsphere, resolution=resolution,
area_thresh=area_thresh, projection=projection)
m.drawcoastlines()
m.drawcountries()
def latlon_basemap(llclat, urclat, llclon, urclon, rsphere=6371200, resolution='h', area_thresh=0.1, projection='merc'):
m = Basemap(llcrnrlat=llclat, urcrnrlat=urclat,
llcrnrlon=llclon, urcrnrlon=urclon,
rsphere=rsphere, resolution=resolution,
area_thresh=area_thresh, projection=projection)
return m
def draw_country(country, rsphere=6371200, resolution='h', area_thresh=0.1, projection='merc'):
geolocator = Nominatim()
location = geolocator.geocode(country)
raw = location.raw
latlon = map(float, raw['boundingbox'])
llclat = latlon[0]
urclat = latlon[1]
llclon = latlon[2]
urclon = latlon[3]
m = Basemap(llcrnrlat=llclat, urcrnrlat=urclat,
llcrnrlon=llclon, urcrnrlon=urclon,
rsphere=rsphere, resolution=resolution,
area_thresh=area_thresh, projection=projection)
m.drawcoastlines()
m.drawcountries()
def country_basemap(country, rsphere=6371200, resolution='h', area_thresh=0.1, projection='merc'):
geolocator = Nominatim()
location = geolocator.geocode(country)
raw = location.raw
latlon = map(float, raw['boundingbox'])
llclat = latlon[0]
urclat = latlon[1]
llclon = latlon[2]
urclon = latlon[3]
m = Basemap(llcrnrlat=llclat, urcrnrlat=urclat,
llcrnrlon=llclon, urcrnrlon=urclon,
rsphere=rsphere, resolution=resolution,
area_thresh=area_thresh, projection=projection)
return m