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.
Files changed (175) hide show
  1. pycoast/__init__.py +30 -9
  2. pycoast/conftest.py +14 -0
  3. pycoast/cw_agg.py +761 -485
  4. pycoast/cw_base.py +1575 -785
  5. pycoast/cw_pil.py +581 -379
  6. pycoast/tests/__init__.py +1 -0
  7. pycoast/tests/brazil_shapefiles.png +0 -0
  8. pycoast/tests/brazil_shapefiles_agg.png +0 -0
  9. pycoast/tests/coasts_and_grid.ini +13 -0
  10. pycoast/tests/coasts_and_grid_agg.ini +17 -0
  11. pycoast/tests/contours_europe.png +0 -0
  12. pycoast/tests/contours_europe_agg.png +0 -0
  13. pycoast/tests/contours_europe_alpha.png +0 -0
  14. pycoast/tests/contours_geos.png +0 -0
  15. pycoast/tests/contours_geos_agg.png +0 -0
  16. pycoast/tests/dateline_boundary_cross.png +0 -0
  17. pycoast/tests/dateline_cross.png +0 -0
  18. pycoast/tests/eastern_shapes_agg.png +0 -0
  19. pycoast/tests/eastern_shapes_pil.png +0 -0
  20. pycoast/tests/grid_europe.png +0 -0
  21. pycoast/tests/grid_europe_agg.png +0 -0
  22. pycoast/tests/grid_europe_agg_txt.png +0 -0
  23. pycoast/tests/grid_from_dict_agg.png +0 -0
  24. pycoast/tests/grid_from_dict_pil.png +0 -0
  25. pycoast/tests/grid_geos.png +0 -0
  26. pycoast/tests/grid_geos_agg.png +0 -0
  27. pycoast/tests/grid_germ.png +0 -0
  28. pycoast/tests/grid_nh.png +0 -0
  29. pycoast/tests/grid_nh_agg.png +0 -0
  30. pycoast/tests/grid_nh_cfg_agg.png +0 -0
  31. pycoast/tests/lonlat_boundary_cross.png +0 -0
  32. pycoast/tests/nh_cities_agg.ini +26 -0
  33. pycoast/tests/nh_cities_agg.png +0 -0
  34. pycoast/tests/nh_cities_from_dict_agg.png +0 -0
  35. pycoast/tests/nh_cities_from_dict_pil.png +0 -0
  36. pycoast/tests/nh_cities_pil.ini +20 -0
  37. pycoast/tests/nh_cities_pil.png +0 -0
  38. pycoast/tests/nh_one_shapefile.ini +11 -0
  39. pycoast/tests/nh_points_agg.ini +24 -0
  40. pycoast/tests/nh_points_agg.png +0 -0
  41. pycoast/tests/nh_points_cfg_pil.png +0 -0
  42. pycoast/tests/nh_points_pil.ini +19 -0
  43. pycoast/tests/nh_points_pil.png +0 -0
  44. pycoast/tests/nh_polygons.png +0 -0
  45. pycoast/tests/nh_polygons_agg.png +0 -0
  46. pycoast/tests/no_h_scratch_agg.png +0 -0
  47. pycoast/tests/no_h_scratch_pil.png +0 -0
  48. pycoast/tests/no_v_scratch_agg.png +0 -0
  49. pycoast/tests/no_v_scratch_pil.png +0 -0
  50. pycoast/tests/one_shapefile_from_cfg_agg.png +0 -0
  51. pycoast/tests/one_shapefile_from_cfg_pil.png +0 -0
  52. pycoast/tests/test_data/DejaVuSerif.ttf +0 -0
  53. pycoast/tests/test_data/gshhs/CITIES/cities.txt +20 -0
  54. pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L1.dbf +0 -0
  55. pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L1.prj +1 -0
  56. pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L1.shp +0 -0
  57. pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L1.shx +0 -0
  58. pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L2.dbf +0 -0
  59. pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L2.prj +1 -0
  60. pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L2.shp +0 -0
  61. pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L2.shx +0 -0
  62. pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L3.dbf +0 -0
  63. pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L3.prj +1 -0
  64. pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L3.shp +0 -0
  65. pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L3.shx +0 -0
  66. pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L4.dbf +0 -0
  67. pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L4.prj +1 -0
  68. pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L4.shp +0 -0
  69. pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L4.shx +0 -0
  70. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L1.dbf +0 -0
  71. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L1.prj +1 -0
  72. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L1.shp +0 -0
  73. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L1.shx +0 -0
  74. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L2.dbf +0 -0
  75. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L2.prj +1 -0
  76. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L2.shp +0 -0
  77. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L2.shx +0 -0
  78. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L3.dbf +0 -0
  79. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L3.prj +1 -0
  80. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L3.shp +0 -0
  81. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L3.shx +0 -0
  82. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L01.dbf +0 -0
  83. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L01.prj +1 -0
  84. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L01.shp +0 -0
  85. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L01.shx +0 -0
  86. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L02.dbf +0 -0
  87. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L02.prj +1 -0
  88. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L02.shp +0 -0
  89. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L02.shx +0 -0
  90. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L03.dbf +0 -0
  91. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L03.prj +1 -0
  92. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L03.shp +0 -0
  93. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L03.shx +0 -0
  94. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L04.dbf +0 -0
  95. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L04.prj +1 -0
  96. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L04.shp +0 -0
  97. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L04.shx +0 -0
  98. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L05.dbf +0 -0
  99. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L05.prj +1 -0
  100. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L05.shp +0 -0
  101. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L05.shx +0 -0
  102. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L06.dbf +0 -0
  103. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L06.prj +1 -0
  104. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L06.shp +0 -0
  105. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L06.shx +0 -0
  106. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L07.dbf +0 -0
  107. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L07.prj +1 -0
  108. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L07.shp +0 -0
  109. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L07.shx +0 -0
  110. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L08.dbf +0 -0
  111. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L08.prj +1 -0
  112. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L08.shp +0 -0
  113. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L08.shx +0 -0
  114. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L09.dbf +0 -0
  115. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L09.prj +1 -0
  116. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L09.shp +0 -0
  117. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L09.shx +0 -0
  118. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L1.dbf +0 -0
  119. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L1.shp +0 -0
  120. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L1.shx +0 -0
  121. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L10.dbf +0 -0
  122. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L10.prj +1 -0
  123. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L10.shp +0 -0
  124. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L10.shx +0 -0
  125. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L11.dbf +0 -0
  126. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L11.prj +1 -0
  127. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L11.shp +0 -0
  128. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L11.shx +0 -0
  129. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L2.dbf +0 -0
  130. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L2.shp +0 -0
  131. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L2.shx +0 -0
  132. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L3.dbf +0 -0
  133. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L3.shp +0 -0
  134. pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L3.shx +0 -0
  135. pycoast/tests/test_data/shapes/Metareas.dbf +0 -0
  136. pycoast/tests/test_data/shapes/Metareas.mxd +0 -0
  137. pycoast/tests/test_data/shapes/Metareas.prj +1 -0
  138. pycoast/tests/test_data/shapes/Metareas.sbn +0 -0
  139. pycoast/tests/test_data/shapes/Metareas.sbx +0 -0
  140. pycoast/tests/test_data/shapes/Metareas.shp +0 -0
  141. pycoast/tests/test_data/shapes/Metareas.shx +0 -0
  142. pycoast/tests/test_data/shapes/README +3 -0
  143. pycoast/tests/test_data/shapes/divisao_politica/BRASIL.dbf +0 -0
  144. pycoast/tests/test_data/shapes/divisao_politica/BRASIL.shp +0 -0
  145. pycoast/tests/test_data/shapes/divisao_politica/BRASIL.shx +0 -0
  146. pycoast/tests/test_data/shapes/divisao_politica/BR_Capitais.dbf +0 -0
  147. pycoast/tests/test_data/shapes/divisao_politica/BR_Capitais.shp +0 -0
  148. pycoast/tests/test_data/shapes/divisao_politica/BR_Capitais.shx +0 -0
  149. pycoast/tests/test_data/shapes/divisao_politica/BR_Contorno.dbf +0 -0
  150. pycoast/tests/test_data/shapes/divisao_politica/BR_Contorno.shp +0 -0
  151. pycoast/tests/test_data/shapes/divisao_politica/BR_Contorno.shx +0 -0
  152. pycoast/tests/test_data/shapes/divisao_politica/BR_Regioes.dbf +0 -0
  153. pycoast/tests/test_data/shapes/divisao_politica/BR_Regioes.shp +0 -0
  154. pycoast/tests/test_data/shapes/divisao_politica/BR_Regioes.shx +0 -0
  155. pycoast/tests/test_data/shapes/divisao_politica/divisao_politica.txt +40 -0
  156. pycoast/tests/test_data/shapes/divisao_politica/leia.txt +9 -0
  157. pycoast/tests/test_data/shapes/metarea5.gsf +0 -0
  158. pycoast/tests/test_data/shapes/metarea5.tbl +21 -0
  159. pycoast/tests/test_data/shapes/metarea5.tbl.info +25 -0
  160. pycoast/tests/test_data/test_config.ini +12 -0
  161. pycoast/tests/test_pycoast.py +1913 -434
  162. pycoast/tests/two_shapefiles_agg.png +0 -0
  163. pycoast/tests/two_shapefiles_pil.png +0 -0
  164. pycoast/tests/western_shapes_agg.png +0 -0
  165. pycoast/tests/western_shapes_pil.png +0 -0
  166. pycoast/version.py +19 -17
  167. pycoast-1.8.0.dist-info/METADATA +107 -0
  168. pycoast-1.8.0.dist-info/RECORD +171 -0
  169. {pycoast-1.1.0.dist-info → pycoast-1.8.0.dist-info}/WHEEL +1 -1
  170. pycoast-1.8.0.dist-info/licenses/LICENSE.txt +201 -0
  171. pycoast-1.1.0.dist-info/DESCRIPTION.rst +0 -3
  172. pycoast-1.1.0.dist-info/METADATA +0 -24
  173. pycoast-1.1.0.dist-info/RECORD +0 -13
  174. pycoast-1.1.0.dist-info/metadata.json +0 -1
  175. {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
- #!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
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
- """Adds countours from GSHHS and WDBII to images
12
+ class ContourWriterPIL(ContourWriterBase):
13
+ """Adds countours from GSHHS and WDBII to images.
36
14
 
37
15
  :Parameters:
38
- db_root_path : str
39
- Path to root dir of GSHHS and WDBII shapefiles
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
- """Returns PIL image object
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['fill'])
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
- draw.rectangle(coordinates, fill=kwargs['fill'],
73
- outline=kwargs['outline'])
74
-
75
- def _draw_text_box(self, draw, text_position, text, font, outline,
76
- box_outline, box_opacity):
77
- """Add text box in xy
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
- draw.line(coordinates, fill=kwargs['outline'])
92
-
93
- def add_shapefile_shapes(self, image, area_def, filename, feature_type=None,
94
- fill=None, outline='white',
95
- x_offset=0, y_offset=0):
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
- image : object
101
- PIL image object
102
- area_def : list [proj4_string, area_extent]
103
- | proj4_string : str
104
- | Projection of area as Proj.4 string
105
- | area_extent : list
106
- | Area extent as a list (LL_x, LL_y, UR_x, UR_y)
107
- filename : str
108
- Path to ESRI shape file
109
- feature_type : 'polygon' or 'line',
110
- only to override the shape type defined in shapefile, optional
111
- fill : str or (R, G, B), optional
112
- Polygon fill color
113
- fill_opacity : int, optional {0; 255}
114
- Opacity of polygon fill
115
- outline : str or (R, G, B), optional
116
- line color
117
- outline_opacity : int, optional {0; 255}
118
- Opacity of lines
119
- x_offset : float, optional
120
- Pixel offset in x direction
121
- y_offset : float, optional
122
- Pixel offset in y direction
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(image=image, area_def=area_def,
125
- filename=filename, feature_type=feature_type,
126
- x_offset=x_offset, y_offset=y_offset,
127
- fill=fill,
128
- outline=outline)
129
-
130
- def add_shapefile_shape(self, image, area_def, filename, shape_id,
131
- feature_type=None,
132
- fill=None, outline='white',
133
- x_offset=0, y_offset=0):
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
- image : object
140
- PIL image object
141
- area_def : list [proj4_string, area_extent]
142
- | proj4_string : str
143
- | Projection of area as Proj.4 string
144
- | area_extent : list
145
- | Area extent as a list (LL_x, LL_y, UR_x, UR_y)
146
- filename : str
147
- Path to ESRI shape file
148
- shape_id : int
149
- integer id of shape in shape file {0; ... }
150
- feature_type : 'polygon' or 'line',
151
- only to override the shape type defined in shapefile, optional
152
- fill : str or (R, G, B), optional
153
- Polygon fill color
154
- outline : str or (R, G, B), optional
155
- line color
156
- x_offset : float, optional
157
- Pixel offset in x direction
158
- y_offset : float, optional
159
- Pixel offset in y direction
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(image=image,
162
- area_def=area_def, filename=filename,
163
- shape_id=shape_id,
164
- feature_type=feature_type,
165
- x_offset=x_offset, y_offset=y_offset,
166
- fill=fill,
167
- outline=outline)
168
-
169
- def add_line(self, image, area_def, lonlats,
170
- fill=None, outline='white', x_offset=0, y_offset=0):
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
- image : object
175
- PIL image object
176
- area_def : list [proj4_string, area_extent]
177
- | proj4_string : str
178
- | Projection of area as Proj.4 string
179
- | area_extent : list
180
- | Area extent as a list (LL_x, LL_y, UR_x, UR_y)
181
- lonlats : list of lon lat pairs
182
- e.g. [(10,20),(20,30),...,(20,20)]
183
- outline : str or (R, G, B), optional
184
- line color
185
- width : float, optional
186
- line width
187
- x_offset : float, optional
188
- Pixel offset in x direction
189
- y_offset : float, optional
190
- Pixel offset in y direction
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
- def add_polygon(self, image, area_def, lonlats,
196
- fill=None, outline='white', x_offset=0, y_offset=0):
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
- image : object
201
- PIL image object
202
- area_def : list [proj4_string, area_extent]
203
- | proj4_string : str
204
- | Projection of area as Proj.4 string
205
- | area_extent : list
206
- | Area extent as a list (LL_x, LL_y, UR_x, UR_y)
207
- lonlats : list of lon lat pairs
208
- e.g. [(10,20),(20,30),...,(20,20)]
209
- fill : str or (R, G, B), optional
210
- Polygon fill color
211
- outline : str or (R, G, B), optional
212
- line color
213
- x_offset : float, optional
214
- Pixel offset in x direction
215
- y_offset : float, optional
216
- Pixel offset in y direction
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
- def add_grid(self, image, area_def, Dlonlat, dlonlat,
222
- font=None, write_text=True, fill=None, outline='white',
223
- minor_outline='white', minor_is_tick=True,
224
- lon_placement='tb', lat_placement='lr'):
225
- """Add a lon-lat grid to a PIL image object
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
- image : object
229
- PIL image object
230
- proj4_string : str
231
- Projection of area as Proj.4 string
232
- Dlonlat: (float, float)
233
- Major grid line separation
234
- dlonlat: (float, float)
235
- Minor grid line separation
236
- font: PIL ImageFont object, optional
237
- Font for major line markings
238
- write_text : boolean, optional
239
- Deterine if line markings are enabled
240
- fill : str or (R, G, B), optional
241
- Text color
242
- outline : str or (R, G, B), optional
243
- Major line color
244
- minor_outline : str or (R, G, B), optional
245
- Minor line/tick color
246
- minor_is_tick : boolean, optional
247
- Use tick minor line style (True) or full minor line style (False)
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(image, area_def, Dlon, Dlat, dlon, dlat, font=font,
252
- write_text=write_text, fill=fill, outline=outline,
253
- minor_outline=minor_outline, minor_is_tick=minor_is_tick,
254
- lon_placement=lon_placement, lat_placement=lat_placement)
255
-
256
- def add_grid_to_file(self, filename, area_def, Dlonlat, dlonlat,
257
- font=None, write_text=True, fill=None, outline='white',
258
- minor_outline='white', minor_is_tick=True,
259
- lon_placement='tb', lat_placement='lr'):
260
- """Add a lon-lat grid to an image file
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
- image : object
264
- PIL image object
265
- proj4_string : str
266
- Projection of area as Proj.4 string
267
- Dlonlat: (float, float)
268
- Major grid line separation
269
- dlonlat: (float, float)
270
- Minor grid line separation
271
- font: PIL ImageFont object, optional
272
- Font for major line markings
273
- write_text : boolean, optional
274
- Deterine if line markings are enabled
275
- fill : str or (R, G, B), optional
276
- Text color
277
- outline : str or (R, G, B), optional
278
- Major line color
279
- minor_outline : str or (R, G, B), optional
280
- Minor line/tick color
281
- minor_is_tick : boolean, optional
282
- Use tick minor line style (True) or full minor line style (False)
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(image, area_def, Dlonlat, dlonlat, font=font,
286
- write_text=write_text, fill=fill, outline=outline,
287
- minor_outline=minor_outline,
288
- minor_is_tick=minor_is_tick,
289
- lon_placement=lon_placement, lat_placement=lat_placement)
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(self, image, area_def, resolution='c', level=1,
293
- fill=None, outline='white', x_offset=0, y_offset=0):
294
- """Add coastlines to a PIL image object
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
- image : object
298
- PIL image object
299
- proj4_string : str
300
- Projection of area as Proj.4 string
301
- area_extent : list
302
- Area extent as a list (LL_x, LL_y, UR_x, UR_y)
303
- resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
304
- Dataset resolution to use
305
- level : int, optional {1, 2, 3, 4}
306
- Detail level of dataset
307
- fill : str or (R, G, B), optional
308
- Land color
309
- outline : str or (R, G, B), optional
310
- Coastline color
311
- x_offset : float, optional
312
- Pixel offset in x direction
313
- y_offset : float, optional
314
- Pixel offset in y direction
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
- def add_coastlines_to_file(self, filename, area_def, resolution='c',
323
- level=1, fill=None, outline='white',
324
- x_offset=0, y_offset=0):
325
- """Add coastlines to an image file
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
- filename : str
329
- Image file
330
- proj4_string : str
331
- Projection of area as Proj.4 string
332
- area_extent : list
333
- Area extent as a list (LL_x, LL_y, UR_x, UR_y)
334
- resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
335
- Dataset resolution to use
336
- level : int, optional {1, 2, 3, 4}
337
- Detail level of dataset
338
- fill : str or (R, G, B)
339
- Land color
340
- outline : str or (R, G, B), optional
341
- Coastline color
342
- x_offset : float, optional
343
- Pixel offset in x direction
344
- y_offset : float, optional
345
- Pixel offset in y direction
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(image, area_def,
350
- resolution=resolution, level=level,
351
- fill=fill, outline=outline, x_offset=x_offset,
352
- y_offset=y_offset)
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(self, image, area_def, resolution='c', level=1,
356
- outline='white', x_offset=0, y_offset=0):
357
- """Add borders to a PIL image object
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
- image : object
361
- PIL image object
362
- proj4_string : str
363
- Projection of area as Proj.4 string
364
- area_extent : list
365
- Area extent as a list (LL_x, LL_y, UR_x, UR_y)
366
- resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
367
- Dataset resolution to use
368
- level : int, optional {1, 2, 3}
369
- Detail level of dataset
370
- outline : str or (R, G, B), optional
371
- Border color
372
- x_offset : float, optional
373
- Pixel offset in x direction
374
- y_offset : float, optional
375
- Pixel offset in y direction
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
- def add_borders_to_file(self, filename, area_def, resolution='c', level=1,
384
- outline='white', x_offset=0, y_offset=0):
385
- """Add borders to an image file
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
- image : object
389
- Image file
390
- proj4_string : str
391
- Projection of area as Proj.4 string
392
- area_extent : list
393
- Area extent as a list (LL_x, LL_y, UR_x, UR_y)
394
- resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
395
- Dataset resolution to use
396
- level : int, optional {1, 2, 3}
397
- Detail level of dataset
398
- outline : str or (R, G, B), optional
399
- Border color
400
- x_offset : float, optional
401
- Pixel offset in x direction
402
- y_offset : float, optional
403
- Pixel offset in y direction
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(image, area_def, resolution=resolution,
407
- level=level, outline=outline, x_offset=x_offset,
408
- y_offset=y_offset)
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(self, image, area_def, resolution='c', level=1,
412
- outline='white', x_offset=0, y_offset=0):
413
- """Add rivers to a PIL image object
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
- image : object
417
- PIL image object
418
- proj4_string : str
419
- Projection of area as Proj.4 string
420
- area_extent : list
421
- Area extent as a list (LL_x, LL_y, UR_x, UR_y)
422
- resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
423
- Dataset resolution to use
424
- level : int, optional {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
425
- Detail level of dataset
426
- outline : str or (R, G, B), optional
427
- River color
428
- x_offset : float, optional
429
- Pixel offset in x direction
430
- y_offset : float, optional
431
- Pixel offset in y direction
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
- def add_rivers_to_file(self, filename, area_def, resolution='c', level=1,
440
- outline='white', x_offset=0, y_offset=0):
441
- """Add rivers to an image file
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
- image : object
445
- Image file
446
- proj4_string : str
447
- Projection of area as Proj.4 string
448
- area_extent : list
449
- Area extent as a list (LL_x, LL_y, UR_x, UR_y)
450
- resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
451
- Dataset resolution to use
452
- level : int, optional {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
453
- Detail level of dataset
454
- outline : str or (R, G, B), optional
455
- River color
456
- x_offset : float, optional
457
- Pixel offset in x direction
458
- y_offset : float, optional
459
- Pixel offset in y direction
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(image, area_def, resolution=resolution, level=level,
464
- outline=outline, x_offset=x_offset, y_offset=y_offset)
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)