Skip to content

Documentation v1.0.0


Documentation / @openassistant/geoda / minimumSpanningTree

Variable: minimumSpanningTree ​

const minimumSpanningTree: OpenAssistantTool<MinimumSpanningTreeArgs, MinimumSpanningTreeLlmResult, MinimumSpanningTreeAdditionalData, SpatialToolContext>

Defined in: src/spatial_ops/mst.ts:60

minimumSpanningTree Tool ​

This tool creates a minimum spanning tree (MST) from a set of points. An MST connects all points with the minimum total edge length, useful for network analysis and optimization problems.

Minimum Spanning Tree ​

The tool creates MSTs with the following features:

  • Point Connection: Connects all input points with minimum total distance
  • Network Analysis: Useful for finding optimal connections between locations
  • Spatial Optimization: Minimizes total length while ensuring connectivity
  • Line Output: Returns the MST as line features for mapping

Parameters ​

  • datasetName: Name of the dataset with point geometries to create MST from (optional)
  • geojson: GeoJSON string of point geometries to create MST from (optional)

Example user prompts:

  • "Create a minimum spanning tree from these points"
  • "Connect all the cities with the shortest possible roads"
  • "Generate an MST for the facility locations"

Example ​

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

const mstTool = {
  ...minimumSpanningTree,
  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 minimum spanning tree from these points',
  tools: { minimumSpanningTree: convertToVercelAiTool(mstTool) },
});

INFO

For polygons, the centroids are used to generate the minimum spanning tree.

Released under the MIT License.