Skip to main content

Variable: cartogram

const cartogram: ExtendedTool<CartogramFunctionArgs, CartogramLlmResult, CartogramAdditionalData, SpatialToolContext>

Defined in: packages/tools/geoda/src/spatial_ops/cartogram.ts:44

cartogram Tool

This tool is used to create a dorling cartogram from a given geometries and a variable.

Cartogram Creation

A cartogram is a map type where the original layout of the areal unit is replaced by a geometric form (usually a circle, rectangle, or hexagon) that is proportional to the value of the variable for the location. This is in contrast to a standard choropleth map, where the size of the polygon corresponds to the area of the location in question. The cartogram has a long history and many variants have been suggested, some quite creative. In essence, the construction of a cartogram is an example of a nonlinear optimization problem, where the geometric forms have to be located such that they reflect the topology (spatial arrangement) of the locations as closely as possible (see Tobler 2004, for an extensive discussion of various aspects of the cartogram).

Example

import { cartogram, CartogramTool } from '@openassistant/geoda';
import { convertToVercelAiTool } from '@openassistant/utils';
import { generateText } from 'ai';

const cartogramTool: CartogramTool = {
...cartogram,
context: {
getGeometries: (datasetName) => {
return SAMPLE_DATASETS[datasetName].map((item) => item.geometry);
},
getValues: (datasetName, variableName) => {
return SAMPLE_DATASETS[datasetName].map((item) => item[variableName]);
},
},
});

generateText({
model: openai('gpt-4o-mini', { apiKey: key }),
prompt: 'Create a dorling cartogram from the geometries and the variable "population"',
tools: { cartogram: convertToVercelAiTool(cartogramTool) },
});