forked from janjaapmeijer/oceanpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maps.py
67 lines (60 loc) · 2.39 KB
/
maps.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# https://ocefpaf.github.io/python4oceanographers/blog/2015/06/22/osm/
import cartopy.crs as ccrs
from cartopy.io import shapereader
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import matplotlib.pyplot as plt
def make_map(projection=ccrs.PlateCarree(), figsize=None):
fig, ax = plt.subplots(figsize=figsize, subplot_kw=dict(projection=projection))
gl = ax.gridlines(draw_labels=True)
gl.xlabels_top = gl.ylabels_right = False
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
return fig, ax, gl
def make_map_subplt(projection=ccrs.PlateCarree()):
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 10), sharey=True,
subplot_kw=dict(projection=projection))
gl = ax1.gridlines(draw_labels=True)
gl.xlabels_top = gl.ylabels_right = False
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
gl2 = ax2.gridlines(draw_labels=True)
gl2.xlabels_top = gl2.ylabels_left = gl2.ylabels_right = False
gl2.xformatter = LONGITUDE_FORMATTER
return fig, (ax1, ax2)
# # GOOGLE MAPS
# import cartopy.io.img_tiles as cimgt
#
# extent = [-39, -38.25, -13.25, -12.5]
#
# request = cimgt.GoogleTiles()
#
# fig, ax = make_map(projection=request.crs)
# ax.set_extent(extent)
#
# ax.add_image(request, 10)
#
#
# # OPEN STREET MAPS
# extent = [14.1, 14.55, 55.75, 56.05]
# # activate oceanv3
# # -clipsrc x_min y_min x_max y_max
# # ogr2ogr -f "ESRI Shapefile" <output>.shp <input>.shp -clipsrc -180 0 180 90
# # ogr2ogr -f "ESRI Shapefile" output.shp lines.shp -clipsrc 14 55 15 57
#
# # coastline + coloured land
# fig, ax = make_map(projection=ccrs.PlateCarree())
# ax.set_extent(extent)
#
# shp = shapereader.Reader('c:/Users/jaap.meijer/Downloads/land-polygons-complete-4326/output')
# for record, geometry in zip(shp.records(), shp.geometries()):
# ax.add_geometries([geometry], ccrs.PlateCarree(), facecolor='lightgray',
# edgecolor='black')
#
# # only coastline
# fig, ax = make_map(projection=ccrs.PlateCarree())
# ax.set_extent(extent)
#
# shp = shapereader.Reader('c:/Users/jaap.meijer/Downloads/coastlines-split-4326/output')
# for record, geometry in zip(shp.records(), shp.geometries()):
# ax.add_geometries([geometry], ccrs.PlateCarree(), facecolor='w',
# edgecolor='black')