Skip to main content
Glama

geojson_to_topojson

Convert GeoJSON files into TopoJSON format for more compact storage and shared boundaries, streamlining GIS data management and processing.

Instructions

Convert GeoJSON to TopoJSON format (more compact with shared boundaries)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
geojsonYesGeoJSON object to convert
objectNameNoName of the TopoJSON object to createdata
quantizationNoQuantization parameter for simplification (0 to disable)

Implementation Reference

  • The handler function that implements the geojson_to_topojson tool. It uses topojsonServer.topology to create a topology from the GeoJSON and optionally applies quantization using topojsonClient.quantize.
    async geojsonToTopoJSON(args: any): Promise<ToolResponse> { const { geojson, objectName = 'data', quantization = 1e4 } = args; if (!geojson) { throw new McpError( ErrorCode.InvalidParams, 'Missing required parameter: geojson' ); } try { console.error('[Converting] GeoJSON to TopoJSON'); // Create a topology object from the GeoJSON const objectsMap: Record<string, any> = {}; objectsMap[objectName] = geojson; // Generate the topology const topology = topojsonServer.topology(objectsMap); // Apply quantization if specified let result = topology; if (quantization > 0) { // Use type assertion to work around TypeScript type incompatibility result = topojsonClient.quantize(topology as any, quantization); } return this.formatToolResponse(JSON.stringify(result, null, 2)); } catch (error) { console.error('[Error] GeoJSON to TopoJSON conversion failed:', error); throw new McpError( ErrorCode.InternalError, `GeoJSON to TopoJSON conversion failed: ${error instanceof Error ? error.message : String(error)}` ); } }
  • Input schema definition for the geojson_to_topojson tool, specifying parameters like geojson (required), objectName, and quantization.
    inputSchema: { type: 'object', properties: { geojson: { type: 'object', description: 'GeoJSON object to convert', }, objectName: { type: 'string', description: 'Name of the TopoJSON object to create', default: 'data', }, quantization: { type: 'number', description: 'Quantization parameter for simplification (0 to disable)', default: 1e4, }, }, required: ['geojson'],
  • src/index.ts:165-187 (registration)
    Registration of the geojson_to_topojson tool in the ListTools response, including name, description, and input schema.
    { name: 'geojson_to_topojson', description: 'Convert GeoJSON to TopoJSON format (more compact with shared boundaries)', inputSchema: { type: 'object', properties: { geojson: { type: 'object', description: 'GeoJSON object to convert', }, objectName: { type: 'string', description: 'Name of the TopoJSON object to create', default: 'data', }, quantization: { type: 'number', description: 'Quantization parameter for simplification (0 to disable)', default: 1e4, }, }, required: ['geojson'], },
  • src/index.ts:288-289 (registration)
    Dispatcher case in CallToolRequestSchema handler that routes to the geojsonToTopoJSON method.
    case 'geojson_to_topojson': return await this.geojsonToTopoJSON(request.params.arguments);
  • Imports for the TopoJSON libraries used in the conversion.
    // Import TopoJSON libraries import * as topojsonClient from 'topojson-client'; import * as topojsonServer from 'topojson-server';

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ronantakizawa/gis-dataconvertersion-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server