Skip to main content

OpenStreetMap Tools

The OpenStreetMap tools for OpenAssistant provides a suite of tools that can invoke OpenStreetMap related APIs e.g. geocoding, calculate routing, fetch OSM roads, generate isochrone etc.

Features

Tool NameDescription
geocodingconverts addresses into geographic coordinates (latitude and longitude) using OpenStreetMap's Nominatim service.
routingcalculates routes between two points using Mapbox's Directions API
isochronegenerates isochrone polygons showing reachable areas within a given time or distance limit
roadsfetch road networks based on a boundary and road type using OSM Overpass API
queryUSZipcodesquery US zipcodes within a given map bounds
getUsStateGeojsonget the GeoJSON data of one or more United States states
getUsCountyGeojsonget the GeoJSON data of one or more United States counties
getUsZipcodeGeojsonget the GeoJSON data of one or more United States zipcodes

Installation

npm install @openassistant/osm @openassistant/utils ai

Quick Start

import { geocoding, GeocodingTool } from "@openassistant/osm";
import { convertToVercelAiTool } from '@openassistant/utils';
import { generateText } from 'ai';

const result = await generateText({
model: openai('gpt-4o-mini', { apiKey: key }),
prompt: 'What are the coordinates of the Eiffel Tower?',
tools: {
geocoding: convertToVercelAiTool(geocoding),
},
});

console.log(result);
tip

The OpenStreetMap tools can be mixed with other tools for more complex tasks. For example, if you have a point datasets in the US, you can use OSM tool to answer questions like "What are the total revenus in the zipcodes area in Maricopa county?"

The LLM could plan the following steps to answer the question:

  1. Get the GeoJSON data of Maricopa county
  2. Query the zipcodes in the county
  3. Get all zipcode areas (GeoJSON) boundaries
  4. Use spatialJoin tool to join the zipcode areas with the revenus data
  5. Return the total revenus in each zipcode area