GeoFrame.Kino (GeoFrame v0.3.4)

Copy Markdown View Source

Livebook rendering for GeoFrame.GeoDataFrame and GeoFrame.GeoSeries.

This module is compiled only when :kino is available. Rendering a frame (the last expression of a cell) shows three tabs: Map, Table and Inspect; a series shows Map and Inspect. For large inputs deck/2 builds a deck.gl widget (GeoFrame.Kino.Deck), and two Smart Cells, GeoFrame.Kino.ReadFileCell ("Read spatial file") and GeoFrame.Kino.SpatialJoinCell ("Spatial join"), are registered when the :geoframe application starts with Kino present.

Map

The map needs the optional :kino_maplibre and :maplibre packages. Without them the Map tab explains how to add them and the other tabs still work.

Data is sent to the browser as one GeoJSON source and styled by geometry kind: polygons are filled with an outline, lines are stroked, points are circles. A GeometryCollection is drawn by decomposing it into its members (nested collections included), one feature per member; every feature carries the "row" of its source row in properties. The view is fitted to the data's GeoFrame.GeoSeries.total_bounds/1. The basemap is MapLibre's demo style, which needs internet access in the browser. Coordinates are drawn as stored and must be longitude/latitude; Z and M are ignored (the Inspect and Table tabs still show them).

Size limit

GeoJSON is JSON text held in the notebook, so the cost of a map is its vertices, not its features. Maps are capped at 50000 features and 500000 vertices by default; larger inputs show a notice instead of a map. Change the caps per call with the :max_features and :max_vertices options of map/2, or globally with config :geoframe, max_map_features: n, max_map_vertices: n. For larger inputs use deck/2, which sends binary buffers and renders them with deck.gl.

Table limit

The Table tab converts every geometry to WKT and hands every row to the browser, so it is capped as well: by default the leading rows that fit 100000 rows and 250000 vertices (all geometry columns together) are shown, above a notice that says how many were left out. Use table/2 with :max_rows and :max_vertices, or config :geoframe, max_table_rows: n, max_table_vertices: n.

Summary

Functions

Builds a deck.gl map kino that draws geometry from binary buffers instead of GeoJSON, so it scales to a million features.

Builds the MapLibre style for a frame or series, without wrapping it in a kino.

The default cap on features drawn on a map.

The default cap on vertices drawn on a map.

Builds the table kino for a frame, capped by rows and vertices.

Functions

deck(frame, opts \\ [])

Builds a deck.gl map kino that draws geometry from binary buffers instead of GeoJSON, so it scales to a million features.

See GeoFrame.Kino.Deck for the options (:color, :radius, :width, :opacity, :tooltip, :popup, :max_features, :max_vertices, :basemap, :height) and how the data is transferred. A list of frames, or of {frame, options}, draws several layers with a layer control. Unlike map/2 it needs no extra packages, only internet access in the browser.

map(frame, opts \\ [])

Builds the map kino for a GeoFrame.GeoDataFrame or GeoFrame.GeoSeries.

Returns a MapLibre kino, or a Markdown notice when the input is too large, has nothing to draw, or :kino_maplibre is not installed.

Options: :max_features - feature cap, defaults to max_features/0; :max_vertices - vertex cap, defaults to max_vertices/0. GeometryCollections are drawn member by member.

maplibre(frame)

Builds the MapLibre style for a frame or series, without wrapping it in a kino.

Use it to customise the map (extra layers, another basemap) before calling Kino.MapLibre.new/1. The GeoJSON source is named "geoframe" and the layers are "geoframe-fill", "geoframe-outline", "geoframe-line" and "geoframe-circle". Features carry their source "row" as the only property and are drawn in 2D: Z and M are dropped. A GeometryCollection becomes one feature per member (nested collections flattened, empty members omitted). The size limits are not applied here.

max_features()

@spec max_features() :: pos_integer()

The default cap on features drawn on a map.

max_vertices()

@spec max_vertices() :: pos_integer()

The default cap on vertices drawn on a map.

table(gdf, opts \\ [])

Builds the table kino for a frame, capped by rows and vertices.

A frame within both caps gives the plain Kino.DataTable. A larger one gives the leading rows that fit, below a notice saying how many were left out; the frame itself is untouched.

Options: :max_rows (default config :geoframe, max_table_rows:, else 100000) and :max_vertices (default config :geoframe, max_table_vertices:, else 250000), the vertices of all geometry columns together.