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_agg.py CHANGED
@@ -2,12 +2,7 @@
2
2
  # -*- coding: utf-8 -*-
3
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
@@ -21,11 +16,12 @@
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
+ """ContourWriter based on the aggdraw library."""
24
20
 
25
- from PIL import Image
26
21
  import logging
27
22
 
28
23
  import aggdraw
24
+ from PIL import Image
29
25
 
30
26
  from pycoast.cw_base import ContourWriterBase
31
27
 
@@ -33,65 +29,73 @@ logger = logging.getLogger(__name__)
33
29
 
34
30
 
35
31
  class ContourWriterAGG(ContourWriterBase):
36
-
37
- """Adds countours from GSHHS and WDBII to images
38
- using the AGG engine for high quality images.
32
+ """Adds countours from GSHHS and WDBII to images using the AGG engine for high quality images.
39
33
 
40
34
  :Parameters:
41
- db_root_path : str
42
- Path to root dir of GSHHS and WDBII shapefiles
35
+ db_root_path : str
36
+ Path to root dir of GSHHS and WDBII shapefiles
37
+
43
38
  """
39
+
44
40
  _draw_module = "AGG"
45
41
  # This is a flag to make _add_grid aware of which text draw routine
46
42
  # from PIL or from aggdraw should be used
47
43
  # (unfortunately they are not fully compatible)
48
44
 
49
45
  def _get_canvas(self, image):
50
- """Returns AGG image object
51
- """
46
+ """Return AGG image object."""
52
47
  return aggdraw.Draw(image)
53
48
 
54
49
  def _engine_text_draw(self, draw, x_pos, y_pos, txt, font, **kwargs):
55
50
  draw.text((x_pos, y_pos), txt, font)
56
51
 
57
52
  def _draw_polygon(self, draw, coordinates, **kwargs):
58
- """Draw polygon
59
- """
60
- pen = aggdraw.Pen(kwargs['outline'],
61
- kwargs['width'],
62
- kwargs['outline_opacity'])
63
- if kwargs['fill'] is None:
64
- fill_opacity = 0
65
- else:
66
- fill_opacity = kwargs['fill_opacity']
67
- brush = aggdraw.Brush(kwargs['fill'], fill_opacity)
53
+ """Draw polygon."""
54
+ pen = aggdraw.Pen(kwargs["outline"], kwargs["width"], kwargs["outline_opacity"])
55
+
56
+ fill_opacity = kwargs.get("fill_opacity", 255) if kwargs["fill"] else 0
57
+
58
+ brush = aggdraw.Brush(kwargs["fill"], fill_opacity)
68
59
  draw.polygon(coordinates, pen, brush)
69
60
 
70
61
  def _draw_rectangle(self, draw, coordinates, **kwargs):
71
- """Draw rectangle
72
- """
73
- pen = aggdraw.Pen(kwargs['outline'])
62
+ """Draw rectangle."""
63
+ pen = aggdraw.Pen(kwargs["outline"], kwargs["width"], kwargs["outline_opacity"])
64
+
65
+ fill_opacity = kwargs.get("fill_opacity", 255) if kwargs["fill"] else 0
66
+
67
+ brush = aggdraw.Brush(kwargs["fill"], fill_opacity)
74
68
 
75
- fill_opacity = kwargs.get('fill_opacity', 255)
76
- brush = aggdraw.Brush(kwargs['fill'], fill_opacity)
77
69
  draw.rectangle(coordinates, pen, brush)
78
70
 
79
71
  def _draw_ellipse(self, draw, coordinates, **kwargs):
80
- """Draw ellipse
81
- """
82
- pen = aggdraw.Pen(kwargs['outline'])
72
+ """Draw ellipse."""
73
+ pen = aggdraw.Pen(kwargs["outline"], kwargs["width"], kwargs["outline_opacity"])
83
74
 
84
- fill_opacity = kwargs.get('fill_opacity', 255)
85
- brush = aggdraw.Brush(kwargs['fill'], fill_opacity)
86
- draw.ellipse(coordinates, brush, pen)
75
+ fill_opacity = kwargs.get("fill_opacity", 255) if kwargs["fill"] else 0
87
76
 
88
- def _draw_text_box(self, draw, text_position, text, font, outline,
89
- box_outline, box_opacity):
90
- """Add text box in xy
91
- """
77
+ brush = aggdraw.Brush(kwargs["fill"], fill_opacity)
92
78
 
79
+ draw.ellipse(coordinates, brush, pen)
80
+
81
+ def _draw_text_box(
82
+ self,
83
+ draw,
84
+ text_position,
85
+ text,
86
+ font,
87
+ outline,
88
+ box_outline,
89
+ box_opacity,
90
+ **kwargs,
91
+ ):
92
+ """Add a text box at position (x,y)."""
93
93
  if box_outline is not None:
94
- text_size = draw.textsize(text, font)
94
+ if hasattr(draw, "textsize"):
95
+ text_size = draw.textsize(text, font)
96
+ else:
97
+ left, top, right, bottom = draw.textbbox(text_position, text, font)
98
+ text_size = right - left, top - bottom
95
99
  margin = 2
96
100
  xUL = text_position[0] - margin
97
101
  yUL = text_position[1]
@@ -99,499 +103,789 @@ class ContourWriterAGG(ContourWriterBase):
99
103
  yLR = yUL + text_size[1]
100
104
  box_size = (xUL, yUL, xLR, yLR)
101
105
 
106
+ width = kwargs.get("box_linewidth", 1)
107
+ fill = kwargs.get("box_fill", None)
108
+
102
109
  self._draw_rectangle(
103
- draw, box_size, fill=box_outline, fill_opacity=box_opacity,
104
- outline=box_outline)
110
+ draw,
111
+ box_size,
112
+ outline=box_outline,
113
+ width=width,
114
+ outline_opacity=box_opacity,
115
+ fill=fill,
116
+ fill_opacity=box_opacity,
117
+ )
105
118
 
106
119
  self._draw_text(draw, text_position, text, font, align="no")
107
120
 
108
121
  def _draw_line(self, draw, coordinates, **kwargs):
109
- """Draw line
110
- """
111
- pen = aggdraw.Pen(kwargs['outline'],
112
- kwargs['width'],
113
- kwargs['outline_opacity'])
122
+ """Draw line."""
123
+ pen = aggdraw.Pen(kwargs["outline"], kwargs["width"], kwargs["outline_opacity"])
114
124
  draw.line(coordinates, pen)
115
125
 
116
- def _finalize(self, draw):
117
- """Flush the AGG image object
118
- """
126
+ def _draw_asterisk(self, draw, pt_size, coordinate, **kwargs):
127
+ """Draw a asterisk sign '*' at the given coordinate."""
128
+ half_ptsize = int(round(pt_size / 2.0))
129
+ x, y = coordinate
130
+
131
+ outline = kwargs.get("outline", "white")
132
+ width = kwargs.get("width", 1.0)
133
+ outline_opacity = kwargs.get("outline_opacity", 255)
134
+
135
+ # draw '|'
136
+ (x_bm, y_bm) = (x, y - half_ptsize) # bottom middle point
137
+ (x_tm, y_tm) = (x, y + half_ptsize) # top middle point
138
+ self._draw_line(
139
+ draw,
140
+ [x_bm, y_bm, x_tm, y_tm],
141
+ outline=outline,
142
+ width=width,
143
+ outline_opacity=outline_opacity,
144
+ )
145
+ # draw '-'
146
+ (x_lm, y_lm) = (x - half_ptsize, y) # left middle point
147
+ (x_rm, y_rm) = (x + half_ptsize, y) # right middle point
148
+ self._draw_line(
149
+ draw,
150
+ [x_lm, y_lm, x_rm, y_rm],
151
+ outline=outline,
152
+ width=width,
153
+ outline_opacity=outline_opacity,
154
+ )
155
+ # draw '/'
156
+ (x_bl, y_bl) = (x - half_ptsize, y - half_ptsize) # bottom left point
157
+ (x_tr, y_tr) = (x + half_ptsize, y + half_ptsize) # top right point
158
+ self._draw_line(
159
+ draw,
160
+ [x_bl, y_bl, x_tr, y_tr],
161
+ outline=outline,
162
+ width=width,
163
+ outline_opacity=outline_opacity,
164
+ )
165
+ # draw '\'
166
+ (x_tl, y_tl) = (x - half_ptsize, y + half_ptsize) # top left point
167
+ (x_br, y_br) = (x + half_ptsize, y - half_ptsize) # bottom right point
168
+ self._draw_line(
169
+ draw,
170
+ [x_tl, y_tl, x_br, y_br],
171
+ outline=outline,
172
+ width=width,
173
+ outline_opacity=outline_opacity,
174
+ )
119
175
 
176
+ def _finalize(self, draw):
177
+ """Flush the AGG image object."""
120
178
  draw.flush()
121
179
 
122
- def add_shapefile_shapes(self, image, area_def, filename,
123
- feature_type=None,
124
- fill=None, fill_opacity=255, outline='white',
125
- width=1, outline_opacity=255, x_offset=0,
126
- y_offset=0):
180
+ def add_shapefile_shapes(
181
+ self,
182
+ image,
183
+ area_def,
184
+ filename,
185
+ feature_type=None,
186
+ fill=None,
187
+ fill_opacity=255,
188
+ outline="white",
189
+ width=1,
190
+ outline_opacity=255,
191
+ x_offset=0,
192
+ y_offset=0,
193
+ ):
127
194
  """Add shape file shapes from an ESRI shapefile.
