Documentation / @openassistant/geoda / cartogram
Variable: cartogram
constcartogram:OpenAssistantTool<CartogramFunctionArgs,CartogramLlmResult,CartogramAdditionalData,SpatialToolContext>
Defined in: src/spatial_ops/cartogram.ts:58
cartogram Tool
This tool creates a Dorling cartogram from given geometries and a variable. A cartogram is a map where the size of geographic units is proportional to a variable value rather than their actual geographic area.
Cartogram Creation
A cartogram replaces the original layout of areal units with geometric forms (usually circles) that are proportional to the variable value. This is useful for visualizing data where geographic size doesn't reflect the importance of the data.
Parameters
datasetName: Name of the dataset containing the geometries and variablevariableName: Name of the variable to use for sizing the cartogram elementsiterations: Number of iterations for cartogram optimization (default: 100)
Example user prompts:
- "Create a Dorling cartogram from the geometries and the variable 'population'"
- "Generate a cartogram showing GDP by country"
- "Make a cartogram of election results by state"
Example
typescript
import { cartogram } from "@openassistant/geoda";
import { convertToVercelAiTool } from "@openassistant/utils";
const cartogramTool = {
...cartogram,
context: {
getGeometries: async (datasetName: string) => {
// Implementation to retrieve geometries from your data source
return geometries;
},
getValues: async (datasetName: string, variableName: string) => {
// Implementation to retrieve values from your data source
return [100, 200, 150, 300, 250];
},
},
};
const result = await generateText({
model: openai('gpt-4.1', { apiKey: key }),
prompt: 'Create a Dorling cartogram from the geometries and the variable "population"',
tools: { cartogram: convertToVercelAiTool(cartogramTool) },
});