import { OpenAssistantTool } from '@openassistant/utils'; import { z } from 'zod'; import { SpatialToolContext } from '../types'; export type AreaFunctionArgs = z.ZodObject<{ geojson: z.ZodOptional; datasetName: z.ZodOptional; distanceUnit: z.ZodDefault>; }>; export type AreaLlmResult = { success: boolean; result: string; areas: number[]; distanceUnit: 'KM' | 'Mile'; }; export type AreaAdditionalData = { datasetName?: string; geojson?: string; distanceUnit: 'KM' | 'Mile'; areas: number[]; }; /** * ## area Tool * * This tool calculates the area of geometries in a GeoJSON dataset. * It supports both direct GeoJSON input and dataset names, and can calculate areas in either square kilometers or square miles. * * ### Area Calculation * * The tool calculates the area of various geometry types: * - **Polygons**: Calculates the area of polygon geometries * - **MultiPolygons**: Calculates the total area of multipolygon geometries * - **FeatureCollections**: Calculates areas for all polygon features in the collection * * ### Parameters * - `datasetName`: Name of the dataset with geometries to calculate area for (optional) * - `geojson`: GeoJSON string of geometries to calculate area for (optional) * - `distanceUnit`: Unit for area calculation - 'KM' for square kilometers or 'Mile' for square miles * * **Example user prompts:** * - "Calculate the area of these counties in square kilometers" * - "What is the total area of these land parcels in square miles?" * - "Measure the area of these polygons" * * ### Example * ```typescript * import { area } from "@openassistant/geoda"; * import { convertToVercelAiTool } from "@openassistant/utils"; * * const areaTool = { * ...area, * 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: 'Calculate the area of these counties in square kilometers', * tools: { area: convertToVercelAiTool(areaTool) }, * }); * ``` * * :::tip * You can also use this tool with other tools, e.g. geocoding, so you don't need to provide the `getGeometries` function. * The geometries from geocoding tool will be used as the input for this tool. * ::: */ export declare const area: OpenAssistantTool; export type AreaTool = typeof area;