195
+
128
196
  Note: Currently only supports lon-lat formatted coordinates.
129
197
 
130
198
  :Parameters:
131
- image : object
132
- PIL image object
133
- area_def : list [proj4_string, area_extent]
134
- | proj4_string : str
135
- | Projection of area as Proj.4 string
136
- | area_extent : list
137
- | Area extent as a list (LL_x, LL_y, UR_x, UR_y)
138
- filename : str
139
- Path to ESRI shape file
140
- feature_type : 'polygon' or 'line',
141
- only to override the shape type defined in shapefile, optional
142
- fill : str or (R, G, B), optional
143
- Polygon fill color
144
- fill_opacity : int, optional {0; 255}
145
- Opacity of polygon fill
146
- outline : str or (R, G, B), optional
147
- line color
148
- width : float, optional
149
- line width
150
- outline_opacity : int, optional {0; 255}
151
- Opacity of lines
152
- x_offset : float, optional
153
- Pixel offset in x direction
154
- y_offset : float, optional
155
- Pixel offset in y direction
199
+ image : object
200
+ PIL image object
201
+ area_def : list [proj4_string, area_extent]
202
+ | proj4_string : str
203
+ | Projection of area as Proj.4 string
204
+ | area_extent : list
205
+ | Area extent as a list (LL_x, LL_y, UR_x, UR_y)
206
+ filename : str
207
+ Path to ESRI shape file
208
+ feature_type : 'polygon' or 'line',
209
+ only to override the shape type defined in shapefile, optional
210
+ fill : str or (R, G, B), optional
211
+ Polygon fill color
212
+ fill_opacity : int, optional {0; 255}
213
+ Opacity of polygon fill
214
+ outline : str or (R, G, B), optional
215
+ line color
216
+ width : float, optional
217
+ line width
218
+ outline_opacity : int, optional {0; 255}
219
+ Opacity of lines
220
+ x_offset : float, optional
221
+ Pixel offset in x direction
222
+ y_offset : float, optional
223
+ Pixel offset in y direction
224
+
156
225
  """
157
- self._add_shapefile_shapes(image=image, area_def=area_def,
158
- filename=filename,
159
- feature_type=feature_type,
160
- x_offset=x_offset, y_offset=y_offset,
161
- fill=fill, fill_opacity=fill_opacity,
162
- outline=outline, width=width,
163
- outline_opacity=outline_opacity)
164
-
165
- def add_shapefile_shape(self, image, area_def, filename, shape_id,
166
- feature_type=None,
167
- fill=None, fill_opacity=255, outline='white',
168
- width=1, outline_opacity=255, x_offset=0,
169
- y_offset=0):
226
+ self._add_shapefile_shapes(
227
+ image=image,
228
+ area_def=area_def,
229
+ filename=filename,
230
+ feature_type=feature_type,
231
+ x_offset=x_offset,
232
+ y_offset=y_offset,
233
+ fill=fill,
234
+ fill_opacity=fill_opacity,
235
+ outline=outline,
236
+ width=width,
237
+ outline_opacity=outline_opacity,
238
+ )
239
+
240
+ def add_shapefile_shape(
241
+ self,
242
+ image,
243
+ area_def,
244
+ filename,
245
+ shape_id,
246
+ feature_type=None,
247
+ fill=None,
248
+ fill_opacity=255,
249
+ outline="white",
250
+ width=1,
251
+ outline_opacity=255,
252
+ x_offset=0,
253
+ y_offset=0,
254
+ ):
170
255
  """Add a single shape file shape from an ESRI shapefile.
