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.
Files changed (176) hide show
  1. pycoast/__init__.py +29 -9
  2. pycoast/conftest.py +14 -0
  3. pycoast/cw_agg.py +762 -468
  4. pycoast/cw_base.py +1575 -768
  5. pycoast/cw_pil.py +583 -363
  6. pycoast/tests/__init__.py +19 -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 +1916 -419
  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.7.1.dist-info/AUTHORS.md +20 -0
  168. pycoast-1.7.1.dist-info/LICENSE.txt +674 -0
  169. pycoast-1.7.1.dist-info/METADATA +81 -0
  170. pycoast-1.7.1.dist-info/RECORD +172 -0
  171. {pycoast-1.1.0.dist-info → pycoast-1.7.1.dist-info}/WHEEL +1 -1
  172. pycoast-1.1.0.dist-info/DESCRIPTION.rst +0 -3
  173. pycoast-1.1.0.dist-info/METADATA +0 -24
  174. pycoast-1.1.0.dist-info/RECORD +0 -13
  175. pycoast-1.1.0.dist-info/metadata.json +0 -1
  176. {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-2015
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
- """Adds countours from GSHHS and WDBII to images
30
+ class ContourWriterPIL(ContourWriterBase):
31
+ """Adds countours from GSHHS and WDBII to images.
36
32
 
37
33
  :Parameters:
38
- db_root_path : str
39
- Path to root dir of GSHHS and WDBII shapefiles
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
- """Returns PIL image object
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['fill'])
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
- 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
-
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
- 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):
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
- 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
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(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):
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
- 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
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(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):
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
- 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)
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
- def add_polygon(self, image, area_def, lonlats,
196
- fill=None, outline='white', x_offset=0, y_offset=0):
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
- 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)
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
- 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
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
- 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)
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(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
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
- 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)
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(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)
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(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
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
- 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)
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
- 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
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
- 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
- """
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(image, area_def,
350
- resolution=resolution, level=level,
351
- fill=fill, outline=outline, x_offset=x_offset,
352
- y_offset=y_offset)
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(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
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
- 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)
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
- 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
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
- 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
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(image, area_def, resolution=resolution,
407
- level=level, outline=outline, x_offset=x_offset,
408
- y_offset=y_offset)
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(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
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
- 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
- """
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
- 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)
438
-
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
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
- 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
- """
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(image, area_def, resolution=resolution, level=level,
464
- outline=outline, x_offset=x_offset, y_offset=y_offset)
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)