HeatmapLayer¶

Screenshot from DuckDB Spatial example
lonboard.HeatmapLayer ¶
Bases: BaseArrowLayer
The HeatmapLayer visualizes the spatial distribution of data.
Example
From GeoPandas:
import geopandas as gpd
from lonboard import Map, HeatmapLayer
# A GeoDataFrame with Point geometries
gdf = gpd.GeoDataFrame()
layer = HeatmapLayer.from_geopandas(gdf)
m = Map(layer)
From an Arrow-compatible source like pyogrio or geoarrow-rust:
from geoarrow.rust.io import read_flatgeobuf
from lonboard import Map, HeatmapLayer
# Example: A FlatGeobuf file with Point geometries
table = read_flatgeobuf("path/to/file.fgb")
layer = HeatmapLayer(
table,
get_fill_color=[255, 0, 0],
)
m = Map(layer)
aggregation
class-attribute
instance-attribute
¶
aggregation = tag(sync=True)
Defines the type of aggregation operation
Valid values are 'SUM', 'MEAN'.
- Type:
str, optional - Default:
"SUM"
auto_highlight
class-attribute
instance-attribute
¶
auto_highlight = tag(sync=True)
When true, the current object pointed to by the mouse pointer (when hovered over) is
highlighted with highlightColor.
Requires pickable to be True.
- Type:
bool - Default:
False
before_id
class-attribute
instance-attribute
¶
before_id = tag(sync=True)
The identifier of a layer in the Maplibre basemap layer stack.
This deck.gl layer will be rendered just before the layer with the given identifier. You can find such an identifier by inspecting the basemap style JSON.
For example, in the Carto Positron style, if
you look at the raw JSON
data, each layer has
an "id" property. The first layer in the basemap stack has "id": "background".
So if you pass before_id="background", you won't see your deck.gl layer because it
will be rendered below all layers in the Maplibre basemap.
A common choice for Carto-based styles is to use before_id="watername_ocean" so
that your deck.gl layer is rendered above the core basemap elements but below all
text labels.
Info
This only has an effect when the map's basemap is a
MaplibreBasemap, and the map is rendering
in "interleaved" mode.
debounce_timeout
class-attribute
instance-attribute
¶
debounce_timeout = tag(sync=True)
Interval in milliseconds during which changes to the viewport don't trigger aggregation.
- Type:
int, optional - Default:
500
extensions
class-attribute
instance-attribute
¶
extensions = tag(sync=True, **(widget_serialization))
A list of layer extension objects to add additional features to a layer.
get_weight
class-attribute
instance-attribute
¶
get_weight = FloatAccessor(None, allow_none=True)
The weight of each object.
- Type: FloatAccessor, optional
- If a number is provided, it is used as the weight for all objects.
- If an array is provided, each value in the array will be used as the weight for the object at the same row index.
- Default:
1.
highlight_color
class-attribute
instance-attribute
¶
highlight_color = VariableLengthTuple(
Int(), default_value=None, minlen=3, maxlen=4
)
RGBA color to blend with the highlighted object (the hovered over object if
auto_highlight=true). When the value is a 3 component (RGB) array, a default alpha
of 255 is applied.
- Type: List or Tuple of integers
- Default:
[0, 0, 128, 128]
intensity
class-attribute
instance-attribute
¶
intensity = tag(sync=True)
Value that is multiplied with the total weight at a pixel to obtain the final weight.
- Type:
float, optional - Default:
1
opacity
class-attribute
instance-attribute
¶
opacity = tag(sync=True)
The opacity of the layer.
- Type:
float. Must range between 0 and 1. - Default:
1
pickable
class-attribute
instance-attribute
¶
pickable = tag(sync=True)
Whether the layer responds to mouse pointer picking events.
This must be set to True for tooltips and other interactive elements to be
available. This can also be used to only allow picking on specific layers within a
map instance.
Note that picking has some performance overhead in rendering. To get the absolute
best rendering performance with large data (at the cost of removing interactivity),
set this to False.
- Type:
bool - Default:
True
radius_pixels
class-attribute
instance-attribute
¶
radius_pixels = tag(sync=True)
Radius of the circle in pixels, to which the weight of an object is distributed.
- Type:
float, optional - Default:
30
selected_index
class-attribute
instance-attribute
¶
selected_index = tag(sync=True)
The positional index of the most-recently clicked on row of data.
You can use this to access the full row of data from a GeoDataFrame
gdf.iloc[layer.selected_index]
Setting a value here from Python will do nothing. This attribute only exists to be
updated from JavaScript on a map click. Note that pickable must be True (the
default) on this layer for the JavaScript onClick handler to work; if pickable
is set to False, selected_index will never update.
Note that you can use observe to call a function whenever a new value is received
from JavaScript. Refer
here
for an example.
table
class-attribute
instance-attribute
¶
table = ArrowTableTrait(allowed_geometry_types={POINT})
A GeoArrow table with a Point column.
This is the fastest way to plot data from an existing GeoArrow source, such as geoarrow-rust or geoarrow-pyarrow.
If you have a GeoPandas GeoDataFrame, use
from_geopandas instead.
threshold
class-attribute
instance-attribute
¶
threshold = tag(sync=True)
Ratio of the fading weight to the max weight, between 0 and 1.
For example, 0.1 affects all pixels with weight under 10% of the max.
Ignored when color_domain is specified.
- Type:
float, optional - Default:
0.05
visible
class-attribute
instance-attribute
¶
visible = tag(sync=True)
Whether the layer is visible.
Under most circumstances, using the visible attribute to control the visibility of
layers is recommended over removing/adding the layer from the Map.layers list.
In particular, toggling the visible attribute will persist the layer on the
JavaScript side, while removing/adding the layer from the Map.layers list will
re-download and re-render from scratch.
- Type:
bool - Default:
True
weights_texture_size
class-attribute
instance-attribute
¶
weights_texture_size = tag(sync=True)
Specifies the size of weight texture.
- Type:
int, optional - Default:
2048
__init__ ¶
__init__(
table: ArrowStreamExportable, **kwargs: Unpack[HeatmapLayerKwargs]
) -> None
Construct a Layer from a GeoArrow table.
This accepts Arrow data from any library implementing the Arrow PyCapsule Interface, including pyarrow, arro3, DuckDB, and others.
The geometry column will be reprojected to EPSG:4326 if it is not already in
that coordinate system.
Parameters:
-
table(ArrowStreamExportable) –An Arrow table or stream object from a library implementing the [Arrow PyCapsule Interface]. This object must contain a column with a geometry type that has the
geoarrowextension metadata.
Other Parameters:
-
kwargs(Unpack[BaseLayerKwargs]) –parameters passed on to
__init__
Returns:
-
None–A Layer with the initialized data.
from_duckdb
classmethod
¶
from_duckdb(
sql: str | DuckDBPyRelation,
con: DuckDBPyConnection | None = None,
*,
crs: str | CRS | None = None,
**kwargs: Unpack[HeatmapLayerKwargs]
) -> Self
Construct a Layer from a duckdb-spatial query.
DuckDB Spatial does not currently expose coordinate reference system
information, so the user must ensure that data has been reprojected to
EPSG:4326 or pass in the existing CRS of the data in the crs keyword
parameter.
Parameters:
-
sql(str | DuckDBPyRelation) –The SQL input to visualize. This can either be a string containing a SQL query or the output of the duckdb
sqlfunction. -
con(DuckDBPyConnection | None, default:None) –The current DuckDB connection. This is required when passing a
strto thesqlparameter.
Other Parameters:
-
crs(str | CRS | None) –The CRS of the input data. This can either be a string passed to
pyproj.CRS.from_user_inputor apyproj.CRSobject. Defaults to None. -
kwargs(Unpack[BaseLayerKwargs]) –parameters passed on to
__init__
Returns:
-
Self–A Layer with the initialized data.
from_geopandas
classmethod
¶
from_geopandas(
gdf: GeoDataFrame,
*,
auto_downcast: bool = True,
**kwargs: Unpack[HeatmapLayerKwargs]
) -> Self
Construct a Layer from a geopandas GeoDataFrame.
The GeoDataFrame will be reprojected to EPSG:4326 if it is not already in that
coordinate system.
Parameters:
-
gdf(GeoDataFrame) –The GeoDataFrame to set on the layer.
Other Parameters:
-
auto_downcast(bool) –If
True, automatically downcast to smaller-size data types if possible without loss of precision. This calls pandas.DataFrame.convert_dtypes and pandas.to_numeric under the hood. -
kwargs(Unpack[BaseLayerKwargs]) –parameters passed on to
__init__
Returns:
-
Self–A Layer with the initialized data.