256
+
171
257
  Note: To add all shapes in file use the 'add_shape_file_shapes' routine
258
+
172
259
  Note: Currently only supports lon-lat formatted coordinates.
173
260
 
174
261
  :Parameters:
175
- image : object
176
- PIL image object
177
- area_def : list [proj4_string, area_extent]
178
- | proj4_string : str
179
- | Projection of area as Proj.4 string
180
- | area_extent : list
181
- | Area extent as a list (LL_x, LL_y, UR_x, UR_y)
182
- filename : str
183
- Path to ESRI shape file
184
- shape_id : int
185
- integer id of shape in shape file {0; ... }
186
- feature_type : 'polygon' or 'line',
187
- only to override the shape type defined in shapefile, optional
188
- fill : str or (R, G, B), optional
189
- Polygon fill color
190
- fill_opacity : int, optional {0; 255}
191
- Opacity of polygon fill
192
- outline : str or (R, G, B), optional
193
- line color
194
- width : float, optional
195
- line width
196
- outline_opacity : int, optional {0; 255}
197
- Opacity of lines
198
- x_offset : float, optional
199
- Pixel offset in x direction
200
- y_offset : float, optional
201
- Pixel offset in y direction
262
+ image : object
263
+ PIL image object
264
+ area_def : list [proj4_string, area_extent]
265
+ | proj4_string : str
266
+ | Projection of area as Proj.4 string
267
+ | area_extent : list
268
+ | Area extent as a list (LL_x, LL_y, UR_x, UR_y)
269
+ filename : str
270
+ Path to ESRI shape file
271
+ shape_id : int
272
+ integer id of shape in shape file {0; ... }
273
+ feature_type : 'polygon' or 'line',
274
+ only to override the shape type defined in shapefile, optional
275
+ fill : str or (R, G, B), optional
276
+ Polygon fill color
277
+ fill_opacity : int, optional {0; 255}
278
+ Opacity of polygon fill
279
+ outline : str or (R, G, B), optional
280
+ line color
281
+ width : float, optional
282
+ line width
283
+ outline_opacity : int, optional {0; 255}
284
+ Opacity of lines
285
+ x_offset : float, optional
286
+ Pixel offset in x direction
287
+ y_offset : float, optional
288
+ Pixel offset in y direction
289
+
202
290
  """
203
- self._add_shapefile_shape(image=image,
204
- area_def=area_def, filename=filename,
205
- shape_id=shape_id,
206
- feature_type=feature_type,
207
- x_offset=x_offset, y_offset=y_offset,
208
- fill=fill, fill_opacity=fill_opacity,
209
- outline=outline, width=width,
210
- outline_opacity=outline_opacity)
211
-
212
- def add_line(self, image, area_def, lonlats,
213
- fill=None, fill_opacity=255, outline='white', width=1,
214
- outline_opacity=255, x_offset=0, y_offset=0):
291
+ self._add_shapefile_shape(
292
+ image=image,
293
+ area_def=area_def,
294
+ filename=filename,
295
+ shape_id=shape_id,
296
+ feature_type=feature_type,
297
+ x_offset=x_offset,
298
+ y_offset=y_offset,
299
+ fill=fill,
300
+ fill_opacity=fill_opacity,
301
+ outline=outline,
302
+ width=width,
303
+ outline_opacity=outline_opacity,
304
+ )
305
+
306
+ def add_line(
307
+ self,
308
+ image,
309
+ area_def,
310
+ lonlats,
311
+ fill=None,
312
+ fill_opacity=255,
313
+ outline="white",
314
+ width=1,
315
+ outline_opacity=255,
316
+ x_offset=0,
317
+ y_offset=0,
318
+ ):
215
319
  """Add a user defined poly-line from a list of (lon,lat) coordinates.
216
320
 
217
321
  :Parameters:
218
- image : object
219
- PIL image object
220
- area_def : list [proj4_string, area_extent]
221
- | proj4_string : str
222
- | Projection of area as Proj.4 string
223
- | area_extent : list
224
- | Area extent as a list (LL_x, LL_y, UR_x, UR_y)
225
- lonlats : list of lon lat pairs
226
- e.g. [(10,20),(20,30),...,(20,20)]
227
- outline : str or (R, G, B), optional
228
- line color
229
- width : float, optional
230
- line width
231
- outline_opacity : int, optional {0; 255}
232
- Opacity of lines
233
- x_offset : float, optional
234
- Pixel offset in x direction
235
- y_offset : float, optional
236
- Pixel offset in y direction
322
+ image : object
323
+ PIL image object
324
+ area_def : list [proj4_string, area_extent]
325
+ | proj4_string : str
326
+ | Projection of area as Proj.4 string
327
+ | area_extent : list
328
+ | Area extent as a list (LL_x, LL_y, UR_x, UR_y)
329
+ lonlats : list of lon lat pairs
330
+ e.g. [(10,20),(20,30),...,(20,20)]
331
+ outline : str or (R, G, B), optional
332
+ line color
333
+ width : float, optional
334
+ line width
335
+ outline_opacity : int, optional {0; 255}
336
+ Opacity of lines
337
+ x_offset : float, optional
338
+ Pixel offset in x direction
339
+ y_offset : float, optional
340
+ Pixel offset in y direction
341
+
237
342
  """
238
- self._add_line(image, area_def, lonlats, x_offset=x_offset,
239
- y_offset=y_offset, fill=fill, fill_opacity=fill_opacity,
240
- outline=outline, width=width,
241
- outline_opacity=outline_opacity)
242
-
243
- def add_polygon(self, image, area_def, lonlats,
244
- fill=None, fill_opacity=255, outline='white', width=1,
245
- outline_opacity=255, x_offset=0, y_offset=0):
343
+ self._add_line(
344
+ image,
345
+ area_def,
346
+ lonlats,
347
+ x_offset=x_offset,
348
+ y_offset=y_offset,
349
+ fill=fill,
350
+ fill_opacity=fill_opacity,
351
+ outline=outline,
352
+ width=width,
353
+ outline_opacity=outline_opacity,
354
+ )
355
+
356
+ def add_polygon(
357
+ self,
358
+ image,
359
+ area_def,
360
+ lonlats,
361
+ fill=None,
362
+ fill_opacity=255,
363
+ outline="white",
364
+ width=1,
365
+ outline_opacity=255,
366
+ x_offset=0,
367
+ y_offset=0,
368
+ ):
246
369
  """Add a user defined polygon from a list of (lon,lat) coordinates.
