Skip to content

Documentation v1.0.0


Documentation / @openassistant/geoda / spatialFilter

Variable: spatialFilter

const spatialFilter: OpenAssistantTool<SpatialJoinFunctionArgs, SpatialJoinLlmResult, SpatialJoinAdditionalData, SpatialJoinFunctionContext>

Defined in: src/spatial_join/spatial-filter.ts:58

spatialFilter Tool

This tool filters geometries from one dataset based on their spatial relationship with geometries from another dataset. It's useful for extracting subsets of spatial data that intersect with specific areas or boundaries.

Spatial Filtering

The tool filters geometries based on spatial relationships:

  • Points in Polygons: Extract points that fall within polygon boundaries
  • Lines Intersecting Areas: Filter lines that intersect with specific areas
  • Polygons Overlapping: Select polygons that overlap with reference polygons

Parameters

  • rightDatasetName: Name of the dataset providing the filter geometries (e.g., polygons)
  • leftDatasetName: Name of the dataset containing geometries to be filtered (e.g., points)
  • joinVariables: Should be empty arrays for filtering operations

Example user prompts:

  • "Filter the crime incidents that fall within the downtown district"
  • "Extract all schools located within the city boundaries"
  • "Find all roads that intersect with the flood zone"

Example

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

const filterTool = {
  ...spatialFilter,
  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: 'Filter the crime incidents that fall within the downtown district',
  tools: { spatialFilter: convertToVercelAiTool(filterTool) },
});

INFO

The left dataset should contain the geometries to be filtered (e.g., points). The right dataset should contain the geometries used for filtering (e.g., polygons). joinVariables should be empty arrays for filtering operations.

Released under the MIT License.