-
-
Notifications
You must be signed in to change notification settings - Fork 344
/
__init__.py
140 lines (120 loc) · 4.82 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
"""Top-level package for leafmap."""
__author__ = """Qiusheng Wu"""
__email__ = "giswqs@gmail.com"
__version__ = "0.31.4"
import os
from .report import Report
def _in_colab_shell():
"""Tests if the code is being executed within Google Colab."""
import sys
if "google.colab" in sys.modules:
return True
else:
return False
def _use_folium():
"""Whether to use the folium or ipyleaflet plotting backend."""
if os.environ.get("USE_MKDOCS") is not None:
return True
else:
return False
def view_vector(
vector,
zoom_to_layer=True,
pickable=True,
color_column=None,
color_scheme="Quantiles",
color_map=None,
color_k=5,
color_args={},
open_args={},
map_args={},
**kwargs,
):
"""Visualize a vector dataset on the map.
Args:
vector (Union[str, GeoDataFrame]): The file path or URL to the vector data, or a GeoDataFrame.
zoom_to_layer (bool, optional): Flag to zoom to the added layer. Defaults to True.
pickable (bool, optional): Flag to enable picking on the added layer. Defaults to True.
color_column (Optional[str], optional): The column to be used for color encoding. Defaults to None.
color_map (Optional[Union[str, Dict]], optional): The color map to use for color encoding. It can be a string or a dictionary. Defaults to None.
color_scheme (Optional[str], optional): The color scheme to use for color encoding. Defaults to "Quantiles".
Name of a choropleth classification scheme (requires mapclassify).
A mapclassify.MapClassifier object will be used
under the hood. Supported are all schemes provided by mapclassify (e.g.
'BoxPlot', 'EqualInterval', 'FisherJenks', 'FisherJenksSampled',
'HeadTailBreaks', 'JenksCaspall', 'JenksCaspallForced',
'JenksCaspallSampled', 'MaxP', 'MaximumBreaks',
'NaturalBreaks', 'Quantiles', 'Percentiles', 'StdMean',
'UserDefined'). Arguments can be passed in classification_kwds.
color_k (Optional[int], optional): The number of classes to use for color encoding. Defaults to 5.
color_args (dict, optional): Additional keyword arguments that will be passed to assign_continuous_colors(). Defaults to {}.
open_args (dict, optional): Additional keyword arguments that will be passed to geopandas.read_file(). Defaults to {}.
map_args (dict, optional): Additional keyword arguments that will be passed to lonboard.Map. Defaults to {}.
**kwargs: Additional keyword arguments that will be passed to lonboard.Layer.from_geopandas()
Returns:
lonboard.Map: A lonboard Map object.
"""
from .deckgl import Map
m = Map(**map_args)
m.add_vector(
vector,
zoom_to_layer,
pickable,
color_column,
color_scheme,
color_map,
color_k,
color_args,
open_args,
**kwargs,
)
return m
def view_pmtiles(
url,
style=None,
name=None,
tooltip=True,
overlay=True,
control=True,
show=True,
zoom_to_layer=True,
map_args={},
**kwargs,
):
"""
Visualize PMTiles the map.
Args:
url (str): The URL of the PMTiles file.
style (str, optional): The CSS style to apply to the layer. Defaults to None.
See https://docs.mapbox.com/style-spec/reference/layers/ for more info.
name (str, optional): The name of the layer. Defaults to None.
tooltip (bool, optional): Whether to show a tooltip when hovering over the layer. Defaults to True.
overlay (bool, optional): Whether the layer should be added as an overlay. Defaults to True.
control (bool, optional): Whether to include the layer in the layer control. Defaults to True.
show (bool, optional): Whether the layer should be shown initially. Defaults to True.
zoom_to_layer (bool, optional): Whether to zoom to the layer extent. Defaults to True.
**kwargs: Additional keyword arguments to pass to the PMTilesLayer constructor.
Returns:
folium.Map: A folium Map object.
"""
from .foliumap import Map
m = Map(**map_args)
m.add_pmtiles(
url, style, name, tooltip, overlay, control, show, zoom_to_layer, **kwargs
)
return m
if _use_folium():
from .foliumap import *
else:
try:
from .leafmap import *
except Exception as e:
if _in_colab_shell():
print(
"Please restart Colab runtime after installation if you encounter any errors when importing leafmap."
)
else:
print(
"Please restart Jupyter kernel after installation if you encounter any errors when importing leafmap."
)
raise Exception(e)