Skip to content

Documentation v1.0.0


Documentation / @openassistant/geoda / area

Variable: area

const area: OpenAssistantTool<AreaFunctionArgs, AreaLlmResult, AreaAdditionalData, SpatialToolContext>

Defined in: src/spatial_ops/area.ts:83

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.

Released under the MIT License.