Documentation / @openassistant/geoda / centroid
Variable: centroid
constcentroid:OpenAssistantTool<CentroidFunctionArgs,CentroidLlmResult,CentroidAdditionalData,SpatialToolContext>
Defined in: src/spatial_ops/centroid.ts:71
centroid Tool
This tool calculates the centroids (geometric centers) of geometries. Centroids are useful for representing polygon features as points for analysis or visualization.
Centroid Calculation
The tool calculates centroids for various geometry types:
- Polygons: Calculates the geometric center of polygon areas
- MultiPolygons: Calculates centroids for each polygon component
- FeatureCollections: Calculates centroids for all polygon features
Parameters
datasetName: Name of the dataset with geometries to calculate centroids from (optional)geojson: GeoJSON string of geometries to calculate centroids from (optional)
Example user prompts:
- "Can you find the center points of these counties?"
- "Calculate centroids for all the polygons"
- "Get the center points of the administrative boundaries"
Example
typescript
import { centroid } from "@openassistant/geoda";
import { convertToVercelAiTool } from "@openassistant/utils";
const centroidTool = {
...centroid,
context: {
getGeometries: async (datasetName: string) => {
// Implementation to retrieve geometries from your data source
return geometries;
},
},
};
const result = await generateText({
model: openai('gpt-4.1', { apiKey: key }),
prompt: 'Can you find the center points of these counties?',
tools: { centroid: convertToVercelAiTool(centroidTool) },
});