Web maps#
WebMap renders pyramids rasters and vectors as MapLibre GL JS / deck.gl layers and exports the result as one
self-contained HTML page.
from digitalearth.web import WebMap
(
WebMap()
.basemap()
.choropleth(gdf, column="pop", name="Population")
.legend(title="People per km²")
.layer_control()
.set_title("Population, 2024", subtitle="Source: CBS")
.save("map.html")
)
The map frames itself on the data you gave it, so there is no center/zoom to work out by hand — pass them
only when you want a view of your own.
What this tier is for#
Thematic maps, 3-D layers, contours, and sharing the result as one file. It is deliberately not a peer of
the static tier for scientific field rendering: vector/flow fields, unstructured meshes and KDE have no native
MapLibre primitive and live in digitalearth.static and digitalearth.interactive.
Naming layers, and why the name matters#
py-maplibregl's layer switcher has no separate label: its JavaScript captions each row with the layer's id
and reads that same string back to toggle it. So a name= you pass becomes the layer's id, and that is what a
viewer reads in the switcher:
WebMap().basemap().choropleth(gdf, column="pop", name="Population").layer_control()
# the switcher shows: Population
Without a name a layer gets a generated id (fill-4), which is what the switcher would then show. A repeated
name is suffixed (Population-2) because two layers cannot share a MapLibre id. WebMap.layer_ids lists them,
and remove_layer(id) drops one.
The big-data path works the same way: past big_data_threshold features, points/polygons render a deck.gl
layer rather than one MapLibre style layer per feature, but the layer still owns a tree slot, so name= and
visible= are honoured and WebMap.layer_ids/remove_layer/set_visible/move_layer all reach it like any
other layer. (tiles_3d, whose tileset streams from a URL, is the one deck builder still off the tree.)
Drawing order#
Layers sit in three bands, and a later call cannot slip under an earlier band:
- basemaps —
basemap(),tiles()(add_underlay) - reference —
graticule()(add_reference) - data — everything else (
add_layer)
Within a band, layers keep the order you added them in. That is why .basemap().graticule() works: a
reference grid belongs over the ground and under the data, which neither end of a flat list can express.
A builder that draws several MapLibre layers — cluster (bubbles, counts, loose points) and graticule
(lines, degree labels) — appears once in layer_ids, under its main layer. remove_layer takes the whole
group; the layer switcher toggles only that main layer, because that is what py-maplibregl's control does.
Sharing a page safely#
- A keyed basemap puts its credential in the saved HTML. See Keyed basemaps — treat such a file as a secret.
- Values from your data are escaped before they reach the legend or the title, so a hostile attribute in a downloaded shapefile cannot inject markup into the page you share.
Time series#
timeslider(collection) gives a notebook an ipywidgets slider. A saved page has no kernel, so it gets a
step picker instead — the steps are labelled with the times you passed, because those labels become the layer
ids. save("out.gif") writes the steps as an animation, which needs a headless browser (Playwright or
Selenium); that is deliberately not part of digitalearth[web]. The method behind that suffix is
save_animation(path, fps=...).
How this tier spells a few things#
Three keywords are worth naming, because the word alone does not say which of two sizes it means: a marker's
visual size is size=, a label's font size is text_size=, and a frame rate is fps= — frames per second,
not seconds per frame. padding on set_bounds is a number of screen pixels here, where the two 2-D
tiers pad by a fraction of the frame's own span; a page is framed in pixels, so that is the only padding that
means anything on it.
digitalearth.web.map.WebMap
#
Bases: RasterMixin, VectorMixin, BigDataMixin, MeshMixin, ThreeDMixin, TemporalMixin, DecorationMixin, LegendMixin, ExportMixin, WebMapBase
Web map: pan/zoom (and 3-D) MapLibre + deck.gl layers built from pyramids data, shareable as HTML.
The web sibling of the static :class:~digitalearth.static.map.Map, the interactive
:class:~digitalearth.interactive.map.InteractiveMap and the true-3D
:class:~digitalearth.three_d.scene3d.Scene3D: raster/vector builders turn pyramids objects into
MapLibre/deck.gl layers (reprojected to the display CRS through pyramids first), register them as layers,
and render()/save() compose them into one maplibre widget / standalone HTML page. Needs the
optional web extra (pip install 'digitalearth[web]') only when a builder/render method is
actually called — importing this module works without it.
Examples:
- Importing and constructing needs no MapLibre engine:
- Layers register in draw order and the builders chain:
- With the
webextra installed, the map renders and saves, handing back the :class:pathlib.Pathit wrote. The path is compared by name rather than echoed, so the example reads the same on every platform (reprisPosixPathorWindowsPath):>>> import tempfile >>> from pathlib import Path >>> from pyramids.dataset import Dataset >>> from digitalearth.web import WebMap >>> dem = Dataset.read_file("examples/data/acc4000.tif") >>> with tempfile.TemporaryDirectory() as folder: ... written = WebMap().field(dem).basemap().save(Path(folder) / "map.html") ... (written.name, written.is_file()) ('map.html', True)
See Also
digitalearth.static.map.Map: the static matplotlib sibling of this scene. digitalearth.interactive.map.InteractiveMap: the interactive-2D (HoloViz) sibling. digitalearth.three_d.scene3d.Scene3D: the true-3D (PyVista) sibling.
Source code in src/digitalearth/web/map.py
layer_ids
property
#
The MapLibre ids of the data layers added so far, in draw order.
The registry used to be write-only: builders minted ids internally and nothing surfaced them, so a caller could not address a layer afterwards to hide, remove or switch it.
Returns:
| Type | Description |
|---|---|
list[str]
|
The layer ids, bottom first, as a new list: the order they were added in, except that a graticule, |
list[str]
|
which is drawn in the reference band beneath the data, is listed before every layer that is not a |
list[str]
|
graticule, whenever it was added. A layer the caller named carries that name as its id; an unnamed one |
list[str]
|
gets a generated id. A generated id counts the layers of its kind: a layer no longer takes a |
list[str]
|
second number for the MapLibre source beside it, because that source is named after the layer |
list[str]
|
(#296) rather than allocated next to it. |
Examples:
- Named and unnamed layers, in the order they were added:
- A graticule added last is listed first, because it is drawn beneath the data:
- A map with no data layers has no ids:
set_bounds(bounds=None, *, padding=0.0, padding_px=20, animate=False)
#
Frame the map on bounds, or on everything added so far.
Without this the view comes only from the center/zoom given to the constructor, so a map of
one country opened on the whole world unless the caller worked out a centre themselves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
Any | None
|
|
None
|
padding
|
float
|
Breathing room around the extent, as a fraction of its own span — |
0.0
|
padding_px
|
Any
|
MapLibre's own viewport padding passed to |
20
|
animate
|
bool
|
Whether the browser eases into the new view rather than jumping. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
The same map instance, so builder calls chain. |
Raises:
| Type | Description |
|---|---|
ValueError
|
when |
Examples:
- Frame on an explicit box:
Source code in src/digitalearth/web/core/base.py
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 | |
layer_control(*, layers=None, position='top-right', controls=None, theme='default', opacity=None, order=None)
#
Add a switcher so a viewer can turn the data layers on and off, dim them, and reorder them.
A map with a basemap, a choropleth and a point overlay had no way to look underneath — which is the
single most common thing anyone does with a web map. The switch lists the data layers by default:
basemaps are the ground, not something a viewer toggles — but naming "basemap" in controls=
opts them in as a basemap gallery (WB-14). The gallery opens on the first basemap and hides the
rest, so a viewer switches the ground from there. py-maplibregl's switcher is checkboxes rather than a
radio, so a viewer can re-show more than one at once; the page simply starts on a single ground.
The three keywords are the ones the Tier-2 contract declares and the interactive tier now answers to
as well — the layers to include, the position, the controls to expose — so the same call adds a layer
control on either tier (#264). What was layer_ids= here is layers=, the name that tier uses
for the same thing.
The manager widens past visibility (WB-8/WB-14), and most of the widening is declarative.
opacity= dims a layer and order= reorders the stack, each applied now — opacity
through :meth:~digitalearth.web.core.base.WebMapBase.replace_layer, which rewrites the layer's own
paint, and order through :meth:~digitalearth.web.core.base.WebMapBase.move_layer — so the saved page
draws the layers dimmed and in that order. The switcher itself stays a live page-side control
(py-maplibregl's LayerSwitcherControl), and controls=["visibility", "basemap"] adds the
basemap layers to it (WB-14) so the ground is switchable too. A live opacity slider or a
drag-to-reorder control would each need a browser-JS layer this tier does not ship (the X-2
limitation), so controls= still refuses "opacity" rather than accept a control it cannot
build — the inertness #242/#244 removed. So controls= selects the live switcher controls, while
opacity=/order= are a one-time transform baked into the page and recorded on the switcher's
furniture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layers
|
list | None
|
The layers to offer, by id, defaulting to every data layer added so far — that is,
:attr: |
None
|
position
|
str
|
One of the four corners in
:data: |
'top-right'
|
controls
|
list | None
|
Which controls to expose, from
:data: |
None
|
theme
|
str
|
|
'default'
|
opacity
|
dict | None
|
A mapping of layer id to opacity in |
None
|
order
|
list | None
|
The bottom-to-top draw order for the named layers, applied now through
:meth: |
None
|
Note
A row toggles exactly one MapLibre layer, because that is what py-maplibregl's control does.
Builders that draw more than one layer — cluster (bubbles, counts, loose points) and
graticule (lines, degree labels) — are listed once, under their main layer, so toggling a
cluster hides its bubbles while the count labels remain. remove_layer does take the whole
group. Hiding the parts together needs a control py-maplibregl does not ship.
Returns:
| Type | Description |
|---|---|
Self
|
The same map instance, so builder calls chain. |
Raises:
| Type | Description |
|---|---|
ValueError
|
when |
IndexError
|
when |
Examples:
- Two layers and a switch between them:
See Also
digitalearth.web.core.base.WebMapBase.layer_ids: the ids this offers by default. digitalearth.base.controls.resolved_controls: the shared control vocabulary.
Source code in src/digitalearth/web/decoration/decoration.py
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 | |
remove_layer(layer_id)
#
Drop a previously added layer from the map.
Building a WebMap was one-way: a mistake meant starting over, which in a notebook — where these
maps are built — is the normal workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str
|
An id from :attr: |
required |
Returns:
| Type | Description |
|---|---|
Self
|
The same map instance, so builder calls chain. |
Note
The colour key goes with the layer. A key is asked for by hanging a
:class:~digitalearth.base.spec.encoding.Guide on the layer's own color encoding
(:meth:~digitalearth.web.legends.legend.LegendMixin.legend), so removing the layer removes the
guide, and the panel — derived from the guides the live layers carry — is rebuilt without it. A
surviving layer that carries its own guide then shows its own key. Nothing has to be rebuilt by
hand, and no key describes a layer that is gone.
The running data extent is not like that, and is not cleared until the last layer goes. It is
a "most recent" accessor rather than a model of what is on the map, so after removing one layer
of several it still spans the removed one; call :meth:set_bounds if that matters.
:attr:last_legend and :attr:last_breaks are "most recent" accessors too — that is what they
are for — but they no longer decide what is drawn: both are handed to the most recent
surviving classification here, together, so neither describes a removed layer and the two
cannot answer for different layers (review L7); the key is drawn from the guides regardless.
The id is not one of those either: it goes back to the pool, so a name removed and asked for
again is handed back unsuffixed. That is the lifetime all four tiers share —
:func:~digitalearth.base.spec.layer.free_layer_id states it.
Raises:
| Type | Description |
|---|---|
KeyError
|
when no such layer was added, listing the ids that were — a silent no-op here would look exactly like a layer that refused to go away. |
Examples:
- Remove one layer; the map is returned, so calls chain:
- An id that was never added is refused, naming the ids that were:
Source code in src/digitalearth/web/core/base.py
2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 | |
legend(*, layer_id=None, title=None, position=DEFAULT_KEY_ANCHOR, labels=None, visible=True)
#
Add a key for a classified layer (recipe W2).
A thematic map is unreadable without one, and until this the tier drew the classes and left the
caller to build a key out of band from last_breaks. The classification records what it actually
coloured with (:attr:~digitalearth.web.core.base.WebMapBase.last_legend), so the key shows the rendered
colours rather than a second guess at them.
The three shapes a classification can take are all handled: a categorical one gets a swatch per category, a graduated one a swatch per class with its range, and a continuous ramp a gradient bar with its end values.
The key belongs to the layer, not to the map (DE-48, order 24). What this call records is a
:class:~digitalearth.base.spec.encoding.Guide on the layer's color
:class:~digitalearth.base.spec.encoding.Encoding — show, the heading, and the corner — and the
panel is derived from the guides the live layers carry, every time the layers change. So the key
moves, hides and disappears with the layer it describes: remove the layer and the key goes, hide it
and the key goes, show it again and the key comes back. It also travels: a guide survives
FigureSpec being written and read back, which a panel built once never did.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id
|
str | None
|
Which layer's classes to describe. |
None
|
title
|
str | None
|
Heading above the key. |
None
|
position
|
str
|
One of the four MapLibre corners. Recorded as the guide's |
DEFAULT_KEY_ANCHOR
|
labels
|
list | None
|
Explicit row labels, replacing the derived ones — for units, or for renaming categories. Ignored for a continuous ramp, which has no rows. Recorded on the layer beside its guide, so a key rebuilt after another layer is removed still carries them. |
None
|
visible
|
bool
|
|
True
|
Returns:
| Type | Description |
|---|---|
Self
|
The same map instance, so builder calls chain. |
Raises:
| Type | Description |
|---|---|
ValueError
|
when |
KeyError
|
when |
TypeError
|
when |
Note
This tier draws one key, and the four tiers differ here. _panels holds one entry per
kind, so a second legend replaces the first rather than stacking an identical box in the same
corner. Layers may each carry a guide all the same, and when several do the topmost visible
one wins — draw order decides, not call order. So keying a lower layer after a higher one
leaves the higher one's key drawn; take the higher one's off with
legend(layer_id=<higher>, visible=False) first. The static tier has no such limit
(matplotlib takes any number of colorbars) and neither does the interactive tier (its guides are
per-layer options); the 3-D tier has one scalar-bar slot per title.
A guide on a hidden layer is recorded and draws nothing until the layer is shown, which is the same rule stated from the other side: the key is drawn while the layer is.
Examples:
- A choropleth and its key:
See Also
digitalearth.web.builders.vector.VectorMixin.choropleth: the builder whose classes this describes. digitalearth.web.decoration.decoration.refresh_legend_panel: derives the panel from the recorded guides.
Source code in src/digitalearth/web/legends/legend.py
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 | |
set_title(heading, *, position='top-left', subtitle=None)
#
Put a title on the map itself, so a saved page carries its own heading.
An exported page travels alone: whatever context the notebook around it had is gone. The title is a control rather than a layer, so it sits above the map and moves with the corner it is pinned to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
heading
|
str
|
The title text. |
required |
position
|
str
|
One of the four MapLibre corners. |
'top-left'
|
subtitle
|
str | None
|
A smaller second line — a date, a source, a unit. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The same map instance, so builder calls chain. |
Raises:
| Type | Description |
|---|---|
ValueError
|
when |
Examples:
- Title a saved map:
Source code in src/digitalearth/web/decoration/decoration.py
text(lon, lat, s=None, *, crs=4326, text_size=14.0, color='#ffffff', halo_color='#000000', halo_width=1.0, name=None)
#
Place a single line of text at a coordinate.
The "label this spot" case, which needed a whole GeoDataFrame before —
:meth:~digitalearth.web.builders.vector.VectorMixin.labels is the data-driven counterpart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lon
|
float
|
X of the anchor point, in |
required |
lat
|
float
|
Y of the anchor point, in |
required |
s
|
str | None
|
The string to draw. Named |
None
|
crs
|
Any
|
What |
4326
|
text_size
|
float
|
Text size in pixels. Named for the text rather than |
14.0
|
color
|
str
|
Text colour. |
'#ffffff'
|
halo_color
|
str
|
Colour of the outline behind the glyphs, which keeps it legible over imagery. |
'#000000'
|
halo_width
|
float
|
Halo width in pixels; |
1.0
|
name
|
str | None
|
What a layer switcher calls this annotation; |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The same map instance, so builder calls chain. |
Raises:
| Type | Description |
|---|---|
TypeError
|
when the string to draw is not given. |
ValueError
|
when |
Examples:
- Mark a place:
See Also
digitalearth.web.builders.vector.VectorMixin.labels: label many features from a column.
Source code in src/digitalearth/web/decoration/decoration.py
1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 | |
labels(features, column, *, text_size=DEFAULT_LABEL_TEXT_SIZE, color=UNSET, halo_color=DEFAULT_LABEL_HALO_COLOR, halo_width=DEFAULT_LABEL_HALO_WIDTH, offset=None, allow_overlap=False, crs=None, name=None, visible=True)
#
Label features with the text in column (recipe W2).
Labels are how a map says what is on it, and MapLibre's symbol layer does the work — data-driven
text, collision detection, halos and placement. None of it was reachable: the only symbol layer the
tier built was the count inside cluster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Any
|
A pyramids |
required |
column
|
str
|
The property to read the text from. |
required |
text_size
|
float
|
Text size in pixels. Named for the text rather than |
DEFAULT_LABEL_TEXT_SIZE
|
color
|
Maybe[str]
|
Text colour; not passed leaves
:data: |
UNSET
|
halo_color
|
str
|
Colour of the outline drawn behind the glyphs, which is what keeps a label legible over imagery. |
DEFAULT_LABEL_HALO_COLOR
|
halo_width
|
float
|
Halo width in pixels; |
DEFAULT_LABEL_HALO_WIDTH
|
offset
|
Any | None
|
|
None
|
allow_overlap
|
bool
|
Whether labels may overlap. |
False
|
crs
|
Any
|
The CRS the features are in when they carry none themselves — used to place a frame that
has no CRS, which would otherwise be taken as lon/lat (EPSG:4326). |
None
|
name
|
str | None
|
What a layer switcher calls this layer; |
None
|
visible
|
bool
|
Whether the layer starts visible, which is what a layer switcher toggles. |
True
|
Returns:
| Type | Description |
|---|---|
Self
|
The same map instance, so builder calls chain. |
Raises:
| Type | Description |
|---|---|
TypeError
|
when |
KeyError
|
when |
ValueError
|
when |
FileNotFoundError
|
when |
Examples:
- Name each feature:
See Also
digitalearth.web.decoration.decoration.DecorationMixin.text: a single annotation at a coordinate.
Source code in src/digitalearth/web/builders/vector.py
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 | |
graticule(*, lon_step=None, lat_step=None, spacing=None, color='#888888', width=0.5, opacity=UNSET, labels=True, name=None, visible=True)
#
Draw a lat/lon grid over the map.
A graticule is a property of the map, not of a tile service — no basemap provides one, so this tier
had no way to show one at all. The lines are ordinary GeoJSON, so they embed in the page and a map
saved with offline=True keeps its grid with no network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lon_step
|
float | None
|
Degrees between meridians; |
None
|
lat_step
|
float | None
|
Degrees between parallels; |
None
|
spacing
|
float | None
|
One step for both, for a caller who wants a square grid; it overrides the two above.
|
None
|
color
|
str
|
Line colour. |
'#888888'
|
width
|
float
|
Line width in pixels. |
0.5
|
opacity
|
Maybe[float]
|
Line opacity in |
UNSET
|
labels
|
bool
|
Whether to label each line with its degree value at the map's edge. It also decides
whether the |
True
|
name
|
str | None
|
What a layer switcher calls this layer; |
None
|
visible
|
bool
|
Whether the layer starts visible, which is what a layer switcher toggles. |
True
|
Returns:
| Type | Description |
|---|---|
Self
|
The same map instance, so builder calls chain. |
Raises:
| Type | Description |
|---|---|
ValueError
|
when |
Examples:
- A 10° grid under the data:
Source code in src/digitalearth/web/decoration/decoration.py
1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 | |
contours(dataset, *, interval=None, levels=None, band=DEFAULT_BAND, filled=False, cmap=None, units=None, color=None, width=UNSET, opacity=UNSET, labels=False, name=None, visible=True)
#
Trace iso-value contours from a raster band and draw them as vectors.
The GIS is pyramids' (Dataset.contour, the gdal_contour equivalent); this only draws what
it returns. Contours are the one field type that maps cleanly onto MapLibre — the result is a
FeatureCollection, which the tier already knows how to render — so it is the field renderer
this tier can honestly offer. Vector fields and meshes have no native primitive here; see the
static and interactive tiers for those.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Any
|
A pyramids |
required |
interval
|
float | ContourInterval | None
|
Spacing between levels — a number for "one every N", or a
:class: |
None
|
levels
|
Any | None
|
Explicit levels to contour. Give at most one of this or |
None
|
band
|
int
|
1-based band to contour, matching
:meth: |
DEFAULT_BAND
|
filled
|
bool
|
Draw filled bands between successive levels instead of lines. |
False
|
cmap
|
str | None
|
Colormap for colouring by level; |
None
|
units
|
str | None
|
What the contoured values are measured in, which the key names in parentheses after the
column — when this layer makes a key at all. An explicit |
None
|
color
|
str | None
|
A single colour for every contour, overriding |
None
|
width
|
Maybe[float]
|
Line width in pixels; ignored when |
UNSET
|
opacity
|
Maybe[float]
|
Layer opacity in |
UNSET
|
labels
|
bool
|
Whether to label each contour with its value — the level for a line, the band's lower
edge when |
False
|
name
|
str | None
|
What a layer switcher calls this layer; |
None
|
visible
|
bool
|
Whether the layer starts visible. |
True
|
Returns:
| Type | Description |
|---|---|
Self
|
The same map instance, so builder calls chain. |
Raises:
| Type | Description |
|---|---|
ValueError
|
when both |
TypeError
|
when |
FileNotFoundError
|
when |
Examples:
- Contour a DEM every 100 m:
See Also
digitalearth.web.builders.vector.VectorMixin.lines: what the traced contours are drawn as. digitalearth.base.autostyle.auto_style: supplies the levels, colormap and units.
Source code in src/digitalearth/web/builders/vector.py
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 | |
rgb_composite(dataset, bands=DEFAULT_COMPOSITE_BANDS, *, mask_nodata=True, limits=None, opacity=UNSET, visible=True, name=None, tiles=None)
#
Overlay three bands as a true- or false-colour image (recipe W1).
Satellite imagery is a headline use of a web map, and the tier could only draw one band through a
colormap. The stretch comes from :mod:digitalearth.base.stretch — the same engine-neutral code
the static tier's rgb_composite uses — so the same three bands look the same on both tiers.
The three channels are read straight as red, green and blue; :meth:hsv_composite reads the same
three as hue, saturation and value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Any
|
A pyramids |
required |
bands
|
Any
|
The three 1-based band numbers, in red-green-blue order. |
DEFAULT_COMPOSITE_BANDS
|
mask_nodata
|
bool
|
Whether NoData becomes NaN (and so transparent) rather than a real value. |
True
|
limits
|
Any | None
|
Per-channel |
None
|
opacity
|
Maybe[float]
|
Raster layer opacity in |
UNSET
|
visible
|
bool
|
Whether the layer starts visible, which is what a layer switcher toggles. |
True
|
name
|
str | None
|
What a layer switcher calls this layer; |
None
|
tiles
|
TileRoute | None
|
How the pixels reach the page, as on :meth: |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The same map instance, so builder calls chain. A composite that cannot be placed — off-limb |
Self
|
in the display CRS, or with corners that will not express as lon/lat — is skipped with a |
Self
|
warning instead, unless the map was built with |
Raises:
| Type | Description |
|---|---|
ValueError
|
when |
FileNotFoundError
|
when |
TypeError
|
for a tiled route, when |
Examples:
- A true-colour composite from a Landsat-ordered dataset:
See Also
digitalearth.web.builders.raster.RasterMixin.hsv_composite: the same three bands read as hue/sat/value.
digitalearth.base.stretch.channel_limits: derives the limits this accepts.
digitalearth.web.builders.raster.RasterMixin.field: the single-band, colormapped path.
Source code in src/digitalearth/web/builders/raster.py
1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 | |
save_animation(path, *, fps=DEFAULT_FPS, loop=0, title=DEFAULT_TITLE, format=None)
#
Write a temporal map's steps as an animated GIF or an MP4 video (recipe W7).
A time series is the case where a moving image says most, and it is also the case a web page
carries worst — a saved page shows a step picker, not an animation, and nothing could be pasted
into a report. The other two tiers have had save_animation all along.
One frame is rendered per time step, by making that step the only visible one and screenshotting
the page, so the frames are the same pixels the map draws. That frame pipeline is shared by both
output kinds; only the encoder differs — a GIF is written by Pillow, an MP4 by ffmpeg (via
imageio-ffmpeg).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Where to write the animation. The suffix picks the encoder when |
required |
fps
|
float
|
Frames per second — the rate every tier's animation entry point takes, with the same
default (:data: |
DEFAULT_FPS
|
loop
|
int
|
How many times to repeat; |
0
|
title
|
str
|
HTML document title used while rendering. |
DEFAULT_TITLE
|
format
|
str | None
|
Force the encoder — |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
The |
Path
|
class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
when the map has no time steps to animate, or fewer than two; when |
ImportError
|
when no headless browser is installed — the same gated dependency the PNG snapshot
needs, deliberately not part of |
Examples:
- Animate a raster stack to a GIF, or to an MP4 by changing the suffix:
>>> from digitalearth.web import WebMap # doctest: +SKIP >>> from pyramids.dataset.collection import DatasetCollection # doctest: +SKIP >>> stack = DatasetCollection.from_files(["jan.tif", "feb.tif"]) # doctest: +SKIP >>> WebMap().basemap().timeslider(stack).save_animation("out.gif") # doctest: +SKIP >>> WebMap().basemap().timeslider(stack).save_animation("out.mp4") # doctest: +SKIP
See Also
digitalearth.web.temporal.temporal.TemporalMixin.timeslider: builds the steps this animates.
Source code in src/digitalearth/web/output/export.py
284 285 286 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 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 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 367 368 369 | |