247
370
 
248
371
  :Parameters:
249
- image : object
250
- PIL image object
251
- area_def : list [proj4_string, area_extent]
252
- | proj4_string : str
253
- | Projection of area as Proj.4 string
254
- | area_extent : list
255
- | Area extent as a list (LL_x, LL_y, UR_x, UR_y)
256
- lonlats : list of lon lat pairs
257
- e.g. [(10,20),(20,30),...,(20,20)]
258
- fill : str or (R, G, B), optional
259
- Polygon fill color
260
- fill_opacity : int, optional {0; 255}
261
- Opacity of polygon fill
262
- outline : str or (R, G, B), optional
263
- line color
264
- width : float, optional
265
- line width
266
- outline_opacity : int, optional {0; 255}
267
- Opacity of lines
268
- x_offset : float, optional
269
- Pixel offset in x direction
270
- y_offset : float, optional
271
- Pixel offset in y direction
372
+ image : object
373
+ PIL image object
374
+ area_def : list [proj4_string, area_extent]
375
+ | proj4_string : str
376
+ | Projection of area as Proj.4 string
377
+ | area_extent : list
378
+ | Area extent as a list (LL_x, LL_y, UR_x, UR_y)
379
+ lonlats : list of lon lat pairs
380
+ e.g. [(10,20),(20,30),...,(20,20)]
381
+ fill : str or (R, G, B), optional
382
+ Polygon fill color
383
+ fill_opacity : int, optional {0; 255}
384
+ Opacity of polygon fill
385
+ outline : str or (R, G, B), optional
386
+ line color
387
+ width : float, optional
388
+ line width
389
+ outline_opacity : int, optional {0; 255}
390
+ Opacity of lines
391
+ x_offset : float, optional
392
+ Pixel offset in x direction
393
+ y_offset : float, optional
394
+ Pixel offset in y direction
395
+
272
396
  """
273
- self._add_polygon(image, area_def, lonlats, x_offset=x_offset,
274
- y_offset=y_offset, fill=fill,
275
- fill_opacity=fill_opacity, outline=outline,
276
- width=width, outline_opacity=outline_opacity)
277
-
278
- def add_grid(self, image, area_def, Dlonlat, dlonlat,
279
- font=None, write_text=True, fill=None, fill_opacity=255,
280
- outline='white', width=1, outline_opacity=255,
281
- minor_outline='white', minor_width=0.5,
282
- minor_outline_opacity=255, minor_is_tick=True,
283
- lon_placement='tb', lat_placement='lr'):
284
- """Add a lon-lat grid to a PIL image object
397
+ self._add_polygon(
398
+ image,
399
+ area_def,
400
+ lonlats,
401
+ x_offset=x_offset,
402
+ y_offset=y_offset,
403
+ fill=fill,
404
+ fill_opacity=fill_opacity,
405
+ outline=outline,
406
+ width=width,
407
+ outline_opacity=outline_opacity,
408
+ )
409
+
410
+ def add_grid(
411
+ self,
412
+ image,
413
+ area_def,
414
+ Dlonlat,
415
+ dlonlat,
416
+ font=None,
417
+ write_text=True,
418
+ fill=None,
419
+ fill_opacity=255,
420
+ outline="white",
421
+ width=1.0,
422
+ outline_opacity=255,
423
+ minor_outline="white",
424
+ minor_width=0.5,
425
+ minor_outline_opacity=255,
426
+ minor_is_tick=True,
427
+ lon_placement="tb",
428
+ lat_placement="lr",
429
+ ):
430
+ """Add a lon-lat grid to a PIL image object.
285
431
 
286
432
  :Parameters:
287
- image : object
288
- PIL image object
289
- proj4_string : str
290
- Projection of area as Proj.4 string
291
- Dlonlat: (float, float)
292
- Major grid line separation
293
- dlonlat: (float, float)
294
- Minor grid line separation
295
- font: Aggdraw Font object, optional
296
- Font for major line markings
297
- write_text : boolean, optional
298
- Deterine if line markings are enabled
299
- fill_opacity : int, optional {0; 255}
300
- Opacity of text
301
- outline : str or (R, G, B), optional
302
- Major line color
303
- width : float, optional
304
- Major line width
305
- outline_opacity : int, optional {0; 255}
306
- Opacity of major lines
307
- minor_outline : str or (R, G, B), optional
308
- Minor line/tick color
309
- minor_width : float, optional
310
- Minor line width
311
- minor_outline_opacity : int, optional {0; 255}
312
- Opacity of minor lines/ticks
313
- minor_is_tick : boolean, optional
314
- Use tick minor line style (True) or full minor line style (False)
433
+ image : object
434
+ PIL image object
435
+ proj4_string : str
436
+ Projection of area as Proj.4 string
437
+ Dlonlat: (float, float)
438
+ Major grid line separation
439
+ dlonlat: (float, float)
440
+ Minor grid line separation
441
+ font: Aggdraw Font object, optional
442
+ Font for major line markings
443
+ write_text : boolean, optional
444
+ Determine if line markings are enabled
445
+ fill_opacity : int, optional {0; 255}
446
+ Opacity of text
447
+ outline : str or (R, G, B), optional
448
+ Major line color
449
+ width : float, optional
450
+ Major line width
451
+ outline_opacity : int, optional {0; 255}
452
+ Opacity of major lines
453
+ minor_outline : str or (R, G, B), optional
454
+ Minor line/tick color
455
+ minor_width : float, optional
456
+ Minor line width
457
+ minor_outline_opacity : int, optional {0; 255}
458
+ Opacity of minor lines/ticks
459
+ minor_is_tick : boolean, optional
460
+ Use tick minor line style (True) or full minor line style (False)
461
+
315
462
  """
