Documentation / @openassistant/geoda / grid
Variable: grid
constgrid:OpenAssistantTool<GridFunctionArgs,GridLlmResult,GridAdditionalData,SpatialToolContext>
Defined in: src/spatial_ops/grid.ts:180
grid Tool
This tool creates a grid of polygons that divides a given area into N rows and M columns. It's useful for spatial analysis, creating regular grids for sampling, or dividing areas into equal sections.
Grid Creation
The tool creates regular grids with the following features:
- Customizable Dimensions: Specify number of rows and columns
- Boundary-based: Create grids within dataset boundaries or map view bounds
- Equal-sized Cells: Each grid cell has equal area
- Spatial Reference: Maintains proper coordinate system
Parameters
datasetName: Name of the dataset with boundary geometry to create grid within (optional)mapBounds: Map bounds defined by northwest and southeast coordinates (optional)rows: Number of rows in the grid (N)columns: Number of columns in the grid (M)
Example user prompts:
- "Create a 5x5 grid over this area"
- "Divide this region into a 10 by 8 grid"
- "Generate a grid with 6 rows and 4 columns for this boundary"
- "Create a 3x3 grid for the current map view"
Example
typescript
import { grid } from "@openassistant/geoda";
import { convertToVercelAiTool } from "@openassistant/utils";
const gridTool = {
...grid,
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: 'Create a 5x5 grid over this area',
tools: { grid: convertToVercelAiTool(gridTool) },
});