Urban data management with Autark DB
Load OpenStreetMap, GeoJSON, CSV with WKT and GeoTIFF into a spatial database that runs entirely in the browser, then query it with SQL and spatial joins.
How to use this page
The examples are cells of one notebook. They share state through ctx: the first cell creates the database and stores it as ctx.db, and later cells reuse it. Run them in order, or press Run all above on any cell to run everything up to it. Edits to the code are saved in this browser.
1. Autark DB
Spatial databases store, index and query geographic data in vector and raster formats. They are needed because conventional databases do not efficiently support the spatial relationships and operations that are central to urban analytics. By combining geometry-aware data types with spatial indexes and query languages, they manage geospatial datasets efficiently. Well-known examples are PostgreSQL with PostGIS, SpatiaLite, and DuckDB with its spatial extension.
Autark DB (autk-db) is the spatial database module of the Autark toolkit. It is powered by DuckDB and runs directly in the browser, with no client-server architecture, so it suits rapid prototyping of urban analytics software. It loads CSV, JSON, GeoJSON, GeoTIFF and OpenStreetMap data, for example from NYC Open Data or OpenStreetMap.
1.1 Initializing a database
Take the AutkDb class, create an instance and call await db.init(), which prepares DuckDB and loads the spatial extension. The cell runner imports @urban-toolkit/autk from the site's pinned local packages through Vite and supplies it as autk to every cell. The database is kept in ctx.db so later cells can reuse it. In this site, the runner uses the pinned RC packages and disposes each cell's resources on rerun or chapter navigation. In your own app, call await db.destroy() when finished; it releases the worker and instance-owned raster data. Initialization is idempotent. Ordinary browser deployments serve the worker/WASM beside the DB bundle, or configure init({assetBaseUrl: "/assets/duckdb/"}); self-hosting the engine does not guarantee offline spatial extensions.
1.2 Workspaces
A workspace is an isolated database context for organizing geospatial tables. A table created in one workspace is not visible in another, which helps when handling several cities or independent analysis scenarios without name conflicts. After initialization there is one workspace, named "autk".
Autark 5 defaults to EPSG:3395 (World Mercator) and snaps vector geometry to a 0.01 precision grid in workspace units. All spatial inputs are converted to the workspace CRS. Distances such as the heatmap radius below are in projected meters; use a local CRS when accurate ground distances or areas matter.
setWorkspace() selects or creates a workspace. To configure a workspace, pass both crs and precisionGrid before loading tables. The remaining cells reuse this workspace and omit the options when switching back to it.
2. Loading data
2.1 OpenStreetMap data
loadOsm() fetches data from the Overpass API or parses a downloaded OSM extract (pbfFileUrl), and stores the extracted layers as named tables. A simple query interface names the area and the layers; since each layer is its own table, it can later be queried, transformed and returned as GeoJSON.
The area is either a bounding box ({bbox: [west, south, east, north]}, used here) or named OSM areas ({geocodeArea: "New York", areas: ["Battery Park City"]}). We use a box because it keeps the download small: the named form first resolves "New York" to the whole state, and then also downloads every coastline inside the state's bounding box, about 10 MB and over a minute of Overpass time, just to cut the water layer for one neighborhood.
2.2 GeoJSON data
loadGeojson() stores a GeoJSON FeatureCollection as a named table; outputTableName names it. The GeoJSON can come as a file URL or as an in-memory object. sourceCrs is a top-level loader option and defaults to EPSG:4326. When you read the table with getLayer(), the coordinates are already in the workspace CRS, not longitude and latitude.
2.3 CSV with WKT data
loadCsv() stores a CSV as a named table. When the file holds geometry as WKT, tell it which column through geometryColumns. Here the column wkt becomes the spatial layer at import time.
2.4 GeoTIFF data
loadGeoTiff() stores an elevation raster as a named table. Pass the file contents as an ArrayBuffer, declare its sourceCrs, and set a maxRasterCells budget to trade resolution for browser memory. Try lowering the budget and compare the dimensions returned by getRaster(). It returns a packed collection: values live in band arrays, not in one polygon per pixel.
3. Analytical queries
Analytical queries use rawQuery(), which runs SQL directly on the tables of the current workspace. Because DuckDB manages the data in the browser, the familiar patterns of filtering, grouping and aggregation work without leaving the page. They support OLAP-style workflows, in which datasets are summarized across dimensions and measures. The examples query the park layer loaded in 2.1.
3.1 Filtering data
A filter keeps only the rows that satisfy a condition. This query creates large_parks with a few descriptive attributes and keeps the geometry column so it can be read back as a spatial layer. The area is planar in the workspace projection.
rawQuery() has different output modes through output. With RETURN_OBJECT the result comes back as an array of JavaScript objects, handy for inspection, summaries and intermediate results. With CREATE_TABLE the result is stored as a new table in the current workspace, named by tableName; optional source and tableType metadata let it be treated as a new dataset for later retrieval or visualization.
3.2 Grouping data
Group-by queries summarize data by category. This one counts park features and sums their areas by category, using attributes already present in table_osm_parks.
4. Spatial queries
4.1 Spatial join
spatialQuery() performs a spatial join between two tables already in the current workspace. It takes a root table and a join table and enriches the root table with information derived from the spatial relationship of their geometries. That answers questions such as how many nearby features surround each polygon, or how values from one layer aggregate into another. Here we count park features within 200 projected meters of each surface geometry.
The root table is updated in place. Retrieve it with getLayer() to inspect the enriched geometries and properties.
4.2 Heatmaps
buildHeatmap() builds a grid over the workspace extent. Here each cell counts nearby parks within 200 projected meters. Autark 5 can smooth the resulting band with a Gaussian filter: smoothingSigma is measured in grid cells, not meters. Smoothing turns counts into a continuous surface, so use the unsmoothed values when you need literal counts.
5. Named selections become SQL
A NamedSelection contains semantic feature IDs or WGS84 regions, not plot/map collection indices. A table layout states where each row is located. Here a closed region selects two observations without changing their stored coordinates.
Scalar location columns default to WGS84; a geometry column defaults to EPSG:3395 unless the layout supplies crs. The region is transformed to that CRS. regionPredicate() also accepts a region directly. SQL requires a closed, finite, non-self-intersecting ring and counts boundary points as inside. rawQuery() accepts one SELECT/CTE statement, not a stack of statements or an untrusted-SQL sandbox.
getLayer() can return null geometries for compact rasters. Use isVectorFeatureCollection() before passing an unknown layer to a vector-only API, and getRaster() for compact bands. See Named selections and SQL for directed flows and geometry-column queries.
Credits
Adapted from the Observable notebook 03. Urban Data Management, produced for the tutorial Urban Data Analytics with Autark at SIBGRAPI 2026. See the author list. Map data © OpenStreetMap contributors (ODbL).