316
463
  Dlon, Dlat = Dlonlat
317
464
  dlon, dlat = dlonlat
318
- self._add_grid(image, area_def, Dlon, Dlat, dlon, dlat,
319
- font=font, write_text=write_text,
320
- fill=fill, fill_opacity=fill_opacity, outline=outline,
321
- width=width, outline_opacity=outline_opacity,
322
- minor_outline=minor_outline, minor_width=minor_width,
323
- minor_outline_opacity=minor_outline_opacity,
324
- minor_is_tick=minor_is_tick,
325
- lon_placement=lon_placement,
326
- lat_placement=lat_placement)
327
-
328
- def add_grid_to_file(self, filename, area_def, Dlonlat, dlonlat,
329
- font=None, write_text=True,
330
- fill=None, fill_opacity=255,
331
- outline='white', width=1, outline_opacity=255,
332
- minor_outline='white', minor_width=0.5,
333
- minor_outline_opacity=255, minor_is_tick=True,
334
- lon_placement='tb', lat_placement='lr'):
335
- """Add a lon-lat grid to an image
465
+ self._add_grid(
466
+ image,
467
+ area_def,
468
+ Dlon,
469
+ Dlat,
470
+ dlon,
471
+ dlat,
472
+ font=font,
473
+ write_text=write_text,
474
+ fill=fill,
475
+ fill_opacity=fill_opacity,
476
+ outline=outline,
477
+ width=width,
478
+ outline_opacity=outline_opacity,
479
+ minor_outline=minor_outline,
480
+ minor_width=minor_width,
481
+ minor_outline_opacity=minor_outline_opacity,
482
+ minor_is_tick=minor_is_tick,
483
+ lon_placement=lon_placement,
484
+ lat_placement=lat_placement,
485
+ )
486
+
487
+ def add_grid_to_file(
488
+ self,
489
+ filename,
490
+ area_def,
491
+ Dlonlat,
492
+ dlonlat,
493
+ font=None,
494
+ write_text=True,
495
+ fill=None,
496
+ fill_opacity=255,
497
+ outline="white",
498
+ width=1,
499
+ outline_opacity=255,
500
+ minor_outline="white",
501
+ minor_width=0.5,
502
+ minor_outline_opacity=255,
503
+ minor_is_tick=True,
504
+ lon_placement="tb",
505
+ lat_placement="lr",
506
+ ):
507
+ """Add a lon-lat grid to an image. The resulting image is in 'RGBA' mode.
336
508
 
337
509
  :Parameters:
338
- image : object
339
- PIL image object
340
- proj4_string : str
341
- Projection of area as Proj.4 string
342
- Dlonlat: (float, float)
343
- Major grid line separation
344
- dlonlat: (float, float)
345
- Minor grid line separation
346
- font: Aggdraw Font object, optional
347
- Font for major line markings
348
- write_text : boolean, optional
349
- Deterine if line markings are enabled
350
- fill_opacity : int, optional {0; 255}
351
- Opacity of text
352
- outline : str or (R, G, B), optional
353
- Major line color
354
- width : float, optional
355
- Major line width
356
- outline_opacity : int, optional {0; 255}
357
- Opacity of major lines
358
- minor_outline : str or (R, G, B), optional
359
- Minor line/tick color
360
- minor_width : float, optional
361
- Minor line width
362
- minor_outline_opacity : int, optional {0; 255}
363
- Opacity of minor lines/ticks
364
- minor_is_tick : boolean, optional
365
- Use tick minor line style (True) or full minor line style (False)
366
- """
510
+ image : object
511
+ PIL image object
512
+ proj4_string : str
513
+ Projection of area as Proj.4 string
514
+ Dlonlat: (float, float)
515
+ Major grid line separation
516
+ dlonlat: (float, float)
517
+ Minor grid line separation
518
+ font: Aggdraw Font object, optional
519
+ Font for major line markings
520
+ write_text : boolean, optional
521
+ Determine if line markings are enabled
522
+ fill_opacity : int, optional {0; 255}
523
+ Opacity of text
524
+ outline : str or (R, G, B), optional
525
+ Major line color
526
+ width : float, optional
527
+ Major line width
528
+ outline_opacity : int, optional {0; 255}
529
+ Opacity of major lines
530
+ minor_outline : str or (R, G, B), optional
531
+ Minor line/tick color
532
+ minor_width : float, optional
533
+ Minor line width
534
+ minor_outline_opacity : int, optional {0; 255}
535
+ Opacity of minor lines/ticks
536
+ minor_is_tick : boolean, optional
537
+ Use tick minor line style (True) or full minor line style (False)
367
538
 
539
+ """
368
540
  image = Image.open(filename)
