Skip to main content
Glama

geojson_to_topojson

Convert GeoJSON to TopoJSON format to reduce file size by sharing boundaries between adjacent features, making geographic data more compact for web applications.

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 main handler function that executes the geojson_to_topojson tool. Converts GeoJSON to TopoJSON using topojsonServer.topology() and optionally applies quantization with 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 required geojson object and optional objectName and quantization parameters.
    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 ListToolsRequestSchema handler, 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'], },

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