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