Skip to content

tutorial - Chapter 05

GPU computing with Autark Compute ​

Custom analysis that runs on the GPU in your browser and attaches its results to the GeoJSON features it describes.

1. Autark Compute

Urban analysis often starts with a question about individual features: How compact is this building footprint? What score should we give this street? How much sky is visible from a location? Autark Compute (autk-compute) runs custom analysis on the GPU, directly in the browser, and attaches the results to GeoJSON features.

This page uses AutkComputeEngine for two workflows: deriving attributes with gpgpuPipeline() and estimating visibility with renderPipeline(). We start with a small dataset so you can check the results by hand. At this scale GPU overhead can outweigh its benefits.

1.1 Feature-centric model and GeoJSON data

A GeoJSON Feature combines a geometry with a properties object, and a FeatureCollection groups features. Autark keeps analysis results attached to the feature they describe: a compactness value belongs to a building, and a visibility result belongs to the feature used as a viewpoint.

{
  type: "Feature",
  id: "building-a",
  geometry: { /* GeoJSON geometry */ },
  properties: {
    area: 400,
    perimeter: 80,
    compute: { compactness: 0.7854 }
  }
}

The pipelines return a new collection rather than modifying the original. Keep a reference to the returned collection: downstream cells should use that enriched result.

1.2 GPU computation and render analysis

PipelineInputAnalysisResult location
gpgpuPipeline()Feature attributes or geometry and a WGSL functionComputes values independently for each featureproperties.compute
renderPipeline()Scene layers and viewpointsRenders sampled views and aggregates visible contentproperties.compute.render on the viewpoints

Use autk-db for filtering, grouping, joins and operations that are naturally SQL. Use autk-compute for custom per-feature GPU formulas or view-based analysis.

1.3 First example

We compute a floor-area proxy, footprint area × number of floors, for a sample of 64 buildings from Battery Park City in lower Manhattan. Each building has its area in square meters, perimeter in meters and number of floors (from the OSM building:levels tag).

The computation itself:

2. Property computation

2.1 The pipeline configuration

The cell above multiplies each measured footprint area by its floor count. Because the inputs come from real buildings, the output varies with both footprint size and height. The configuration has four parts: collection selects the input features; variableMapping exposes area and floors to WGSL; wgslBody defines the calculation; and resultField stores the result at properties.compute.floorArea.

2.2 Mapping feature attributes with variableMapping

The mapping keys are WGSL variable names; the values are paths into the input feature. For example {area: "shape_area"} makes the property shape_area available as area inside WGSL. Both "area" and "properties.area" are valid paths.

Mapped scalar values are 32-bit floats. Missing numeric inputs fall back to zero, so validate required attributes before running a calculation:

2.3 Writing WGSL expressions

WGSL is the shader language of WebGPU. The string passed as wgslBody is the body of a function; the pipeline supplies the mapped inputs. Use floating-point literals such as 1.0, and return a value on every branch.

wgslBody: `
  if (perimeter <= 0.0) { return -1.0; }
  return (4.0 * 3.1415927 * area) / (perimeter * perimeter);
`

Here -1.0 is an explicit sentinel for an invalid perimeter. Exclude or label it in a visualization rather than treating it as a real compactness value, and validate area too when working with external data.

2.4 Scalar and multi-column outputs

Use resultField when returning one f32. Use outputColumns when returning an array<f32, N>; the array length and order must match the declared columns. This computes two related measures in one pass:

2.5 Example: computing building compactness

For a footprint with area A and perimeter P, define compactness as C = 4πA / P². A circle has C = 1, a square has C = π/4 ≈ 0.7854, and an elongated rectangle has a smaller value. The measure describes shape, not size or building quality.

The cell computes compactness for every building in the sample. A value near 1 means a compact footprint; lower values mean elongated footprints or multipart buildings with more boundary per unit area. The collection keeps the original OSM tags and geometry and adds the result at properties.compute.compactness.

2.6 Measuring a multipart road

Autark 5 can pass feature geometry to WGSL through a topology-aware binding. Map road to "geometry", not "geometry.coordinates" as an attribute matrix. Each LineString node has its own point range, so a MultiLineString does not gain a false segment between parts.

Run this example with two disjoint line segments in projected meters. Their lengths are 3 m and 4 m. The result should be 7 m, regardless of the gap between them. Try moving the second segment without changing its length.

3. Render analysis

3.1 The render pipeline

Attribute computation asks what we can derive from a feature's stored values. Render analysis asks what can be seen from a location. The engine renders a scene from sampled camera positions, counts visible content, and attaches aggregated results to viewpoint features.

3.2 Defining the scene and viewpoints

A render analysis begins with the scene: a list of FeatureCollection objects the pipeline can draw. Here the scene is the buildings of Battery Park City and the Financial District in New York City (a bounding box around them), and the viewpoints are the roads there. After loading the data with autk-db, getLayer() returns the building and road layers.

The buildings become the scene. The pipeline also needs a viewpoints collection, which fixes where each camera goes. Each road feature is sampled at its centerline midpoint, which becomes the camera location, and sampling.directions sets the viewing directions. With one direction the output is a fast first-pass exposure estimate for every road feature.

const layers = [{id: "buildings", collection: ctx.skyBuildings, type: "buildings"}];
const viewpoints = {collection: ctx.skyRoads, sampling: {directions: 1}};

3.3 Aggregating render results

Next, choose how the rendered pixels are aggregated. This choice decides the metric returned for each viewpoint, such as the visible share of a class or the set of visible objects.

This example treats pixels not covered by a scene layer as sky. With class aggregation, that uncovered background contributes to the sky class. By contrast, {type: "objects"} reports the individual visible objects; to match object results back to source data, give each scene layer a stable objectIdProperty.

Camera settings control the field of view and clipping distances. tileSize sets the resolution of each sample and must be a positive integer multiple of eight. For baseline/proposal scenes or subsets of viewpoints, reuse a coordinateOrigin computed from the unchanged baseline geometry, as well as identical camera/sampling settings. Otherwise rounding can produce false small differences. The camera extent, sampling strategy, scene completeness and resolution all influence the result.

const aggregation = {
  type: "classes",
  includeBackground: true,
  backgroundLayerType: "sky",
};

The sky component is at properties.compute.render.classes.sky. Object aggregation writes to properties.compute.render.objects. Inspect the output before choosing fields for a table or color scale, and during validation keep a missing result distinct from a measured zero.

3.4 Example: measuring sky exposure

We now have what a render analysis needs: a scene built from the buildings and a set of viewpoints sampled from the roads. The cell runs renderPipeline() with the layers, viewpoints and aggregation options above, using class aggregation with sky as the background layer.

The render pipeline returns a new collection of viewpoint features enriched with render metrics. Here are the ten roads with the most sky:

Autark 5 can use building windows as viewpoints too. See the User Guide’s render analysis chapter for window IDs and how to match each result to its source building.

Credits

Adapted from the Observable notebook 06. GPU Computing, produced for the tutorial Urban Data Analytics with Autark at SIBGRAPI 2026. See the author list. The building sample is derived from OpenStreetMap data © OpenStreetMap contributors (ODbL).

Released under the MIT License.