0
# Data Visualization
1
2
Comprehensive data visualization capabilities for vector and raster data with support for various formats including shapefiles, GeoJSON, COG, STAC, NetCDF, and online data sources.
3
4
## Capabilities
5
6
### Vector Data Visualization
7
8
Display and style vector data from files, GeoDataFrames, and online sources with comprehensive styling and interaction options.
9
10
```python { .api }
11
def add_vector(self, filename, layer_name='Untitled', **kwargs):
12
"""
13
Add vector data to the map.
14
15
Args:
16
filename (str): Path to vector file or URL
17
layer_name (str): Display name for the layer
18
**kwargs: Styling options (style, hover_style, popup, etc.)
19
"""
20
21
def add_geojson(self, data, layer_name='Untitled', **kwargs):
22
"""
23
Add GeoJSON data to the map.
24
25
Args:
26
data (dict or str): GeoJSON data or file path
27
layer_name (str): Display name for the layer
28
**kwargs: Styling options
29
"""
30
31
def add_gdf(self, gdf, layer_name='Untitled', **kwargs):
32
"""
33
Add GeoDataFrame to the map.
34
35
Args:
36
gdf (gpd.GeoDataFrame): GeoDataFrame to display
37
layer_name (str): Display name for the layer
38
**kwargs: Styling options
39
"""
40
41
def add_shp(self, shp, layer_name='Untitled', **kwargs):
42
"""
43
Add shapefile to the map.
44
45
Args:
46
shp (str): Path to shapefile
47
layer_name (str): Display name for the layer
48
**kwargs: Styling options
49
"""
50
51
def add_kml(self, kml, layer_name='Untitled', **kwargs):
52
"""
53
Add KML file to the map.
54
55
Args:
56
kml (str): Path to KML file
57
layer_name (str): Display name for the layer
58
**kwargs: Styling options
59
"""
60
```
61
62
### Raster Data Visualization
63
64
Display raster data with customizable colormaps, value ranges, and transparency settings supporting various formats and online sources.
65
66
```python { .api }
67
def add_raster(self, image, colormap=None, vmin=None, vmax=None, **kwargs):
68
"""
69
Add raster data to the map.
70
71
Args:
72
image (str): Path to raster file
73
colormap (str): Matplotlib colormap name
74
vmin (float): Minimum value for color mapping
75
vmax (float): Maximum value for color mapping
76
**kwargs: Additional raster options (opacity, layer_name, etc.)
77
"""
78
79
def add_cog_layer(self, url, name='Untitled', **kwargs):
80
"""
81
Add Cloud Optimized GeoTIFF layer.
82
83
Args:
84
url (str): URL to COG file
85
name (str): Layer name
86
**kwargs: COG visualization options (bands, colormap, rescale, etc.)
87
"""
88
89
def add_stac_layer(self, url, collection=None, item=None, **kwargs):
90
"""
91
Add STAC (SpatioTemporal Asset Catalog) layer.
92
93
Args:
94
url (str): STAC URL or item URL
95
collection (str): STAC collection ID
96
item (str): STAC item ID
97
**kwargs: STAC layer options (assets, bands, etc.)
98
"""
99
100
def add_netcdf(self, filename, variables=None, **kwargs):
101
"""
102
Add NetCDF data to the map.
103
104
Args:
105
filename (str): Path to NetCDF file
106
variables (list): Variables to display
107
**kwargs: NetCDF visualization options
108
"""
109
```
110
111
### Heatmaps and Point Data
112
113
Create heatmaps and visualize point data with various marker styles and clustering options.
114
115
```python { .api }
116
def add_heatmap(self, data, latitude='latitude', longitude='longitude', **kwargs):
117
"""
118
Add heatmap layer from point data.
119
120
Args:
121
data: DataFrame or list of points
122
latitude (str): Column name for latitude values
123
longitude (str): Column name for longitude values
124
**kwargs: Heatmap options (radius, blur, max_zoom, etc.)
125
"""
126
127
def add_markers(self, markers, **kwargs):
128
"""
129
Add point markers to the map.
130
131
Args:
132
markers (list): List of [lat, lon] coordinates or marker objects
133
**kwargs: Marker styling (popup, tooltip, icon, etc.)
134
"""
135
136
def add_circle_markers_from_xy(self, data, x='longitude', y='latitude', **kwargs):
137
"""
138
Add circle markers from coordinate data.
139
140
Args:
141
data: DataFrame with coordinate columns
142
x (str): Column name for x/longitude coordinates
143
y (str): Column name for y/latitude coordinates
144
**kwargs: Circle marker options (radius, color, weight, etc.)
145
"""
146
147
def add_points_from_xy(self, data, x='longitude', y='latitude', **kwargs):
148
"""
149
Add point markers from coordinate data.
150
151
Args:
152
data: DataFrame with coordinate columns
153
x (str): Column name for x/longitude coordinates
154
y (str): Column name for y/latitude coordinates
155
**kwargs: Point styling options
156
"""
157
```
158
159
### Specialized Data Sources
160
161
Integration with specialized geospatial data sources and services.
162
163
```python { .api }
164
def add_census_data(self, dataset='states', layer_name='Census Data', **kwargs):
165
"""
166
Add US Census data to the map.
167
168
Args:
169
dataset (str): Census dataset name ('states', 'counties', etc.)
170
layer_name (str): Layer name for display
171
**kwargs: Census data options (year, variables, etc.)
172
"""
173
174
def add_nlcd(self, year=2019, region='conus', **kwargs):
175
"""
176
Add National Land Cover Database data.
177
178
Args:
179
year (int): NLCD data year
180
region (str): Geographic region ('conus', 'alaska', 'hawaii', 'pr')
181
**kwargs: NLCD visualization options
182
"""
183
184
def add_nwi(self, layer_name='NWI', **kwargs):
185
"""
186
Add National Wetlands Inventory data.
187
188
Args:
189
layer_name (str): Layer name for display
190
**kwargs: NWI layer options
191
"""
192
193
def add_overture_data(self, bbox, theme, **kwargs):
194
"""
195
Add Overture Maps data.
196
197
Args:
198
bbox (list): Bounding box [minx, miny, maxx, maxy]
199
theme (str): Overture theme ('buildings', 'transportation', etc.)
200
**kwargs: Overture data options
201
"""
202
```
203
204
### 3D Visualization (MapLibre GL JS Backend)
205
206
Advanced 3D visualization capabilities available with the MapLibre GL JS backend.
207
208
```python { .api }
209
def add_3d_terrain(self, source=None, **kwargs):
210
"""
211
Add 3D terrain visualization.
212
213
Args:
214
source: Terrain data source
215
**kwargs: 3D terrain options (exaggeration, etc.)
216
"""
217
218
def add_sky_layer(self, **kwargs):
219
"""
220
Add atmospheric sky layer for 3D scenes.
221
222
Args:
223
**kwargs: Sky layer options (sun_position, etc.)
224
"""
225
226
def add_3d_model(self, model_url, coordinates, **kwargs):
227
"""
228
Add 3D model to the map.
229
230
Args:
231
model_url (str): URL to 3D model file
232
coordinates (list): [longitude, latitude, altitude]
233
**kwargs: 3D model options (scale, rotation, etc.)
234
"""
235
```
236
237
### Image Comparison and Analysis
238
239
Tools for comparing and analyzing imagery with interactive features.
240
241
```python { .api }
242
def image_comparison(self, img1, img2, **kwargs):
243
"""
244
Create side-by-side image comparison.
245
246
Args:
247
img1 (str): Path to first image
248
img2 (str): Path to second image
249
**kwargs: Comparison options (labels, etc.)
250
"""
251
252
def create_timelapse(self, images, **kwargs):
253
"""
254
Create animated timelapse from image series.
255
256
Args:
257
images (list): List of image paths or URLs
258
**kwargs: Timelapse options (fps, loop, etc.)
259
"""
260
261
def add_time_slider(self, layers, **kwargs):
262
"""
263
Add time slider control for temporal data.
264
265
Args:
266
layers (list): List of time-series layers
267
**kwargs: Time slider options
268
"""
269
```
270
271
## Styling Options
272
273
### Vector Styling
274
275
```python { .api }
276
# Style dictionary for vector data
277
vector_style = {
278
'stroke': True, # Draw stroke
279
'color': '#3388ff', # Stroke color
280
'weight': 3, # Stroke width
281
'opacity': 1.0, # Stroke opacity
282
'fill': True, # Fill polygons
283
'fillColor': '#3388ff', # Fill color
284
'fillOpacity': 0.2, # Fill opacity
285
'dashArray': None, # Dash pattern
286
'lineCap': 'round', # Line cap style
287
'lineJoin': 'round' # Line join style
288
}
289
290
# Hover style
291
hover_style = {
292
'weight': 5,
293
'fillOpacity': 0.5
294
}
295
```
296
297
### Raster Styling
298
299
```python { .api }
300
# Colormap options
301
colormaps = [
302
'viridis', 'plasma', 'inferno', 'magma', # Perceptually uniform
303
'terrain', 'gist_earth', 'ocean', # Earth/geographic
304
'hot', 'cool', 'spring', 'summer', # Temperature
305
'jet', 'rainbow', 'hsv' # Classic
306
]
307
308
# Raster display options
309
raster_options = {
310
'opacity': 0.8, # Layer opacity
311
'colormap': 'viridis', # Color mapping
312
'vmin': 0, # Minimum value
313
'vmax': 100, # Maximum value
314
'nodata': -9999, # NoData value
315
'layer_name': 'Raster' # Display name
316
}
317
```
318
319
## Usage Examples
320
321
### Vector Data Visualization
322
323
```python
324
import leafmap
325
326
# Create map
327
m = leafmap.Map(center=[40, -100], zoom=4)
328
329
# Add shapefile with custom styling
330
style = {
331
'color': 'red',
332
'weight': 2,
333
'fillColor': 'yellow',
334
'fillOpacity': 0.3
335
}
336
337
m.add_vector('path/to/data.shp',
338
layer_name='Custom Layer',
339
style=style)
340
341
# Add GeoJSON with popup
342
m.add_geojson('data.geojson',
343
layer_name='GeoJSON Layer',
344
popup=['name', 'value'])
345
346
m
347
```
348
349
### Raster Data Visualization
350
351
```python
352
import leafmap
353
354
# Create map
355
m = leafmap.Map()
356
357
# Add raster with custom colormap
358
m.add_raster('elevation.tif',
359
colormap='terrain',
360
vmin=0,
361
vmax=4000,
362
layer_name='Elevation',
363
opacity=0.7)
364
365
# Add COG from URL
366
m.add_cog_layer('https://example.com/data.tif',
367
name='Remote COG',
368
rescale='0,255',
369
colormap='viridis')
370
371
m
372
```
373
374
### Heatmap Creation
375
376
```python
377
import leafmap
378
import pandas as pd
379
380
# Load point data
381
df = pd.read_csv('points.csv')
382
383
# Create map
384
m = leafmap.Map()
385
386
# Add heatmap
387
m.add_heatmap(df,
388
latitude='lat',
389
longitude='lon',
390
radius=15,
391
blur=10,
392
max_zoom=18)
393
394
m
395
```
396
397
## Data Format Support
398
399
### Vector Formats
400
- Shapefile (.shp)
401
- GeoJSON (.geojson, .json)
402
- KML/KMZ (.kml, .kmz)
403
- GeoPackage (.gpkg)
404
- GML (.gml)
405
- PostGIS (via connection string)
406
407
### Raster Formats
408
- GeoTIFF (.tif, .tiff)
409
- Cloud Optimized GeoTIFF (COG)
410
- NetCDF (.nc, .nc4)
411
- HDF5 (.h5, .hdf5)
412
- JPEG2000 (.jp2)
413
- PNG (.png)
414
- JPEG (.jpg, .jpeg)
415
416
### Online Sources
417
- STAC catalogs and items
418
- WMS/WMTS services
419
- XYZ tile services
420
- PMTiles archives
421
- S3/cloud storage URLs