geovizpy 0.1.5__tar.gz → 0.1.7__tar.gz
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.
- {geovizpy-0.1.5 → geovizpy-0.1.7}/PKG-INFO +118 -117
- {geovizpy-0.1.5 → geovizpy-0.1.7}/README.md +5 -4
- {geovizpy-0.1.5 → geovizpy-0.1.7}/geovizpy/geoviz.py +3 -1
- geovizpy-0.1.7/geovizpy/insets.py +20 -0
- {geovizpy-0.1.5 → geovizpy-0.1.7}/geovizpy/renderer.py +94 -27
- {geovizpy-0.1.5 → geovizpy-0.1.7}/geovizpy.egg-info/PKG-INFO +118 -117
- {geovizpy-0.1.5 → geovizpy-0.1.7}/geovizpy.egg-info/SOURCES.txt +1 -0
- {geovizpy-0.1.5 → geovizpy-0.1.7}/setup.cfg +4 -4
- {geovizpy-0.1.5 → geovizpy-0.1.7}/setup.py +1 -1
- {geovizpy-0.1.5 → geovizpy-0.1.7}/geovizpy/__init__.py +0 -0
- {geovizpy-0.1.5 → geovizpy-0.1.7}/geovizpy/controls.py +0 -0
- {geovizpy-0.1.5 → geovizpy-0.1.7}/geovizpy/effects.py +0 -0
- {geovizpy-0.1.5 → geovizpy-0.1.7}/geovizpy/legends.py +0 -0
- {geovizpy-0.1.5 → geovizpy-0.1.7}/geovizpy/marks.py +0 -0
- {geovizpy-0.1.5 → geovizpy-0.1.7}/geovizpy/plots.py +0 -0
- {geovizpy-0.1.5 → geovizpy-0.1.7}/geovizpy.egg-info/dependency_links.txt +0 -0
- {geovizpy-0.1.5 → geovizpy-0.1.7}/geovizpy.egg-info/requires.txt +0 -0
- {geovizpy-0.1.5 → geovizpy-0.1.7}/geovizpy.egg-info/top_level.txt +0 -0
|
@@ -1,117 +1,118 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: geovizpy
|
|
3
|
-
Version: 0.1.
|
|
4
|
-
Summary: A Python wrapper for the geoviz JavaScript library
|
|
5
|
-
Author: fbxyz
|
|
6
|
-
Project-URL: Source, https://codeberg.org/fbxyz/geovizpy
|
|
7
|
-
Classifier: Programming Language :: Python :: 3
|
|
8
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
-
Classifier: Operating System :: OS Independent
|
|
10
|
-
Requires-Python: >=3.6
|
|
11
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
Provides-Extra: export
|
|
13
|
-
Requires-Dist: playwright; extra == "export"
|
|
14
|
-
Dynamic: author
|
|
15
|
-
Dynamic: classifier
|
|
16
|
-
Dynamic: description
|
|
17
|
-
Dynamic: description-content-type
|
|
18
|
-
Dynamic: project-url
|
|
19
|
-
Dynamic: provides-extra
|
|
20
|
-
Dynamic: requires-python
|
|
21
|
-
Dynamic: summary
|
|
22
|
-
|
|
23
|
-
# geovizpy
|
|
24
|
-
|
|
25
|
-
**geovizpy** is a Python wrapper for the `geoviz` JavaScript library, designed to bring the power of D3.js-based thematic mapping to Python. It allows you to create high-quality, interactive maps directly from Python scripts or Jupyter notebooks.
|
|
26
|
-
|
|
27
|
-
This library is a wrapper around the
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
- **
|
|
34
|
-
- **
|
|
35
|
-
- **
|
|
36
|
-
- **
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
#
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: geovizpy
|
|
3
|
+
Version: 0.1.7
|
|
4
|
+
Summary: A Python wrapper for the geoviz JavaScript library
|
|
5
|
+
Author: fbxyz
|
|
6
|
+
Project-URL: Source, https://codeberg.org/fbxyz/geovizpy
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.6
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Provides-Extra: export
|
|
13
|
+
Requires-Dist: playwright; extra == "export"
|
|
14
|
+
Dynamic: author
|
|
15
|
+
Dynamic: classifier
|
|
16
|
+
Dynamic: description
|
|
17
|
+
Dynamic: description-content-type
|
|
18
|
+
Dynamic: project-url
|
|
19
|
+
Dynamic: provides-extra
|
|
20
|
+
Dynamic: requires-python
|
|
21
|
+
Dynamic: summary
|
|
22
|
+
|
|
23
|
+
# geovizpy
|
|
24
|
+
|
|
25
|
+
**geovizpy** is a Python wrapper for the `geoviz` JavaScript library, designed to bring the power of D3.js-based thematic mapping to Python. It allows you to create high-quality, interactive maps directly from Python scripts or Jupyter notebooks.
|
|
26
|
+
|
|
27
|
+
This library is a wrapper around the `geoviz` library. For detailed information on the underlying mapping logic, please refer to the [original geoviz documentation](https://github.com/neocarto/geoviz).
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- **Simple, chainable API**: Build complex maps by chaining intuitive methods.
|
|
34
|
+
- **Variety of Map Types**: Create choropleth, proportional symbol, typology, and other thematic maps.
|
|
35
|
+
- **Interactive Controls**: Add hover-to-expand controls for toggling layer visibility and exporting the map as SVG or PNG.
|
|
36
|
+
- **Customizable**: Extensive options to customize colors, legends, strokes, and more.
|
|
37
|
+
- **Standalone HTML**: Renders self-contained HTML files with no server required.
|
|
38
|
+
- **Image Export**: Save maps directly to PNG or SVG from Python (requires optional dependencies).
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
### Standard Installation
|
|
43
|
+
|
|
44
|
+
You can install the core library using pip:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install geovizpy
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Or install directly from the source repository:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install git+https://codeberg.org/fbxyz/geovizpy.git
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### For Image Export
|
|
57
|
+
|
|
58
|
+
To save maps as PNG or SVG files directly from Python, you need to install the optional `export` dependencies:
|
|
59
|
+
|
|
60
|
+
1. **Install the extra dependencies:**
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install "geovizpy[export]"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
2. **Install Playwright's browser binaries:**
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
playwright install
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
On Linux, you may also need to install host dependencies:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
sudo playwright install-deps
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Quick Start
|
|
79
|
+
|
|
80
|
+
Here is a simple example of how to create a choropleth map:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from geovizpy import Geoviz
|
|
84
|
+
import json
|
|
85
|
+
|
|
86
|
+
# Load your GeoJSON data
|
|
87
|
+
# (Assuming 'world.json' is in a 'data' subdirectory)
|
|
88
|
+
with open("data/world.json") as f:
|
|
89
|
+
world_data = json.load(f)
|
|
90
|
+
|
|
91
|
+
# Initialize the map
|
|
92
|
+
viz = Geoviz(projection="EqualEarth", width=800)
|
|
93
|
+
|
|
94
|
+
# Add layers
|
|
95
|
+
viz.outline()
|
|
96
|
+
viz.graticule()
|
|
97
|
+
|
|
98
|
+
# Add a choropleth layer
|
|
99
|
+
viz.choro(
|
|
100
|
+
data=world_data,
|
|
101
|
+
var="gdppc",
|
|
102
|
+
colors="Blues",
|
|
103
|
+
legend=True,
|
|
104
|
+
leg_title="GDP per Capita"
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
# Add interactive controls
|
|
108
|
+
viz.add_layer_control(layers=["choropleth_gdp"])
|
|
109
|
+
viz.add_export_control()
|
|
110
|
+
|
|
111
|
+
# Save the map
|
|
112
|
+
viz.save("my_map.html") # Renders an interactive HTML file
|
|
113
|
+
# viz.save("my_map.png") # Renders a static PNG image (requires export dependencies)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Documentation
|
|
117
|
+
|
|
118
|
+
For more detailed information on all available methods and parameters, please see the [full documentation](https://geovizpy.readthedocs.io/en/latest/).
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
**geovizpy** is a Python wrapper for the `geoviz` JavaScript library, designed to bring the power of D3.js-based thematic mapping to Python. It allows you to create high-quality, interactive maps directly from Python scripts or Jupyter notebooks.
|
|
4
4
|
|
|
5
|
-
This library is a wrapper around the
|
|
5
|
+
This library is a wrapper around the `geoviz` library. For detailed information on the underlying mapping logic, please refer to the [original geoviz documentation](https://github.com/neocarto/geoviz).
|
|
6
|
+
|
|
7
|
+

|
|
6
8
|
|
|
7
9
|
## Features
|
|
8
10
|
|
|
@@ -31,7 +33,7 @@ pip install git+https://codeberg.org/fbxyz/geovizpy.git
|
|
|
31
33
|
|
|
32
34
|
### For Image Export
|
|
33
35
|
|
|
34
|
-
To save maps as PNG or SVG files directly from Python, you need to install the optional `export` dependencies
|
|
36
|
+
To save maps as PNG or SVG files directly from Python, you need to install the optional `export` dependencies:
|
|
35
37
|
|
|
36
38
|
1. **Install the extra dependencies:**
|
|
37
39
|
|
|
@@ -91,5 +93,4 @@ viz.save("my_map.html") # Renders an interactive HTML file
|
|
|
91
93
|
|
|
92
94
|
## Documentation
|
|
93
95
|
|
|
94
|
-
For more detailed information on all available methods and parameters, please see the [full documentation](https://
|
|
95
|
-
|
|
96
|
+
For more detailed information on all available methods and parameters, please see the [full documentation](https://geovizpy.readthedocs.io/en/latest/).
|
|
@@ -6,6 +6,7 @@ from .legends import LegendsMixin
|
|
|
6
6
|
from .effects import EffectsMixin
|
|
7
7
|
from .controls import ControlsMixin
|
|
8
8
|
from .renderer import RendererMixin
|
|
9
|
+
from .insets import InsetsMixin
|
|
9
10
|
|
|
10
11
|
class Geoviz(
|
|
11
12
|
MarksMixin,
|
|
@@ -13,7 +14,8 @@ class Geoviz(
|
|
|
13
14
|
LegendsMixin,
|
|
14
15
|
EffectsMixin,
|
|
15
16
|
ControlsMixin,
|
|
16
|
-
RendererMixin
|
|
17
|
+
RendererMixin,
|
|
18
|
+
InsetsMixin
|
|
17
19
|
):
|
|
18
20
|
"""
|
|
19
21
|
A Python wrapper for the geoviz JavaScript library.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Module for creating inset maps."""
|
|
2
|
+
|
|
3
|
+
class InsetsMixin:
|
|
4
|
+
"""Mixin class for adding inset map functionality."""
|
|
5
|
+
|
|
6
|
+
def inset(self, **kwargs):
|
|
7
|
+
"""
|
|
8
|
+
Add an inset map to the main map.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
pos (list): [x, y] position of the inset.
|
|
12
|
+
width (int): Width of the inset SVG.
|
|
13
|
+
height (int): Height of the inset SVG.
|
|
14
|
+
domain (object): GeoJSON to define the domain of the inset.
|
|
15
|
+
projection (string): Projection name for the inset.
|
|
16
|
+
outline (dict): Dictionary for outline properties (e.g., {"stroke": "black", "strokeWidth": 2}).
|
|
17
|
+
"""
|
|
18
|
+
# The actual creation of the inset will be handled in the JavaScript renderer,
|
|
19
|
+
# where the `geoviz.create` function will be called with the main SVG as parent.
|
|
20
|
+
return self._add_command("inset.create", kwargs)
|
|
@@ -4,6 +4,9 @@ import json
|
|
|
4
4
|
import tempfile
|
|
5
5
|
import os
|
|
6
6
|
import time
|
|
7
|
+
import html
|
|
8
|
+
import sys
|
|
9
|
+
import subprocess
|
|
7
10
|
|
|
8
11
|
class RendererMixin:
|
|
9
12
|
"""Mixin class for rendering the map."""
|
|
@@ -33,14 +36,14 @@ class RendererMixin:
|
|
|
33
36
|
"""Return the configuration as a JSON string."""
|
|
34
37
|
return json.dumps(self.get_config())
|
|
35
38
|
|
|
36
|
-
def
|
|
37
|
-
"""
|
|
39
|
+
def _get_html_content(self):
|
|
40
|
+
"""Generate the full HTML content string."""
|
|
38
41
|
json_commands = self.to_json()
|
|
39
42
|
|
|
40
43
|
layer_control_js = self._get_layer_control_js()
|
|
41
44
|
export_control_js = self._get_export_control_js()
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
return f"""
|
|
44
47
|
<!DOCTYPE html>
|
|
45
48
|
<html>
|
|
46
49
|
<head>
|
|
@@ -49,7 +52,7 @@ class RendererMixin:
|
|
|
49
52
|
<script src="https://cdn.jsdelivr.net/npm/d3@7"></script>
|
|
50
53
|
<script src="https://cdn.jsdelivr.net/npm/geoviz@0.9.8"></script>
|
|
51
54
|
<style>
|
|
52
|
-
body {{ margin: 0; padding: 0; }}
|
|
55
|
+
body {{ margin: 0; padding: 0; overflow: hidden; }}
|
|
53
56
|
button {{ background: #f8f9fa; border: 1px solid #ddd; border-radius: 3px; }}
|
|
54
57
|
button:hover {{ background: #e2e6ea; }}
|
|
55
58
|
</style>
|
|
@@ -91,12 +94,21 @@ class RendererMixin:
|
|
|
91
94
|
}} else {{
|
|
92
95
|
console.warn("Method " + parts[0] + " not found");
|
|
93
96
|
}}
|
|
94
|
-
}} else if (parts.length === 2) {
|
|
95
|
-
if (
|
|
97
|
+
}} else if (parts.length === 2) {
|
|
98
|
+
if (cmd.name === "inset.create") {
|
|
99
|
+
const insetArgs = { ...cmd.args };
|
|
100
|
+
const outlineArgs = insetArgs.outline;
|
|
101
|
+
delete insetArgs.outline;
|
|
102
|
+
|
|
103
|
+
const insetSvg = geoviz.create({ parent: svg, ...insetArgs });
|
|
104
|
+
if (outlineArgs) {
|
|
105
|
+
insetSvg.outline(outlineArgs);
|
|
106
|
+
}
|
|
107
|
+
} else if (svg[parts[0]] && svg[parts[0]][parts[1]]) {
|
|
96
108
|
svg[parts[0]][parts[1]](cmd.args);
|
|
97
|
-
}
|
|
109
|
+
} else {
|
|
98
110
|
console.warn("Method " + cmd.name + " not found");
|
|
99
|
-
}
|
|
111
|
+
}
|
|
100
112
|
}}
|
|
101
113
|
}}
|
|
102
114
|
}});
|
|
@@ -111,10 +123,35 @@ class RendererMixin:
|
|
|
111
123
|
</body>
|
|
112
124
|
</html>
|
|
113
125
|
"""
|
|
126
|
+
|
|
127
|
+
def render_html(self, filename="map.html"):
|
|
128
|
+
"""Render the map to an HTML file."""
|
|
129
|
+
html_content = self._get_html_content()
|
|
114
130
|
with open(filename, "w") as f:
|
|
115
131
|
f.write(html_content)
|
|
116
132
|
print(f"Map saved to {filename}")
|
|
117
133
|
|
|
134
|
+
def show(self, width=800, height=600):
|
|
135
|
+
"""
|
|
136
|
+
Display the map in a Jupyter notebook using an IFrame.
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
width (int/str): Width of the display area (default 800).
|
|
140
|
+
height (int/str): Height of the display area (default 600).
|
|
141
|
+
"""
|
|
142
|
+
try:
|
|
143
|
+
from IPython.display import IFrame
|
|
144
|
+
import base64
|
|
145
|
+
except ImportError:
|
|
146
|
+
print("IPython is required to display the map. Please install it with 'pip install ipython'.")
|
|
147
|
+
return
|
|
148
|
+
|
|
149
|
+
html_content = self._get_html_content()
|
|
150
|
+
b64_content = base64.b64encode(html_content.encode('utf-8')).decode('utf-8')
|
|
151
|
+
data_uri = f"data:text/html;base64,{b64_content}"
|
|
152
|
+
|
|
153
|
+
return IFrame(src=data_uri, width=width, height=height)
|
|
154
|
+
|
|
118
155
|
def save(self, filename="map.html"):
|
|
119
156
|
"""
|
|
120
157
|
Save the map to a file.
|
|
@@ -134,39 +171,69 @@ class RendererMixin:
|
|
|
134
171
|
print("Error: filename must end with .html, .png, or .svg")
|
|
135
172
|
|
|
136
173
|
def _save_image(self, filename):
|
|
137
|
-
"""Internal method to save as PNG or SVG using Playwright."""
|
|
174
|
+
"""Internal method to save as PNG or SVG using Playwright via a subprocess."""
|
|
175
|
+
|
|
176
|
+
# Check if playwright is installed
|
|
138
177
|
try:
|
|
139
|
-
|
|
178
|
+
import playwright
|
|
140
179
|
except ImportError:
|
|
141
180
|
print("Error: Playwright is required for image export.")
|
|
142
181
|
print("Please install it with: pip install geovizpy[export] && playwright install")
|
|
143
182
|
return
|
|
144
183
|
|
|
184
|
+
# Create a temporary HTML file
|
|
145
185
|
with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".html") as tmp_file:
|
|
146
186
|
self.render_html(tmp_file.name)
|
|
147
187
|
tmp_path = tmp_file.name
|
|
148
188
|
|
|
189
|
+
# Create a temporary Python script to run Playwright
|
|
190
|
+
# This isolates Playwright from the current asyncio loop (Jupyter)
|
|
191
|
+
script_content = f"""
|
|
192
|
+
import os
|
|
193
|
+
from playwright.sync_api import sync_playwright
|
|
194
|
+
|
|
195
|
+
def run():
|
|
196
|
+
try:
|
|
197
|
+
with sync_playwright() as p:
|
|
198
|
+
browser = p.chromium.launch()
|
|
199
|
+
page = browser.new_page(viewport={{"width": 1000, "height": 800}})
|
|
200
|
+
page.goto(f"file://{{os.path.abspath('{tmp_path}')}}")
|
|
201
|
+
page.wait_for_timeout(2000)
|
|
202
|
+
|
|
203
|
+
if "{filename}".endswith(".svg"):
|
|
204
|
+
svg_outer = page.locator("svg").first.evaluate("el => el.outerHTML")
|
|
205
|
+
with open("{filename}", "w") as f:
|
|
206
|
+
f.write(svg_outer)
|
|
207
|
+
else:
|
|
208
|
+
page.locator("svg").first.screenshot(path="{filename}")
|
|
209
|
+
|
|
210
|
+
browser.close()
|
|
211
|
+
print(f"Image saved to {filename}")
|
|
212
|
+
except Exception as e:
|
|
213
|
+
print(f"Error in subprocess: {{e}}")
|
|
214
|
+
exit(1)
|
|
215
|
+
|
|
216
|
+
if __name__ == "__main__":
|
|
217
|
+
run()
|
|
218
|
+
"""
|
|
219
|
+
|
|
220
|
+
with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".py") as tmp_script:
|
|
221
|
+
tmp_script.write(script_content)
|
|
222
|
+
tmp_script_path = tmp_script.name
|
|
223
|
+
|
|
149
224
|
try:
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if filename.endswith(".svg"):
|
|
157
|
-
svg_outer = page.locator("svg").first.evaluate("el => el.outerHTML")
|
|
158
|
-
with open(filename, "w") as f:
|
|
159
|
-
f.write(svg_outer)
|
|
160
|
-
else: # .png
|
|
161
|
-
page.locator("svg").first.screenshot(path=filename)
|
|
162
|
-
|
|
163
|
-
browser.close()
|
|
164
|
-
print(f"Image saved to {filename}")
|
|
165
|
-
except Exception as e:
|
|
166
|
-
print(f"Error saving image: {e}")
|
|
225
|
+
# Run the script in a subprocess
|
|
226
|
+
result = subprocess.run([sys.executable, tmp_script_path], capture_output=True, text=True)
|
|
227
|
+
if result.returncode != 0:
|
|
228
|
+
print(f"Error saving image: {result.stderr}")
|
|
229
|
+
else:
|
|
230
|
+
print(result.stdout.strip())
|
|
167
231
|
finally:
|
|
232
|
+
# Cleanup
|
|
168
233
|
if os.path.exists(tmp_path):
|
|
169
234
|
os.remove(tmp_path)
|
|
235
|
+
if os.path.exists(tmp_script_path):
|
|
236
|
+
os.remove(tmp_script_path)
|
|
170
237
|
|
|
171
238
|
def _get_layer_control_js(self):
|
|
172
239
|
if not self.layer_control_config:
|
|
@@ -1,117 +1,118 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: geovizpy
|
|
3
|
-
Version: 0.1.
|
|
4
|
-
Summary: A Python wrapper for the geoviz JavaScript library
|
|
5
|
-
Author: fbxyz
|
|
6
|
-
Project-URL: Source, https://codeberg.org/fbxyz/geovizpy
|
|
7
|
-
Classifier: Programming Language :: Python :: 3
|
|
8
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
-
Classifier: Operating System :: OS Independent
|
|
10
|
-
Requires-Python: >=3.6
|
|
11
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
Provides-Extra: export
|
|
13
|
-
Requires-Dist: playwright; extra == "export"
|
|
14
|
-
Dynamic: author
|
|
15
|
-
Dynamic: classifier
|
|
16
|
-
Dynamic: description
|
|
17
|
-
Dynamic: description-content-type
|
|
18
|
-
Dynamic: project-url
|
|
19
|
-
Dynamic: provides-extra
|
|
20
|
-
Dynamic: requires-python
|
|
21
|
-
Dynamic: summary
|
|
22
|
-
|
|
23
|
-
# geovizpy
|
|
24
|
-
|
|
25
|
-
**geovizpy** is a Python wrapper for the `geoviz` JavaScript library, designed to bring the power of D3.js-based thematic mapping to Python. It allows you to create high-quality, interactive maps directly from Python scripts or Jupyter notebooks.
|
|
26
|
-
|
|
27
|
-
This library is a wrapper around the
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
- **
|
|
34
|
-
- **
|
|
35
|
-
- **
|
|
36
|
-
- **
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
#
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: geovizpy
|
|
3
|
+
Version: 0.1.7
|
|
4
|
+
Summary: A Python wrapper for the geoviz JavaScript library
|
|
5
|
+
Author: fbxyz
|
|
6
|
+
Project-URL: Source, https://codeberg.org/fbxyz/geovizpy
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.6
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Provides-Extra: export
|
|
13
|
+
Requires-Dist: playwright; extra == "export"
|
|
14
|
+
Dynamic: author
|
|
15
|
+
Dynamic: classifier
|
|
16
|
+
Dynamic: description
|
|
17
|
+
Dynamic: description-content-type
|
|
18
|
+
Dynamic: project-url
|
|
19
|
+
Dynamic: provides-extra
|
|
20
|
+
Dynamic: requires-python
|
|
21
|
+
Dynamic: summary
|
|
22
|
+
|
|
23
|
+
# geovizpy
|
|
24
|
+
|
|
25
|
+
**geovizpy** is a Python wrapper for the `geoviz` JavaScript library, designed to bring the power of D3.js-based thematic mapping to Python. It allows you to create high-quality, interactive maps directly from Python scripts or Jupyter notebooks.
|
|
26
|
+
|
|
27
|
+
This library is a wrapper around the `geoviz` library. For detailed information on the underlying mapping logic, please refer to the [original geoviz documentation](https://github.com/neocarto/geoviz).
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- **Simple, chainable API**: Build complex maps by chaining intuitive methods.
|
|
34
|
+
- **Variety of Map Types**: Create choropleth, proportional symbol, typology, and other thematic maps.
|
|
35
|
+
- **Interactive Controls**: Add hover-to-expand controls for toggling layer visibility and exporting the map as SVG or PNG.
|
|
36
|
+
- **Customizable**: Extensive options to customize colors, legends, strokes, and more.
|
|
37
|
+
- **Standalone HTML**: Renders self-contained HTML files with no server required.
|
|
38
|
+
- **Image Export**: Save maps directly to PNG or SVG from Python (requires optional dependencies).
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
### Standard Installation
|
|
43
|
+
|
|
44
|
+
You can install the core library using pip:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install geovizpy
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Or install directly from the source repository:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install git+https://codeberg.org/fbxyz/geovizpy.git
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### For Image Export
|
|
57
|
+
|
|
58
|
+
To save maps as PNG or SVG files directly from Python, you need to install the optional `export` dependencies:
|
|
59
|
+
|
|
60
|
+
1. **Install the extra dependencies:**
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install "geovizpy[export]"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
2. **Install Playwright's browser binaries:**
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
playwright install
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
On Linux, you may also need to install host dependencies:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
sudo playwright install-deps
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Quick Start
|
|
79
|
+
|
|
80
|
+
Here is a simple example of how to create a choropleth map:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from geovizpy import Geoviz
|
|
84
|
+
import json
|
|
85
|
+
|
|
86
|
+
# Load your GeoJSON data
|
|
87
|
+
# (Assuming 'world.json' is in a 'data' subdirectory)
|
|
88
|
+
with open("data/world.json") as f:
|
|
89
|
+
world_data = json.load(f)
|
|
90
|
+
|
|
91
|
+
# Initialize the map
|
|
92
|
+
viz = Geoviz(projection="EqualEarth", width=800)
|
|
93
|
+
|
|
94
|
+
# Add layers
|
|
95
|
+
viz.outline()
|
|
96
|
+
viz.graticule()
|
|
97
|
+
|
|
98
|
+
# Add a choropleth layer
|
|
99
|
+
viz.choro(
|
|
100
|
+
data=world_data,
|
|
101
|
+
var="gdppc",
|
|
102
|
+
colors="Blues",
|
|
103
|
+
legend=True,
|
|
104
|
+
leg_title="GDP per Capita"
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
# Add interactive controls
|
|
108
|
+
viz.add_layer_control(layers=["choropleth_gdp"])
|
|
109
|
+
viz.add_export_control()
|
|
110
|
+
|
|
111
|
+
# Save the map
|
|
112
|
+
viz.save("my_map.html") # Renders an interactive HTML file
|
|
113
|
+
# viz.save("my_map.png") # Renders a static PNG image (requires export dependencies)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Documentation
|
|
117
|
+
|
|
118
|
+
For more detailed information on all available methods and parameters, please see the [full documentation](https://geovizpy.readthedocs.io/en/latest/).
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[egg_info]
|
|
2
|
-
tag_build =
|
|
3
|
-
tag_date = 0
|
|
4
|
-
|
|
1
|
+
[egg_info]
|
|
2
|
+
tag_build =
|
|
3
|
+
tag_date = 0
|
|
4
|
+
|
|
@@ -9,7 +9,7 @@ long_description = (this_directory / "README.md").read_text()
|
|
|
9
9
|
|
|
10
10
|
setup(
|
|
11
11
|
name="geovizpy",
|
|
12
|
-
version="0.1.
|
|
12
|
+
version="0.1.7",
|
|
13
13
|
description="A Python wrapper for the geoviz JavaScript library",
|
|
14
14
|
long_description=long_description,
|
|
15
15
|
long_description_content_type='text/markdown',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|