create-linestring
Generate LineString geometries from coordinate arrays using the PostGIS MCP Server. Input coordinate pairs to create spatial lines for GIS applications.
Instructions
Koordinat dizisinden çizgi geometrisi oluştur
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| coordinates | Yes | Koordinat dizisi [[lon,lat], [lon,lat], ...] | |
| srid | No | SRID (varsayılan: 4326) |
Implementation Reference
- server.ts:1315-1349 (handler)The main handler for the 'create-linestring' tool. Parses input using CreateLineStringSchema, constructs a LINESTRING WKT from the provided coordinates, executes a PostGIS query to generate WKT, GeoJSON representations, and computes the length in meters using ST_Length on geography type.
case "create-linestring": { const { coordinates, srid } = CreateLineStringSchema.parse(args); const coordString = coordinates .map((coord) => `${coord[0]} ${coord[1]}`) .join(", "); const result = await client.query( ` SELECT ST_AsText(ST_GeomFromText('LINESTRING(${coordString})', $1)) as wkt, ST_AsGeoJSON(ST_GeomFromText('LINESTRING(${coordString})', $1)) as geojson, ST_Length(ST_GeomFromText('LINESTRING(${coordString})', $1)::geography) as length_meters `, [srid] ); return { content: [ { type: "text", text: JSON.stringify( { wkt: result.rows[0].wkt, geojson: JSON.parse(result.rows[0].geojson), coordinates: coordinates, length_meters: parseFloat(result.rows[0].length_meters), srid: srid, }, null, 2 ), }, ], }; } - server.ts:37-40 (schema)Zod schema for validating the input parameters of the create-linestring tool: array of coordinate pairs/triples and optional SRID.
const CreateLineStringSchema = z.object({ coordinates: z.array(z.array(z.number().min(2).max(3))), srid: z.number().optional().default(4326), }); - server.ts:635-649 (registration)Tool registration in the ListToolsRequestHandler response, defining the name, description, and JSON input schema for create-linestring.
name: "create-linestring", description: "Koordinat dizisinden çizgi geometrisi oluştur", inputSchema: { type: "object", properties: { coordinates: { type: "array", description: "Koordinat dizisi [[lon,lat], [lon,lat], ...]", items: { type: "array", items: { type: "number" } }, }, srid: { type: "number", description: "SRID (varsayılan: 4326)" }, }, required: ["coordinates"], }, },