pycoast 1.1.0__py3-none-any.whl → 1.8.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pycoast/__init__.py +30 -9
- pycoast/conftest.py +14 -0
- pycoast/cw_agg.py +761 -485
- pycoast/cw_base.py +1575 -785
- pycoast/cw_pil.py +581 -379
- pycoast/tests/__init__.py +1 -0
- pycoast/tests/brazil_shapefiles.png +0 -0
- pycoast/tests/brazil_shapefiles_agg.png +0 -0
- pycoast/tests/coasts_and_grid.ini +13 -0
- pycoast/tests/coasts_and_grid_agg.ini +17 -0
- pycoast/tests/contours_europe.png +0 -0
- pycoast/tests/contours_europe_agg.png +0 -0
- pycoast/tests/contours_europe_alpha.png +0 -0
- pycoast/tests/contours_geos.png +0 -0
- pycoast/tests/contours_geos_agg.png +0 -0
- pycoast/tests/dateline_boundary_cross.png +0 -0
- pycoast/tests/dateline_cross.png +0 -0
- pycoast/tests/eastern_shapes_agg.png +0 -0
- pycoast/tests/eastern_shapes_pil.png +0 -0
- pycoast/tests/grid_europe.png +0 -0
- pycoast/tests/grid_europe_agg.png +0 -0
- pycoast/tests/grid_europe_agg_txt.png +0 -0
- pycoast/tests/grid_from_dict_agg.png +0 -0
- pycoast/tests/grid_from_dict_pil.png +0 -0
- pycoast/tests/grid_geos.png +0 -0
- pycoast/tests/grid_geos_agg.png +0 -0
- pycoast/tests/grid_germ.png +0 -0
- pycoast/tests/grid_nh.png +0 -0
- pycoast/tests/grid_nh_agg.png +0 -0
- pycoast/tests/grid_nh_cfg_agg.png +0 -0
- pycoast/tests/lonlat_boundary_cross.png +0 -0
- pycoast/tests/nh_cities_agg.ini +26 -0
- pycoast/tests/nh_cities_agg.png +0 -0
- pycoast/tests/nh_cities_from_dict_agg.png +0 -0
- pycoast/tests/nh_cities_from_dict_pil.png +0 -0
- pycoast/tests/nh_cities_pil.ini +20 -0
- pycoast/tests/nh_cities_pil.png +0 -0
- pycoast/tests/nh_one_shapefile.ini +11 -0
- pycoast/tests/nh_points_agg.ini +24 -0
- pycoast/tests/nh_points_agg.png +0 -0
- pycoast/tests/nh_points_cfg_pil.png +0 -0
- pycoast/tests/nh_points_pil.ini +19 -0
- pycoast/tests/nh_points_pil.png +0 -0
- pycoast/tests/nh_polygons.png +0 -0
- pycoast/tests/nh_polygons_agg.png +0 -0
- pycoast/tests/no_h_scratch_agg.png +0 -0
- pycoast/tests/no_h_scratch_pil.png +0 -0
- pycoast/tests/no_v_scratch_agg.png +0 -0
- pycoast/tests/no_v_scratch_pil.png +0 -0
- pycoast/tests/one_shapefile_from_cfg_agg.png +0 -0
- pycoast/tests/one_shapefile_from_cfg_pil.png +0 -0
- pycoast/tests/test_data/DejaVuSerif.ttf +0 -0
- pycoast/tests/test_data/gshhs/CITIES/cities.txt +20 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L1.dbf +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L1.prj +1 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L1.shp +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L1.shx +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L2.dbf +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L2.prj +1 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L2.shp +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L2.shx +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L3.dbf +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L3.prj +1 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L3.shp +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L3.shx +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L4.dbf +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L4.prj +1 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L4.shp +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L4.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L1.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L1.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L1.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L1.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L2.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L2.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L2.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L2.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L3.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L3.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L3.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L3.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L01.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L01.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L01.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L01.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L02.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L02.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L02.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L02.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L03.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L03.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L03.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L03.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L04.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L04.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L04.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L04.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L05.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L05.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L05.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L05.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L06.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L06.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L06.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L06.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L07.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L07.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L07.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L07.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L08.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L08.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L08.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L08.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L09.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L09.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L09.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L09.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L1.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L1.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L1.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L10.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L10.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L10.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L10.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L11.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L11.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L11.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L11.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L2.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L2.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L2.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L3.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L3.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L3.shx +0 -0
- pycoast/tests/test_data/shapes/Metareas.dbf +0 -0
- pycoast/tests/test_data/shapes/Metareas.mxd +0 -0
- pycoast/tests/test_data/shapes/Metareas.prj +1 -0
- pycoast/tests/test_data/shapes/Metareas.sbn +0 -0
- pycoast/tests/test_data/shapes/Metareas.sbx +0 -0
- pycoast/tests/test_data/shapes/Metareas.shp +0 -0
- pycoast/tests/test_data/shapes/Metareas.shx +0 -0
- pycoast/tests/test_data/shapes/README +3 -0
- pycoast/tests/test_data/shapes/divisao_politica/BRASIL.dbf +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BRASIL.shp +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BRASIL.shx +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Capitais.dbf +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Capitais.shp +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Capitais.shx +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Contorno.dbf +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Contorno.shp +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Contorno.shx +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Regioes.dbf +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Regioes.shp +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Regioes.shx +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/divisao_politica.txt +40 -0
- pycoast/tests/test_data/shapes/divisao_politica/leia.txt +9 -0
- pycoast/tests/test_data/shapes/metarea5.gsf +0 -0
- pycoast/tests/test_data/shapes/metarea5.tbl +21 -0
- pycoast/tests/test_data/shapes/metarea5.tbl.info +25 -0
- pycoast/tests/test_data/test_config.ini +12 -0
- pycoast/tests/test_pycoast.py +1913 -434
- pycoast/tests/two_shapefiles_agg.png +0 -0
- pycoast/tests/two_shapefiles_pil.png +0 -0
- pycoast/tests/western_shapes_agg.png +0 -0
- pycoast/tests/western_shapes_pil.png +0 -0
- pycoast/version.py +19 -17
- pycoast-1.8.0.dist-info/METADATA +107 -0
- pycoast-1.8.0.dist-info/RECORD +171 -0
- {pycoast-1.1.0.dist-info → pycoast-1.8.0.dist-info}/WHEEL +1 -1
- pycoast-1.8.0.dist-info/licenses/LICENSE.txt +201 -0
- pycoast-1.1.0.dist-info/DESCRIPTION.rst +0 -3
- pycoast-1.1.0.dist-info/METADATA +0 -24
- pycoast-1.1.0.dist-info/RECORD +0 -13
- pycoast-1.1.0.dist-info/metadata.json +0 -1
- {pycoast-1.1.0.dist-info → pycoast-1.8.0.dist-info}/top_level.txt +0 -0
pycoast/cw_pil.py
CHANGED
|
@@ -1,42 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
# pycoast, Writing of coastlines, borders and rivers to images in Python
|
|
4
|
-
#
|
|
5
|
-
# Copyright (C) 2011-2015
|
|
6
|
-
# Esben S. Nielsen
|
|
7
|
-
# Hróbjartur Þorsteinsson
|
|
8
|
-
# Stefano Cerino
|
|
9
|
-
# Katja Hungershofer
|
|
10
|
-
# Panu Lahtinen
|
|
11
|
-
#
|
|
12
|
-
# This program is free software: you can redistribute it and/or modify
|
|
13
|
-
# it under the terms of the GNU General Public License as published by
|
|
14
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
15
|
-
#(at your option) any later version.
|
|
16
|
-
#
|
|
17
|
-
# This program is distributed in the hope that it will be useful,
|
|
18
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20
|
-
# GNU General Public License for more details.
|
|
21
|
-
#
|
|
22
|
-
# You should have received a copy of the GNU General Public License
|
|
23
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
24
|
-
|
|
25
|
-
from PIL import Image, ImageFont
|
|
26
|
-
from PIL import ImageDraw
|
|
1
|
+
"""PIL-based ContourWriter."""
|
|
2
|
+
|
|
27
3
|
import logging
|
|
28
4
|
|
|
5
|
+
from PIL import Image, ImageDraw, ImageFont
|
|
6
|
+
|
|
29
7
|
from pycoast.cw_base import ContourWriterBase
|
|
30
8
|
|
|
31
9
|
logger = logging.getLogger(__name__)
|
|
32
10
|
|
|
33
|
-
class ContourWriter(ContourWriterBase):
|
|
34
11
|
|
|
35
|
-
|
|
12
|
+
class ContourWriterPIL(ContourWriterBase):
|
|
13
|
+
"""Adds countours from GSHHS and WDBII to images.
|
|
36
14
|
|
|
37
15
|
:Parameters:
|
|
38
|
-
|
|
39
|
-
|
|
16
|
+
db_root_path : str
|
|
17
|
+
Path to root dir of GSHHS and WDBII shapefiles
|
|
18
|
+
|
|
40
19
|
"""
|
|
41
20
|
|
|
42
21
|
_draw_module = "PIL"
|
|
@@ -45,425 +24,648 @@ class ContourWriter(ContourWriterBase):
|
|
|
45
24
|
# they are not fully compatible)
|
|
46
25
|
|
|
47
26
|
def _get_canvas(self, image):
|
|
48
|
-
"""
|
|
49
|
-
"""
|
|
50
|
-
|
|
27
|
+
"""Return PIL image object."""
|
|
51
28
|
return ImageDraw.Draw(image)
|
|
52
29
|
|
|
53
30
|
def _engine_text_draw(self, draw, x_pos, y_pos, txt, font, **kwargs):
|
|
54
|
-
draw.text((x_pos, y_pos), txt, font=font, fill=kwargs[
|
|
31
|
+
draw.text((x_pos, y_pos), txt, font=font, fill=kwargs["fill"])
|
|
55
32
|
|
|
56
33
|
def _draw_polygon(self, draw, coordinates, **kwargs):
|
|
57
|
-
"""Draw polygon
|
|
58
|
-
"""
|
|
59
|
-
|
|
60
|
-
draw.polygon(coordinates, fill=kwargs['fill'],
|
|
61
|
-
outline=kwargs['outline'])
|
|
34
|
+
"""Draw polygon."""
|
|
35
|
+
draw.polygon(coordinates, fill=kwargs["fill"], outline=kwargs["outline"])
|
|
62
36
|
|
|
63
37
|
def _draw_ellipse(self, draw, coordinates, **kwargs):
|
|
64
|
-
"""Draw ellipse
|
|
65
|
-
"""
|
|
66
|
-
draw.ellipse(coordinates, fill=kwargs['fill'],
|
|
67
|
-
outline=kwargs['outline'])
|
|
38
|
+
"""Draw ellipse."""
|
|
39
|
+
draw.ellipse(coordinates, fill=kwargs["fill"], outline=kwargs["outline"])
|
|
68
40
|
|
|
69
41
|
def _draw_rectangle(self, draw, coordinates, **kwargs):
|
|
70
|
-
"""Draw rectangle
|
|
71
|
-
"""
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
42
|
+
"""Draw rectangle."""
|
|
43
|
+
draw.rectangle(coordinates, fill=kwargs["fill"], outline=kwargs["outline"])
|
|
44
|
+
|
|
45
|
+
def _draw_text_box(
|
|
46
|
+
self,
|
|
47
|
+
draw,
|
|
48
|
+
text_position,
|
|
49
|
+
text,
|
|
50
|
+
font,
|
|
51
|
+
outline,
|
|
52
|
+
box_outline,
|
|
53
|
+
box_opacity,
|
|
54
|
+
**kwargs,
|
|
55
|
+
):
|
|
56
|
+
"""Add text box in xy."""
|
|
80
57
|
if box_outline is not None:
|
|
81
|
-
logger.warning(
|
|
82
|
-
"Box background will not added; please install aggdraw lib")
|
|
58
|
+
logger.warning("Box background will not be added; please use ContourWriterAGG module")
|
|
83
59
|
|
|
84
|
-
self._draw_text(
|
|
85
|
-
draw, text_position, text, font, align="no", fill=outline)
|
|
60
|
+
self._draw_text(draw, text_position, text, font, align="no", fill=outline)
|
|
86
61
|
|
|
87
62
|
def _draw_line(self, draw, coordinates, **kwargs):
|
|
88
|
-
"""Draw line
|
|
89
|
-
""
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
63
|
+
"""Draw line."""
|
|
64
|
+
draw.line(coordinates, fill=kwargs["outline"])
|
|
65
|
+
|
|
66
|
+
def _draw_asterisk(self, draw, pt_size, coordinate, **kwargs):
|
|
67
|
+
"""Draw a asterisk sign '*' center at the given coordinate."""
|
|
68
|
+
half_ptsize = int(round(pt_size / 2.0))
|
|
69
|
+
x, y = coordinate
|
|
70
|
+
|
|
71
|
+
outline = kwargs.get("outline", "white")
|
|
72
|
+
|
|
73
|
+
# draw '|'
|
|
74
|
+
x_bm, y_bm = (x, y - half_ptsize) # bottom middle point
|
|
75
|
+
x_tm, y_tm = (x, y + half_ptsize) # top middle point
|
|
76
|
+
self._draw_line(draw, [x_bm, y_bm, x_tm, y_tm], outline=outline)
|
|
77
|
+
|
|
78
|
+
# draw '-'
|
|
79
|
+
x_lm, y_lm = (x - half_ptsize, y) # left middle point
|
|
80
|
+
x_rm, y_rm = (x + half_ptsize, y) # right middle point
|
|
81
|
+
self._draw_line(draw, [x_lm, y_lm, x_rm, y_rm], outline=outline)
|
|
82
|
+
|
|
83
|
+
# draw '/'
|
|
84
|
+
x_bl, y_bl = (x - half_ptsize, y - half_ptsize) # bottom left point
|
|
85
|
+
x_tr, y_tr = (x + half_ptsize, y + half_ptsize) # top right point
|
|
86
|
+
self._draw_line(draw, [x_bl, y_bl, x_tr, y_tr], outline=outline)
|
|
87
|
+
|
|
88
|
+
# draw '\'
|
|
89
|
+
x_tl, y_tl = (x - half_ptsize, y + half_ptsize) # top left point
|
|
90
|
+
x_br, y_br = (x + half_ptsize, y - half_ptsize) # bottom right point
|
|
91
|
+
self._draw_line(draw, [x_tl, y_tl, x_br, y_br], outline=outline)
|
|
92
|
+
|
|
93
|
+
def add_shapefile_shapes(
|
|
94
|
+
self,
|
|
95
|
+
image,
|
|
96
|
+
area_def,
|
|
97
|
+
filename,
|
|
98
|
+
feature_type=None,
|
|
99
|
+
fill=None,
|
|
100
|
+
outline="white",
|
|
101
|
+
x_offset=0,
|
|
102
|
+
y_offset=0,
|
|
103
|
+
):
|
|
96
104
|
"""Add shape file shapes from an ESRI shapefile.
|
|
105
|
+
|
|
97
106
|
Note: Currently only supports lon-lat formatted coordinates.
|
|
98
107
|
|
|
99
108
|
:Parameters:
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
109
|
+
image : object
|
|
110
|
+
PIL image object
|
|
111
|
+
area_def : list [proj4_string, area_extent]
|
|
112
|
+
| proj4_string : str
|
|
113
|
+
| Projection of area as Proj.4 string
|
|
114
|
+
| area_extent : list
|
|
115
|
+
| Area extent as a list (LL_x, LL_y, UR_x, UR_y)
|
|
116
|
+
filename : str
|
|
117
|
+
Path to ESRI shape file
|
|
118
|
+
feature_type : 'polygon' or 'line',
|
|
119
|
+
only to override the shape type defined in shapefile, optional
|
|
120
|
+
fill : str or (R, G, B), optional
|
|
121
|
+
Polygon fill color
|
|
122
|
+
fill_opacity : int, optional {0; 255}
|
|
123
|
+
Opacity of polygon fill
|
|
124
|
+
outline : str or (R, G, B), optional
|
|
125
|
+
line color
|
|
126
|
+
outline_opacity : int, optional {0; 255}
|
|
127
|
+
Opacity of lines
|
|
128
|
+
x_offset : float, optional
|
|
129
|
+
Pixel offset in x direction
|
|
130
|
+
y_offset : float, optional
|
|
131
|
+
Pixel offset in y direction
|
|
132
|
+
|
|
123
133
|
"""
|
|
124
|
-
self._add_shapefile_shapes(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
+
self._add_shapefile_shapes(
|
|
135
|
+
image=image,
|
|
136
|
+
area_def=area_def,
|
|
137
|
+
filename=filename,
|
|
138
|
+
feature_type=feature_type,
|
|
139
|
+
x_offset=x_offset,
|
|
140
|
+
y_offset=y_offset,
|
|
141
|
+
fill=fill,
|
|
142
|
+
outline=outline,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
def add_shapefile_shape(
|
|
146
|
+
self,
|
|
147
|
+
image,
|
|
148
|
+
area_def,
|
|
149
|
+
filename,
|
|
150
|
+
shape_id,
|
|
151
|
+
feature_type=None,
|
|
152
|
+
fill=None,
|
|
153
|
+
outline="white",
|
|
154
|
+
x_offset=0,
|
|
155
|
+
y_offset=0,
|
|
156
|
+
):
|
|
134
157
|
"""Add a single shape file shape from an ESRI shapefile.
|
|
158
|
+
|
|
135
159
|
Note: To add all shapes in file use the 'add_shape_file_shapes' routine.
|
|
136
160
|
Note: Currently only supports lon-lat formatted coordinates.
|
|
137
161
|
|
|
138
162
|
:Parameters:
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
163
|
+
image : object
|
|
164
|
+
PIL image object
|
|
165
|
+
area_def : list [proj4_string, area_extent]
|
|
166
|
+
| proj4_string : str
|
|
167
|
+
| Projection of area as Proj.4 string
|
|
168
|
+
| area_extent : list
|
|
169
|
+
| Area extent as a list (LL_x, LL_y, UR_x, UR_y)
|
|
170
|
+
filename : str
|
|
171
|
+
Path to ESRI shape file
|
|
172
|
+
shape_id : int
|
|
173
|
+
integer id of shape in shape file {0; ... }
|
|
174
|
+
feature_type : 'polygon' or 'line',
|
|
175
|
+
only to override the shape type defined in shapefile, optional
|
|
176
|
+
fill : str or (R, G, B), optional
|
|
177
|
+
Polygon fill color
|
|
178
|
+
outline : str or (R, G, B), optional
|
|
179
|
+
line color
|
|
180
|
+
x_offset : float, optional
|
|
181
|
+
Pixel offset in x direction
|
|
182
|
+
y_offset : float, optional
|
|
183
|
+
Pixel offset in y direction
|
|
184
|
+
|
|
160
185
|
"""
|
|
161
|
-
self._add_shapefile_shape(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
186
|
+
self._add_shapefile_shape(
|
|
187
|
+
image=image,
|
|
188
|
+
area_def=area_def,
|
|
189
|
+
filename=filename,
|
|
190
|
+
shape_id=shape_id,
|
|
191
|
+
feature_type=feature_type,
|
|
192
|
+
x_offset=x_offset,
|
|
193
|
+
y_offset=y_offset,
|
|
194
|
+
fill=fill,
|
|
195
|
+
outline=outline,
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
def add_line(
|
|
199
|
+
self,
|
|
200
|
+
image,
|
|
201
|
+
area_def,
|
|
202
|
+
lonlats,
|
|
203
|
+
fill=None,
|
|
204
|
+
outline="white",
|
|
205
|
+
x_offset=0,
|
|
206
|
+
y_offset=0,
|
|
207
|
+
):
|
|
171
208
|
"""Add a user defined poly-line from a list of (lon,lat) coordinates.
|
|
172
209
|
|
|
173
210
|
:Parameters:
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
"""
|
|
192
|
-
self._add_line(image, area_def, lonlats, x_offset=x_offset, y_offset=y_offset,
|
|
193
|
-
fill=fill, outline=outline)
|
|
211
|
+
image : object
|
|
212
|
+
PIL image object
|
|
213
|
+
area_def : list [proj4_string, area_extent]
|
|
214
|
+
| proj4_string : str
|
|
215
|
+
| Projection of area as Proj.4 string
|
|
216
|
+
| area_extent : list
|
|
217
|
+
| Area extent as a list (LL_x, LL_y, UR_x, UR_y)
|
|
218
|
+
lonlats : list of lon lat pairs
|
|
219
|
+
e.g. [(10,20),(20,30),...,(20,20)]
|
|
220
|
+
outline : str or (R, G, B), optional
|
|
221
|
+
line color
|
|
222
|
+
width : float, optional
|
|
223
|
+
line width
|
|
224
|
+
x_offset : float, optional
|
|
225
|
+
Pixel offset in x direction
|
|
226
|
+
y_offset : float, optional
|
|
227
|
+
Pixel offset in y direction
|
|
194
228
|
|
|
195
|
-
|
|
196
|
-
|
|
229
|
+
"""
|
|
230
|
+
self._add_line(
|
|
231
|
+
image,
|
|
232
|
+
area_def,
|
|
233
|
+
lonlats,
|
|
234
|
+
x_offset=x_offset,
|
|
235
|
+
y_offset=y_offset,
|
|
236
|
+
fill=fill,
|
|
237
|
+
outline=outline,
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
def add_polygon(
|
|
241
|
+
self,
|
|
242
|
+
image,
|
|
243
|
+
area_def,
|
|
244
|
+
lonlats,
|
|
245
|
+
fill=None,
|
|
246
|
+
outline="white",
|
|
247
|
+
x_offset=0,
|
|
248
|
+
y_offset=0,
|
|
249
|
+
):
|
|
197
250
|
"""Add a user defined polygon from a list of (lon,lat) coordinates.
|
|
198
251
|
|
|
199
252
|
:Parameters:
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
"""
|
|
218
|
-
self._add_polygon(image, area_def, lonlats, x_offset=x_offset,
|
|
219
|
-
y_offset=y_offset, fill=fill, outline=outline)
|
|
253
|
+
image : object
|
|
254
|
+
PIL image object
|
|
255
|
+
area_def : list [proj4_string, area_extent]
|
|
256
|
+
| proj4_string : str
|
|
257
|
+
| Projection of area as Proj.4 string
|
|
258
|
+
| area_extent : list
|
|
259
|
+
| Area extent as a list (LL_x, LL_y, UR_x, UR_y)
|
|
260
|
+
lonlats : list of lon lat pairs
|
|
261
|
+
e.g. [(10,20),(20,30),...,(20,20)]
|
|
262
|
+
fill : str or (R, G, B), optional
|
|
263
|
+
Polygon fill color
|
|
264
|
+
outline : str or (R, G, B), optional
|
|
265
|
+
line color
|
|
266
|
+
x_offset : float, optional
|
|
267
|
+
Pixel offset in x direction
|
|
268
|
+
y_offset : float, optional
|
|
269
|
+
Pixel offset in y direction
|
|
220
270
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
271
|
+
"""
|
|
272
|
+
self._add_polygon(
|
|
273
|
+
image,
|
|
274
|
+
area_def,
|
|
275
|
+
lonlats,
|
|
276
|
+
x_offset=x_offset,
|
|
277
|
+
y_offset=y_offset,
|
|
278
|
+
fill=fill,
|
|
279
|
+
outline=outline,
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
def add_grid(
|
|
283
|
+
self,
|
|
284
|
+
image,
|
|
285
|
+
area_def,
|
|
286
|
+
Dlonlat,
|
|
287
|
+
dlonlat,
|
|
288
|
+
font=None,
|
|
289
|
+
write_text=True,
|
|
290
|
+
fill=None,
|
|
291
|
+
outline="white",
|
|
292
|
+
minor_outline="white",
|
|
293
|
+
minor_is_tick=True,
|
|
294
|
+
lon_placement="tb",
|
|
295
|
+
lat_placement="lr",
|
|
296
|
+
):
|
|
297
|
+
"""Add a lon-lat grid to a PIL image object.
|
|
226
298
|
|
|
227
299
|
:Parameters:
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
300
|
+
image : object
|
|
301
|
+
PIL image object
|
|
302
|
+
proj4_string : str
|
|
303
|
+
Projection of area as Proj.4 string
|
|
304
|
+
Dlonlat: (float, float)
|
|
305
|
+
Major grid line separation
|
|
306
|
+
dlonlat: (float, float)
|
|
307
|
+
Minor grid line separation
|
|
308
|
+
font: PIL ImageFont object, optional
|
|
309
|
+
Font for major line markings
|
|
310
|
+
write_text : boolean, optional
|
|
311
|
+
Determine if line markings are enabled
|
|
312
|
+
fill : str or (R, G, B), optional
|
|
313
|
+
Text color
|
|
314
|
+
outline : str or (R, G, B), optional
|
|
315
|
+
Major line color
|
|
316
|
+
minor_outline : str or (R, G, B), optional
|
|
317
|
+
Minor line/tick color
|
|
318
|
+
minor_is_tick : boolean, optional
|
|
319
|
+
Use tick minor line style (True) or full minor line style (False)
|
|
320
|
+
|
|
248
321
|
"""
|
|
249
322
|
Dlon, Dlat = Dlonlat
|
|
250
323
|
dlon, dlat = dlonlat
|
|
251
|
-
self._add_grid(
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
324
|
+
self._add_grid(
|
|
325
|
+
image,
|
|
326
|
+
area_def,
|
|
327
|
+
Dlon,
|
|
328
|
+
Dlat,
|
|
329
|
+
dlon,
|
|
330
|
+
dlat,
|
|
331
|
+
font=font,
|
|
332
|
+
write_text=write_text,
|
|
333
|
+
fill=fill,
|
|
334
|
+
outline=outline,
|
|
335
|
+
minor_outline=minor_outline,
|
|
336
|
+
minor_is_tick=minor_is_tick,
|
|
337
|
+
lon_placement=lon_placement,
|
|
338
|
+
lat_placement=lat_placement,
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
def add_grid_to_file(
|
|
342
|
+
self,
|
|
343
|
+
filename,
|
|
344
|
+
area_def,
|
|
345
|
+
Dlonlat,
|
|
346
|
+
dlonlat,
|
|
347
|
+
font=None,
|
|
348
|
+
write_text=True,
|
|
349
|
+
fill=None,
|
|
350
|
+
outline="white",
|
|
351
|
+
minor_outline="white",
|
|
352
|
+
minor_is_tick=True,
|
|
353
|
+
lon_placement="tb",
|
|
354
|
+
lat_placement="lr",
|
|
355
|
+
):
|
|
356
|
+
"""Add a lon-lat grid to an image file.
|
|
261
357
|
|
|
262
358
|
:Parameters:
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
359
|
+
image : object
|
|
360
|
+
PIL image object
|
|
361
|
+
proj4_string : str
|
|
362
|
+
Projection of area as Proj.4 string
|
|
363
|
+
Dlonlat: (float, float)
|
|
364
|
+
Major grid line separation
|
|
365
|
+
dlonlat: (float, float)
|
|
366
|
+
Minor grid line separation
|
|
367
|
+
font: PIL ImageFont object, optional
|
|
368
|
+
Font for major line markings
|
|
369
|
+
write_text : boolean, optional
|
|
370
|
+
Determine if line markings are enabled
|
|
371
|
+
fill : str or (R, G, B), optional
|
|
372
|
+
Text color
|
|
373
|
+
outline : str or (R, G, B), optional
|
|
374
|
+
Major line color
|
|
375
|
+
minor_outline : str or (R, G, B), optional
|
|
376
|
+
Minor line/tick color
|
|
377
|
+
minor_is_tick : boolean, optional
|
|
378
|
+
Use tick minor line style (True) or full minor line style (False)
|
|
379
|
+
|
|
283
380
|
"""
|
|
284
381
|
image = Image.open(filename)
|
|
285
|
-
self.add_grid(
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
382
|
+
self.add_grid(
|
|
383
|
+
image,
|
|
384
|
+
area_def,
|
|
385
|
+
Dlonlat,
|
|
386
|
+
dlonlat,
|
|
387
|
+
font=font,
|
|
388
|
+
write_text=write_text,
|
|
389
|
+
fill=fill,
|
|
390
|
+
outline=outline,
|
|
391
|
+
minor_outline=minor_outline,
|
|
392
|
+
minor_is_tick=minor_is_tick,
|
|
393
|
+
lon_placement=lon_placement,
|
|
394
|
+
lat_placement=lat_placement,
|
|
395
|
+
)
|
|
290
396
|
image.save(filename)
|
|
291
397
|
|
|
292
|
-
def add_coastlines(
|
|
293
|
-
|
|
294
|
-
|
|
398
|
+
def add_coastlines(
|
|
399
|
+
self,
|
|
400
|
+
image,
|
|
401
|
+
area_def,
|
|
402
|
+
resolution="c",
|
|
403
|
+
level=1,
|
|
404
|
+
fill=None,
|
|
405
|
+
outline="white",
|
|
406
|
+
x_offset=0,
|
|
407
|
+
y_offset=0,
|
|
408
|
+
):
|
|
409
|
+
"""Add coastlines to a PIL image object.
|
|
295
410
|
|
|
296
411
|
:Parameters:
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
"""
|
|
316
|
-
|
|
317
|
-
self._add_feature(image, area_def, 'polygon', 'GSHHS',
|
|
318
|
-
resolution=resolution, level=level,
|
|
319
|
-
fill=fill, outline=outline, x_offset=x_offset,
|
|
320
|
-
y_offset=y_offset)
|
|
412
|
+
image : object
|
|
413
|
+
PIL image object
|
|
414
|
+
proj4_string : str
|
|
415
|
+
Projection of area as Proj.4 string
|
|
416
|
+
area_extent : list
|
|
417
|
+
Area extent as a list (LL_x, LL_y, UR_x, UR_y)
|
|
418
|
+
resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
|
|
419
|
+
Dataset resolution to use
|
|
420
|
+
level : int, optional {1, 2, 3, 4}
|
|
421
|
+
Detail level of dataset
|
|
422
|
+
fill : str or (R, G, B), optional
|
|
423
|
+
Land color
|
|
424
|
+
outline : str or (R, G, B), optional
|
|
425
|
+
Coastline color
|
|
426
|
+
x_offset : float, optional
|
|
427
|
+
Pixel offset in x direction
|
|
428
|
+
y_offset : float, optional
|
|
429
|
+
Pixel offset in y direction
|
|
321
430
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
431
|
+
"""
|
|
432
|
+
self._add_feature(
|
|
433
|
+
image,
|
|
434
|
+
area_def,
|
|
435
|
+
"polygon",
|
|
436
|
+
"GSHHS",
|
|
437
|
+
resolution=resolution,
|
|
438
|
+
level=level,
|
|
439
|
+
fill=fill,
|
|
440
|
+
outline=outline,
|
|
441
|
+
x_offset=x_offset,
|
|
442
|
+
y_offset=y_offset,
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
def add_coastlines_to_file(
|
|
446
|
+
self,
|
|
447
|
+
filename,
|
|
448
|
+
area_def,
|
|
449
|
+
resolution="c",
|
|
450
|
+
level=1,
|
|
451
|
+
fill=None,
|
|
452
|
+
outline="white",
|
|
453
|
+
x_offset=0,
|
|
454
|
+
y_offset=0,
|
|
455
|
+
):
|
|
456
|
+
"""Add coastlines to an image file.
|
|
326
457
|
|
|
327
458
|
:Parameters:
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
"""
|
|
459
|
+
filename : str
|
|
460
|
+
Image file
|
|
461
|
+
proj4_string : str
|
|
462
|
+
Projection of area as Proj.4 string
|
|
463
|
+
area_extent : list
|
|
464
|
+
Area extent as a list (LL_x, LL_y, UR_x, UR_y)
|
|
465
|
+
resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
|
|
466
|
+
Dataset resolution to use
|
|
467
|
+
level : int, optional {1, 2, 3, 4}
|
|
468
|
+
Detail level of dataset
|
|
469
|
+
fill : str or (R, G, B)
|
|
470
|
+
Land color
|
|
471
|
+
outline : str or (R, G, B), optional
|
|
472
|
+
Coastline color
|
|
473
|
+
x_offset : float, optional
|
|
474
|
+
Pixel offset in x direction
|
|
475
|
+
y_offset : float, optional
|
|
476
|
+
Pixel offset in y direction
|
|
347
477
|
|
|
478
|
+
"""
|
|
348
479
|
image = Image.open(filename)
|
|
349
|
-
self.add_coastlines(
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
480
|
+
self.add_coastlines(
|
|
481
|
+
image,
|
|
482
|
+
area_def,
|
|
483
|
+
resolution=resolution,
|
|
484
|
+
level=level,
|
|
485
|
+
fill=fill,
|
|
486
|
+
outline=outline,
|
|
487
|
+
x_offset=x_offset,
|
|
488
|
+
y_offset=y_offset,
|
|
489
|
+
)
|
|
353
490
|
image.save(filename)
|
|
354
491
|
|
|
355
|
-
def add_borders(
|
|
356
|
-
|
|
357
|
-
|
|
492
|
+
def add_borders(
|
|
493
|
+
self,
|
|
494
|
+
image,
|
|
495
|
+
area_def,
|
|
496
|
+
resolution="c",
|
|
497
|
+
level=1,
|
|
498
|
+
outline="white",
|
|
499
|
+
x_offset=0,
|
|
500
|
+
y_offset=0,
|
|
501
|
+
):
|
|
502
|
+
"""Add borders to a PIL image object.
|
|
358
503
|
|
|
359
504
|
:Parameters:
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
"""
|
|
377
|
-
|
|
378
|
-
self._add_feature(image, area_def, 'line', 'WDBII',
|
|
379
|
-
tag='border', resolution=resolution, level=level,
|
|
380
|
-
outline=outline, x_offset=x_offset,
|
|
381
|
-
y_offset=y_offset)
|
|
505
|
+
image : object
|
|
506
|
+
PIL image object
|
|
507
|
+
proj4_string : str
|
|
508
|
+
Projection of area as Proj.4 string
|
|
509
|
+
area_extent : list
|
|
510
|
+
Area extent as a list (LL_x, LL_y, UR_x, UR_y)
|
|
511
|
+
resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
|
|
512
|
+
Dataset resolution to use
|
|
513
|
+
level : int, optional {1, 2, 3}
|
|
514
|
+
Detail level of dataset
|
|
515
|
+
outline : str or (R, G, B), optional
|
|
516
|
+
Border color
|
|
517
|
+
x_offset : float, optional
|
|
518
|
+
Pixel offset in x direction
|
|
519
|
+
y_offset : float, optional
|
|
520
|
+
Pixel offset in y direction
|
|
382
521
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
522
|
+
"""
|
|
523
|
+
self._add_feature(
|
|
524
|
+
image,
|
|
525
|
+
area_def,
|
|
526
|
+
"line",
|
|
527
|
+
"WDBII",
|
|
528
|
+
tag="border",
|
|
529
|
+
resolution=resolution,
|
|
530
|
+
level=level,
|
|
531
|
+
outline=outline,
|
|
532
|
+
x_offset=x_offset,
|
|
533
|
+
y_offset=y_offset,
|
|
534
|
+
)
|
|
535
|
+
|
|
536
|
+
def add_borders_to_file(
|
|
537
|
+
self,
|
|
538
|
+
filename,
|
|
539
|
+
area_def,
|
|
540
|
+
resolution="c",
|
|
541
|
+
level=1,
|
|
542
|
+
outline="white",
|
|
543
|
+
x_offset=0,
|
|
544
|
+
y_offset=0,
|
|
545
|
+
):
|
|
546
|
+
"""Add borders to an image file.
|
|
386
547
|
|
|
387
548
|
:Parameters:
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
549
|
+
image : object
|
|
550
|
+
Image file
|
|
551
|
+
proj4_string : str
|
|
552
|
+
Projection of area as Proj.4 string
|
|
553
|
+
area_extent : list
|
|
554
|
+
Area extent as a list (LL_x, LL_y, UR_x, UR_y)
|
|
555
|
+
resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
|
|
556
|
+
Dataset resolution to use
|
|
557
|
+
level : int, optional {1, 2, 3}
|
|
558
|
+
Detail level of dataset
|
|
559
|
+
outline : str or (R, G, B), optional
|
|
560
|
+
Border color
|
|
561
|
+
x_offset : float, optional
|
|
562
|
+
Pixel offset in x direction
|
|
563
|
+
y_offset : float, optional
|
|
564
|
+
Pixel offset in y direction
|
|
565
|
+
|
|
404
566
|
"""
|
|
405
567
|
image = Image.open(filename)
|
|
406
|
-
self.add_borders(
|
|
407
|
-
|
|
408
|
-
|
|
568
|
+
self.add_borders(
|
|
569
|
+
image,
|
|
570
|
+
area_def,
|
|
571
|
+
resolution=resolution,
|
|
572
|
+
level=level,
|
|
573
|
+
outline=outline,
|
|
574
|
+
x_offset=x_offset,
|
|
575
|
+
y_offset=y_offset,
|
|
576
|
+
)
|
|
409
577
|
image.save(filename)
|
|
410
578
|
|
|
411
|
-
def add_rivers(
|
|
412
|
-
|
|
413
|
-
|
|
579
|
+
def add_rivers(
|
|
580
|
+
self,
|
|
581
|
+
image,
|
|
582
|
+
area_def,
|
|
583
|
+
resolution="c",
|
|
584
|
+
level=2,
|
|
585
|
+
outline="white",
|
|
586
|
+
x_offset=0,
|
|
587
|
+
y_offset=0,
|
|
588
|
+
):
|
|
589
|
+
"""Add rivers to a PIL image object.
|
|
414
590
|
|
|
415
591
|
:Parameters:
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
"""
|
|
433
|
-
|
|
434
|
-
self._add_feature(image, area_def, 'line', 'WDBII',
|
|
435
|
-
tag='river', zero_pad=True, resolution=resolution,
|
|
436
|
-
level=level, outline=outline, x_offset=x_offset,
|
|
437
|
-
y_offset=y_offset)
|
|
592
|
+
image : object
|
|
593
|
+
PIL image object
|
|
594
|
+
proj4_string : str
|
|
595
|
+
Projection of area as Proj.4 string
|
|
596
|
+
area_extent : list
|
|
597
|
+
Area extent as a list (LL_x, LL_y, UR_x, UR_y)
|
|
598
|
+
resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
|
|
599
|
+
Dataset resolution to use
|
|
600
|
+
level : int, optional {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
|
|
601
|
+
Detail level of dataset
|
|
602
|
+
outline : str or (R, G, B), optional
|
|
603
|
+
River color
|
|
604
|
+
x_offset : float, optional
|
|
605
|
+
Pixel offset in x direction
|
|
606
|
+
y_offset : float, optional
|
|
607
|
+
Pixel offset in y direction
|
|
438
608
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
609
|
+
"""
|
|
610
|
+
self._add_feature(
|
|
611
|
+
image,
|
|
612
|
+
area_def,
|
|
613
|
+
"line",
|
|
614
|
+
"WDBII",
|
|
615
|
+
tag="river",
|
|
616
|
+
zero_pad=True,
|
|
617
|
+
resolution=resolution,
|
|
618
|
+
level=level,
|
|
619
|
+
outline=outline,
|
|
620
|
+
x_offset=x_offset,
|
|
621
|
+
y_offset=y_offset,
|
|
622
|
+
)
|
|
623
|
+
|
|
624
|
+
def add_rivers_to_file(
|
|
625
|
+
self,
|
|
626
|
+
filename,
|
|
627
|
+
area_def,
|
|
628
|
+
resolution="c",
|
|
629
|
+
level=1,
|
|
630
|
+
outline="white",
|
|
631
|
+
x_offset=0,
|
|
632
|
+
y_offset=0,
|
|
633
|
+
):
|
|
634
|
+
"""Add rivers to an image file.
|
|
442
635
|
|
|
443
636
|
:Parameters:
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
"""
|
|
637
|
+
image : object
|
|
638
|
+
Image file
|
|
639
|
+
proj4_string : str
|
|
640
|
+
Projection of area as Proj.4 string
|
|
641
|
+
area_extent : list
|
|
642
|
+
Area extent as a list (LL_x, LL_y, UR_x, UR_y)
|
|
643
|
+
resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
|
|
644
|
+
Dataset resolution to use
|
|
645
|
+
level : int, optional {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
|
|
646
|
+
Detail level of dataset
|
|
647
|
+
outline : str or (R, G, B), optional
|
|
648
|
+
River color
|
|
649
|
+
x_offset : float, optional
|
|
650
|
+
Pixel offset in x direction
|
|
651
|
+
y_offset : float, optional
|
|
652
|
+
Pixel offset in y direction
|
|
461
653
|
|
|
654
|
+
"""
|
|
462
655
|
image = Image.open(filename)
|
|
463
|
-
self.add_rivers(
|
|
464
|
-
|
|
656
|
+
self.add_rivers(
|
|
657
|
+
image,
|
|
658
|
+
area_def,
|
|
659
|
+
resolution=resolution,
|
|
660
|
+
level=level,
|
|
661
|
+
outline=outline,
|
|
662
|
+
x_offset=x_offset,
|
|
663
|
+
y_offset=y_offset,
|
|
664
|
+
)
|
|
465
665
|
image.save(filename)
|
|
466
666
|
|
|
467
667
|
def _get_font(self, outline, font_file, font_size):
|
|
468
668
|
"""Return a font."""
|
|
669
|
+
if font_file is None:
|
|
670
|
+
return ImageFont.load_default()
|
|
469
671
|
return ImageFont.truetype(font_file, font_size)
|