369
- self.add_grid(image, area_def, Dlonlat, dlonlat,
370
- font=font, write_text=write_text,
371
- fill=fill, fill_opacity=fill_opacity,
372
- outline=outline, width=width,
373
- outline_opacity=outline_opacity,
374
- minor_outline=minor_outline,
375
- minor_width=minor_width,
376
- minor_outline_opacity=minor_outline_opacity,
377
- minor_is_tick=minor_is_tick,
378
- lon_placement=lon_placement, lat_placement=lat_placement)
541
+ image = image.convert("RGBA")
542
+ self.add_grid(
543
+ image,
544
+ area_def,
545
+ Dlonlat,
546
+ dlonlat,
547
+ font=font,
548
+ write_text=write_text,
549
+ fill=fill,
550
+ fill_opacity=fill_opacity,
551
+ outline=outline,
552
+ width=width,
553
+ outline_opacity=outline_opacity,
554
+ minor_outline=minor_outline,
555
+ minor_width=minor_width,
556
+ minor_outline_opacity=minor_outline_opacity,
557
+ minor_is_tick=minor_is_tick,
558
+ lon_placement=lon_placement,
559
+ lat_placement=lat_placement,
560
+ )
379
561
  image.save(filename)
380
562
 
381
- def add_coastlines(self, image, area_def, resolution='c', level=1,
382
- fill=None, fill_opacity=255, outline='white', width=1,
383
- outline_opacity=255, x_offset=0, y_offset=0):
384
- """Add coastlines to a PIL image object
563
+ def add_coastlines(
564
+ self,
565
+ image,
566
+ area_def,
567
+ resolution="c",
568
+ level=1,
569
+ fill=None,
570
+ fill_opacity=255,
571
+ outline="white",
572
+ width=1,
573
+ outline_opacity=255,
574
+ x_offset=0,
575
+ y_offset=0,
576
+ ):
577
+ """Add coastlines to a PIL image object.
385
578
 
386
579
  :Parameters:
387
- image : object
388
- PIL image object
389
- proj4_string : str
390
- Projection of area as Proj.4 string
391
- area_extent : list
392
- Area extent as a list (LL_x, LL_y, UR_x, UR_y)
393
- resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
394
- Dataset resolution to use
395
- level : int, optional {1, 2, 3, 4}
396
- Detail level of dataset
397
- fill : str or (R, G, B), optional
398
- Land color
399
- fill_opacity : int, optional {0; 255}
400
- Opacity of land color
401
- outline : str or (R, G, B), optional
402
- Coastline color
403
- width : float, optional
404
- Width of coastline
405
- outline_opacity : int, optional {0; 255}
406
- Opacity of coastline color
407
- x_offset : float, optional
408
- Pixel offset in x direction
409
- y_offset : float, optional
410
- Pixel offset in y direction
411
- """
412
-
413
- self._add_feature(image, area_def, 'polygon', 'GSHHS',
414
- resolution=resolution, level=level,
415
- fill=fill, fill_opacity=fill_opacity,
416
- outline=outline, width=width,
417
- outline_opacity=outline_opacity, x_offset=x_offset,
418
- y_offset=y_offset)
580
+ image : object
581
+ PIL image object
582
+ proj4_string : str
583
+ Projection of area as Proj.4 string
584
+ area_extent : list
585
+ Area extent as a list (LL_x, LL_y, UR_x, UR_y)
586
+ resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
587
+ Dataset resolution to use
588
+ level : int, optional {1, 2, 3, 4}
589
+ Detail level of dataset
590
+ fill : str or (R, G, B), optional
591
+ Land color
592
+ fill_opacity : int, optional {0; 255}
593
+ Opacity of land color
594
+ outline : str or (R, G, B), optional
595
+ Coastline color
596
+ width : float, optional
597
+ Width of coastline
598
+ outline_opacity : int, optional {0; 255}
599
+ Opacity of coastline color
600
+ x_offset : float, optional
601
+ Pixel offset in x direction
602
+ y_offset : float, optional
603
+ Pixel offset in y direction
419
604
 
420
- def add_coastlines_to_file(self, filename, area_def, resolution='c',
421
- level=1, fill=None, fill_opacity=255,
422
- outline='white', width=1, outline_opacity=255,
423
- x_offset=0, y_offset=0):
424
- """Add coastlines to an image file
605
+ """
606
+ self._add_feature(
607
+ image,
608
+ area_def,
609
+ "polygon",
610
+ "GSHHS",
611
+ resolution=resolution,
612
+ level=level,
613
+ fill=fill,
614
+ fill_opacity=fill_opacity,
615
+ outline=outline,
616
+ width=width,
617
+ outline_opacity=outline_opacity,
618
+ x_offset=x_offset,
619
+ y_offset=y_offset,
620
+ )
621
+
622
+ def add_coastlines_to_file(
623
+ self,
624
+ filename,
625
+ area_def,
626
+ resolution="c",
627
+ level=1,
628
+ fill=None,
629
+ fill_opacity=255,
630
+ outline="white",
631
+ width=1,
632
+ outline_opacity=255,
633
+ x_offset=0,
634
+ y_offset=0,
635
+ ):
636
+ """Add coastlines to an image file. The resulting image is in 'RGBA' mode.
425
637
 
426
638
  :Parameters:
427
- filename : str
428
- Image file
429
- proj4_string : str
430
- Projection of area as Proj.4 string
431
- area_extent : list
432
- Area extent as a list (LL_x, LL_y, UR_x, UR_y)
433
- resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
434
- Dataset resolution to use
435
- level : int, optional {1, 2, 3, 4}
436
- Detail level of dataset
437
- fill : str or (R, G, B), optional
438
- Land color
439
- fill_opacity : int, optional {0; 255}
440
- Opacity of land color
441
- outline : str or (R, G, B), optional
442
- Coastline color
443
- width : float, optional
444
- Width of coastline
445
- outline_opacity : int, optional {0; 255}
446
- Opacity of coastline color
447
- x_offset : float, optional
448
- Pixel offset in x direction
449
- y_offset : float, optional
450
- Pixel offset in y direction
451
- """
639
+ filename : str
640
+ Image file
641
+ proj4_string : str
642
+ Projection of area as Proj.4 string
643
+ area_extent : list
644
+ Area extent as a list (LL_x, LL_y, UR_x, UR_y)
645
+ resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
646
+ Dataset resolution to use
647
+ level : int, optional {1, 2, 3, 4}
648
+ Detail level of dataset
649
+ fill : str or (R, G, B), optional
650
+ Land color
651
+ fill_opacity : int, optional {0; 255}
652
+ Opacity of land color
653
+ outline : str or (R, G, B), optional
654
+ Coastline color
655
+ width : float, optional
656
+ Width of coastline
657
+ outline_opacity : int, optional {0; 255}
658
+ Opacity of coastline color
659
+ x_offset : float, optional
660
+ Pixel offset in x direction
661
+ y_offset : float, optional
662
+ Pixel offset in y direction
452
663
 
664
+ """
453
665
  image = Image.open(filename)
