pycoast 1.1.0__py3-none-any.whl → 1.7.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pycoast/__init__.py +29 -9
- pycoast/conftest.py +14 -0
- pycoast/cw_agg.py +762 -468
- pycoast/cw_base.py +1575 -768
- pycoast/cw_pil.py +583 -363
- pycoast/tests/__init__.py +19 -0
- pycoast/tests/brazil_shapefiles.png +0 -0
- pycoast/tests/brazil_shapefiles_agg.png +0 -0
- pycoast/tests/coasts_and_grid.ini +13 -0
- pycoast/tests/coasts_and_grid_agg.ini +17 -0
- pycoast/tests/contours_europe.png +0 -0
- pycoast/tests/contours_europe_agg.png +0 -0
- pycoast/tests/contours_europe_alpha.png +0 -0
- pycoast/tests/contours_geos.png +0 -0
- pycoast/tests/contours_geos_agg.png +0 -0
- pycoast/tests/dateline_boundary_cross.png +0 -0
- pycoast/tests/dateline_cross.png +0 -0
- pycoast/tests/eastern_shapes_agg.png +0 -0
- pycoast/tests/eastern_shapes_pil.png +0 -0
- pycoast/tests/grid_europe.png +0 -0
- pycoast/tests/grid_europe_agg.png +0 -0
- pycoast/tests/grid_europe_agg_txt.png +0 -0
- pycoast/tests/grid_from_dict_agg.png +0 -0
- pycoast/tests/grid_from_dict_pil.png +0 -0
- pycoast/tests/grid_geos.png +0 -0
- pycoast/tests/grid_geos_agg.png +0 -0
- pycoast/tests/grid_germ.png +0 -0
- pycoast/tests/grid_nh.png +0 -0
- pycoast/tests/grid_nh_agg.png +0 -0
- pycoast/tests/grid_nh_cfg_agg.png +0 -0
- pycoast/tests/lonlat_boundary_cross.png +0 -0
- pycoast/tests/nh_cities_agg.ini +26 -0
- pycoast/tests/nh_cities_agg.png +0 -0
- pycoast/tests/nh_cities_from_dict_agg.png +0 -0
- pycoast/tests/nh_cities_from_dict_pil.png +0 -0
- pycoast/tests/nh_cities_pil.ini +20 -0
- pycoast/tests/nh_cities_pil.png +0 -0
- pycoast/tests/nh_one_shapefile.ini +11 -0
- pycoast/tests/nh_points_agg.ini +24 -0
- pycoast/tests/nh_points_agg.png +0 -0
- pycoast/tests/nh_points_cfg_pil.png +0 -0
- pycoast/tests/nh_points_pil.ini +19 -0
- pycoast/tests/nh_points_pil.png +0 -0
- pycoast/tests/nh_polygons.png +0 -0
- pycoast/tests/nh_polygons_agg.png +0 -0
- pycoast/tests/no_h_scratch_agg.png +0 -0
- pycoast/tests/no_h_scratch_pil.png +0 -0
- pycoast/tests/no_v_scratch_agg.png +0 -0
- pycoast/tests/no_v_scratch_pil.png +0 -0
- pycoast/tests/one_shapefile_from_cfg_agg.png +0 -0
- pycoast/tests/one_shapefile_from_cfg_pil.png +0 -0
- pycoast/tests/test_data/DejaVuSerif.ttf +0 -0
- pycoast/tests/test_data/gshhs/CITIES/cities.txt +20 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L1.dbf +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L1.prj +1 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L1.shp +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L1.shx +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L2.dbf +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L2.prj +1 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L2.shp +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L2.shx +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L3.dbf +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L3.prj +1 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L3.shp +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L3.shx +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L4.dbf +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L4.prj +1 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L4.shp +0 -0
- pycoast/tests/test_data/gshhs/GSHHS_shp/l/GSHHS_l_L4.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L1.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L1.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L1.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L1.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L2.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L2.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L2.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L2.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L3.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L3.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L3.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_border_c_L3.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L01.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L01.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L01.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L01.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L02.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L02.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L02.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L02.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L03.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L03.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L03.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L03.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L04.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L04.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L04.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L04.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L05.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L05.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L05.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L05.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L06.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L06.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L06.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L06.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L07.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L07.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L07.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L07.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L08.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L08.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L08.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L08.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L09.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L09.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L09.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L09.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L1.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L1.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L1.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L10.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L10.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L10.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L10.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L11.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L11.prj +1 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L11.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L11.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L2.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L2.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L2.shx +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L3.dbf +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L3.shp +0 -0
- pycoast/tests/test_data/gshhs/WDBII_shp/c/WDBII_river_c_L3.shx +0 -0
- pycoast/tests/test_data/shapes/Metareas.dbf +0 -0
- pycoast/tests/test_data/shapes/Metareas.mxd +0 -0
- pycoast/tests/test_data/shapes/Metareas.prj +1 -0
- pycoast/tests/test_data/shapes/Metareas.sbn +0 -0
- pycoast/tests/test_data/shapes/Metareas.sbx +0 -0
- pycoast/tests/test_data/shapes/Metareas.shp +0 -0
- pycoast/tests/test_data/shapes/Metareas.shx +0 -0
- pycoast/tests/test_data/shapes/README +3 -0
- pycoast/tests/test_data/shapes/divisao_politica/BRASIL.dbf +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BRASIL.shp +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BRASIL.shx +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Capitais.dbf +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Capitais.shp +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Capitais.shx +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Contorno.dbf +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Contorno.shp +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Contorno.shx +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Regioes.dbf +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Regioes.shp +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/BR_Regioes.shx +0 -0
- pycoast/tests/test_data/shapes/divisao_politica/divisao_politica.txt +40 -0
- pycoast/tests/test_data/shapes/divisao_politica/leia.txt +9 -0
- pycoast/tests/test_data/shapes/metarea5.gsf +0 -0
- pycoast/tests/test_data/shapes/metarea5.tbl +21 -0
- pycoast/tests/test_data/shapes/metarea5.tbl.info +25 -0
- pycoast/tests/test_data/test_config.ini +12 -0
- pycoast/tests/test_pycoast.py +1916 -419
- pycoast/tests/two_shapefiles_agg.png +0 -0
- pycoast/tests/two_shapefiles_pil.png +0 -0
- pycoast/tests/western_shapes_agg.png +0 -0
- pycoast/tests/western_shapes_pil.png +0 -0
- pycoast/version.py +19 -17
- pycoast-1.7.1.dist-info/AUTHORS.md +20 -0
- pycoast-1.7.1.dist-info/LICENSE.txt +674 -0
- pycoast-1.7.1.dist-info/METADATA +81 -0
- pycoast-1.7.1.dist-info/RECORD +172 -0
- {pycoast-1.1.0.dist-info → pycoast-1.7.1.dist-info}/WHEEL +1 -1
- pycoast-1.1.0.dist-info/DESCRIPTION.rst +0 -3
- pycoast-1.1.0.dist-info/METADATA +0 -24
- pycoast-1.1.0.dist-info/RECORD +0 -13
- pycoast-1.1.0.dist-info/metadata.json +0 -1
- {pycoast-1.1.0.dist-info → pycoast-1.7.1.dist-info}/top_level.txt +0 -0
pycoast/cw_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-
|
|
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
|
-
|
|
42
|
-
|
|
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
|
-
"""
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
104
|
-
|
|
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
|
|
117
|
-
"""
|
|
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(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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(
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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(
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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(
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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(
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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(
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
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
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
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
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
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(
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
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
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
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
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
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
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
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
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
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(
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
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
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
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
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
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
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
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
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
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):
|