Skip to content

Documentation v1.0.0


Documentation / @openassistant/geoda / perimeter

Variable: perimeter

const perimeter: OpenAssistantTool<PerimeterFunctionArgs, PerimeterLlmResult, PerimeterAdditionalData, SpatialToolContext>

Defined in: src/spatial_ops/perimeter.ts:78

perimeter Tool

This tool calculates the perimeter of geometries in a GeoJSON dataset. It supports both direct GeoJSON input and dataset names, and can calculate perimeters in either kilometers or miles.

Perimeter Calculation

The tool calculates perimeters for various geometry types:

  • Polygons: Calculates the perimeter length of polygon boundaries
  • MultiPolygons: Calculates the total perimeter of multipolygon geometries
  • FeatureCollections: Calculates perimeters for all polygon features in the collection

Parameters

  • datasetName: Name of the dataset with geometries to calculate perimeter for (optional)
  • geojson: GeoJSON string of geometries to calculate perimeter for (optional)
  • distanceUnit: Unit for perimeter calculation - 'KM' for kilometers or 'Mile' for miles

Example user prompts:

  • "Calculate the perimeter of these polygons in kilometers"
  • "What is the total perimeter of these boundaries in miles?"
  • "Measure the perimeter of these land parcels"

Example

typescript
import { perimeter } from "@openassistant/geoda";
import { convertToVercelAiTool } from "@openassistant/utils";

const perimeterTool = {
  ...perimeter,
  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 perimeter of these polygons in kilometers',
  tools: { perimeter: convertToVercelAiTool(perimeterTool) },
});

Released under the MIT License.