454
- self.add_coastlines(image, area_def, resolution=resolution,
455
- level=level, fill=fill,
456
- fill_opacity=fill_opacity, outline=outline,
457
- width=width, outline_opacity=outline_opacity,
458
- x_offset=x_offset, y_offset=y_offset)
666
+ image = image.convert("RGBA")
667
+ self.add_coastlines(
668
+ image,
669
+ area_def,
670
+ resolution=resolution,
671
+ level=level,
672
+ fill=fill,
673
+ fill_opacity=fill_opacity,
674
+ outline=outline,
675
+ width=width,
676
+ outline_opacity=outline_opacity,
677
+ x_offset=x_offset,
678
+ y_offset=y_offset,
679
+ )
459
680
  image.save(filename)
460
681
 
461
- def add_borders(self, image, area_def, resolution='c', level=1,
462
- outline='white', width=1, outline_opacity=255,
463
- x_offset=0, y_offset=0):
464
- """Add borders to a PIL image object
682
+ def add_borders(
683
+ self,
684
+ image,
685
+ area_def,
686
+ resolution="c",
687
+ level=1,
688
+ outline="white",
689
+ width=1,
690
+ outline_opacity=255,
691
+ x_offset=0,
692
+ y_offset=0,
693
+ ):
694
+ """Add borders to a PIL image object.
465
695
 
466
696
  :Parameters:
467
- image : object
468
- PIL image object
469
- proj4_string : str
470
- Projection of area as Proj.4 string
471
- area_extent : list
472
- Area extent as a list (LL_x, LL_y, UR_x, UR_y)
473
- resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
474
- Dataset resolution to use
475
- level : int, optional {1, 2, 3}
476
- Detail level of dataset
477
- outline : str or (R, G, B), optional
478
- Border color
479
- width : float, optional
480
- Width of coastline
481
- outline_opacity : int, optional {0; 255}
482
- Opacity of coastline color
483
- x_offset : float, optional
484
- Pixel offset in x direction
485
- y_offset : float, optional
486
- Pixel offset in y direction
487
- """
697
+ image : object
698
+ PIL image object
699
+ proj4_string : str
700
+ Projection of area as Proj.4 string
701
+ area_extent : list
702
+ Area extent as a list (LL_x, LL_y, UR_x, UR_y)
703
+ resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
704
+ Dataset resolution to use
705
+ level : int, optional {1, 2, 3}
706
+ Detail level of dataset
707
+ outline : str or (R, G, B), optional
708
+ Border color
709
+ width : float, optional
710
+ Width of coastline
711
+ outline_opacity : int, optional {0; 255}
712
+ Opacity of coastline color
713
+ x_offset : float, optional
714
+ Pixel offset in x direction
715
+ y_offset : float, optional
716
+ Pixel offset in y direction
488
717
 
489
- self._add_feature(image, area_def, 'line', 'WDBII', tag='border',
490
- resolution=resolution, level=level, outline=outline,
491
- width=width, outline_opacity=outline_opacity,
492
- x_offset=x_offset, y_offset=y_offset)
493
-
494
- def add_borders_to_file(self, filename, area_def, resolution='c',
495
- level=1, outline='white', width=1,
496
- outline_opacity=255, x_offset=0, y_offset=0):
497
- """Add borders to an image file
718
+ """
719
+ self._add_feature(
720
+ image,
721
+ area_def,
722
+ "line",
723
+ "WDBII",
724
+ tag="border",
725
+ resolution=resolution,
726
+ level=level,
727
+ outline=outline,
728
+ width=width,
729
+ outline_opacity=outline_opacity,
730
+ x_offset=x_offset,
731
+ y_offset=y_offset,
732
+ )
733
+
734
+ def add_borders_to_file(
735
+ self,
736
+ filename,
737
+ area_def,
738
+ resolution="c",
739
+ level=1,
740
+ outline="white",
741
+ width=1,
742
+ outline_opacity=255,
743
+ x_offset=0,
744
+ y_offset=0,
745
+ ):
746
+ """Add borders to an image file. The resulting image is in 'RGBA' mode.
498
747
 
499
748
  :Parameters:
500
- image : object
501
- Image file
502
- proj4_string : str
503
- Projection of area as Proj.4 string
504
- area_extent : list
505
- Area extent as a list (LL_x, LL_y, UR_x, UR_y)
506
- resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
507
- Dataset resolution to use
508
- level : int, optional {1, 2, 3}
509
- Detail level of dataset
510
- outline : str or (R, G, B), optional
511
- Border color
512
- width : float, optional
513
- Width of coastline
514
- outline_opacity : int, optional {0; 255}
515
- Opacity of coastline color
516
- x_offset : float, optional
517
- Pixel offset in x direction
518
- y_offset : float, optional
519
- Pixel offset in y direction
749
+ image : object
750
+ Image file
751
+ proj4_string : str
752
+ Projection of area as Proj.4 string
753
+ area_extent : list
754
+ Area extent as a list (LL_x, LL_y, UR_x, UR_y)
755
+ resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
756
+ Dataset resolution to use
757
+ level : int, optional {1, 2, 3}
758
+ Detail level of dataset
759
+ outline : str or (R, G, B), optional
760
+ Border color
761
+ width : float, optional
762
+ Width of coastline
763
+ outline_opacity : int, optional {0; 255}
764
+ Opacity of coastline color
765
+ x_offset : float, optional
766
+ Pixel offset in x direction
767
+ y_offset : float, optional
768
+ Pixel offset in y direction
769
+
520
770
  """
521
771
  image = Image.open(filename)
522
- self.add_borders(image, area_def, resolution=resolution, level=level,
523
- outline=outline, width=width,
524
- outline_opacity=outline_opacity, x_offset=x_offset,
525
- y_offset=y_offset)
772
+ image = image.convert("RGBA")
773
+ self.add_borders(
774
+ image,
775
+ area_def,
776
+ resolution=resolution,
777
+ level=level,
778
+ outline=outline,
779
+ width=width,
780
+ outline_opacity=outline_opacity,
781
+ x_offset=x_offset,
782
+ y_offset=y_offset,
783
+ )
526
784
  image.save(filename)
527
785
 
528
- def add_rivers(self, image, area_def, resolution='c', level=1,
529
- outline='white', width=1, outline_opacity=255,
530
- x_offset=0, y_offset=0):
531
- """Add rivers to a PIL image object
786
+ def add_rivers(
787
+ self,
788
+ image,
789
+ area_def,
790
+ resolution="c",
791
+ level=1,
792
+ outline="white",
793
+ width=1,
794
+ outline_opacity=255,
795
+ x_offset=0,
796
+ y_offset=0,
797
+ ):
798
+ """Add rivers to a PIL image object.
532
799
 
533
800
  :Parameters:
534
- image : object
535
- PIL image object
536
- proj4_string : str
537
- Projection of area as Proj.4 string
538
- area_extent : list
539
- Area extent as a list (LL_x, LL_y, UR_x, UR_y)
540
- resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
541
- Dataset resolution to use
542
- level : int, optional {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
543
- Detail level of dataset
544
- outline : str or (R, G, B), optional
545
- River color
546
- width : float, optional
547
- Width of coastline
548
- outline_opacity : int, optional {0; 255}
549
- Opacity of coastline color
550
- x_offset : float, optional
551
- Pixel offset in x direction
552
- y_offset : float, optional
553
- Pixel offset in y direction
554
- """
555
-
556
- self._add_feature(image, area_def, 'line', 'WDBII', tag='river',
557
- zero_pad=True, resolution=resolution, level=level,
558
- outline=outline, width=width,
559
- outline_opacity=outline_opacity, x_offset=x_offset,
560
- y_offset=y_offset)
801
+ image : object
802
+ PIL image object
803
+ proj4_string : str
804
+ Projection of area as Proj.4 string
805
+ area_extent : list
806
+ Area extent as a list (LL_x, LL_y, UR_x, UR_y)
807
+ resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
808
+ Dataset resolution to use
809
+ level : int, optional {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
810
+ Detail level of dataset
811
+ outline : str or (R, G, B), optional
812
+ River color
813
+ width : float, optional
814
+ Width of coastline
815
+ outline_opacity : int, optional {0; 255}
816
+ Opacity of coastline color
817
+ x_offset : float, optional
818
+ Pixel offset in x direction
819
+ y_offset : float, optional
820
+ Pixel offset in y direction
561
821
 
562
- def add_rivers_to_file(self, filename, area_def, resolution='c', level=1,
563
- outline='white', width=1, outline_opacity=255,
564
- x_offset=0, y_offset=0):
565
- """Add rivers to an image file
822
+ """
823
+ self._add_feature(
824
+ image,
825
+ area_def,
826
+ "line",
827
+ "WDBII",
828
+ tag="river",
829
+ zero_pad=True,
830
+ resolution=resolution,
831
+ level=level,
832
+ outline=outline,
833
+ width=width,
834
+ outline_opacity=outline_opacity,
835
+ x_offset=x_offset,
836
+ y_offset=y_offset,
837
+ )
838
+
839
+ def add_rivers_to_file(
840
+ self,
841
+ filename,
842
+ area_def,
843
+ resolution="c",
844
+ level=1,
845
+ outline="white",
846
+ width=1,
847
+ outline_opacity=255,
848
+ x_offset=0,
849
+ y_offset=0,
850
+ ):
851
+ """Add rivers to an image file. The resulting image is in 'RGBA' mode.
566
852
 
567
853
  :Parameters:
568
- image : object
569
- Image file
570
- proj4_string : str
571
- Projection of area as Proj.4 string
572
- area_extent : list
573
- Area extent as a list (LL_x, LL_y, UR_x, UR_y)
574
- resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
575
- Dataset resolution to use
576
- level : int, optional {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
577
- Detail level of dataset
578
- outline : str or (R, G, B), optional
579
- River color
580
- width : float, optional
581
- Width of coastline
582
- outline_opacity : int, optional {0; 255}
583
- Opacity of coastline color
584
- x_offset : float, optional
585
- Pixel offset in x direction
586
- y_offset : float, optional
587
- Pixel offset in y direction
588
- """
854
+ image : object
855
+ Image file
856
+ proj4_string : str
857
+ Projection of area as Proj.4 string
858
+ area_extent : list
859
+ Area extent as a list (LL_x, LL_y, UR_x, UR_y)
860
+ resolution : str, optional {'c', 'l', 'i', 'h', 'f'}
861
+ Dataset resolution to use
862
+ level : int, optional {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
863
+ Detail level of dataset
864
+ outline : str or (R, G, B), optional
865
+ River color
866
+ width : float, optional
867
+ Width of coastline
868
+ outline_opacity : int, optional {0; 255}
869
+ Opacity of coastline color
870
+ x_offset : float, optional
871
+ Pixel offset in x direction
872
+ y_offset : float, optional
873
+ Pixel offset in y direction
589
874
 
875
+ """
590
876
  image = Image.open(filename)
591
- self.add_rivers(image, area_def, resolution=resolution, level=level,
592
- outline=outline, width=width,
593
- outline_opacity=outline_opacity, x_offset=x_offset,
594
- y_offset=y_offset)
877
+ image = image.convert("RGBA")
878
+ self.add_rivers(
879
+ image,
880
+ area_def,
881
+ resolution=resolution,
882
+ level=level,
883
+ outline=outline,
884
+ width=width,
885
+ outline_opacity=outline_opacity,
886
+ x_offset=x_offset,
887
+ y_offset=y_offset,
888
+ )
595
889
  image.save(filename)
596
890
 
597
891
  def _get_font(self, outline, font_file, font_size):