extract-raster-value
Retrieve raster values at specified coordinates using a PostGIS database. Input a table name, latitude, and longitude to extract spatial data for analysis or mapping.
Instructions
Belirli koordinattaki raster değerini çıkar
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| latitude | Yes | Enlem | |
| longitude | Yes | Boylam | |
| raster_column | No | Raster kolonu (varsayılan: rast) | |
| table_name | Yes | Raster tablosu |
Implementation Reference
- server.ts:1842-1882 (handler)The handler function for the 'extract-raster-value' tool. It parses input using the schema, sanitizes table/raster column names, executes a PostGIS query using ST_Value and ST_Intersects to extract raster pixel value at given longitude/latitude coordinates, and returns the results including value, band1 value, num_bands, and intersection status.case "extract-raster-value": { const { table_name, longitude, latitude, raster_column } = ExtractRasterValueSchema.parse(args); const sanitizedTableName = table_name.replace(/[^a-zA-Z0-9_]/g, ""); const sanitizedRasterColumn = raster_column || "rast"; const result = await client.query( ` SELECT ST_Value(${sanitizedRasterColumn}, ST_SetSRID(ST_MakePoint($1, $2), 4326)) as raster_value, ST_Value(${sanitizedRasterColumn}, 1, ST_SetSRID(ST_MakePoint($1, $2), 4326)) as band1_value, ST_NumBands(${sanitizedRasterColumn}) as num_bands FROM ${sanitizedTableName} WHERE ST_Intersects(${sanitizedRasterColumn}, ST_SetSRID(ST_MakePoint($1, $2), 4326)) LIMIT 1; `, [longitude, latitude] ); return { content: [ { type: "text", text: JSON.stringify( { table_name: sanitizedTableName, raster_column: sanitizedRasterColumn, coordinates: [longitude, latitude], raster_value: result.rows[0]?.raster_value || null, band1_value: result.rows[0]?.band1_value || null, num_bands: result.rows[0]?.num_bands || 0, found_intersection: result.rows.length > 0, }, null, 2 ), }, ], }; }
- server.ts:125-130 (schema)Zod schema defining the input parameters for the 'extract-raster-value' tool: table_name (required), longitude (required), latitude (required), raster_column (optional, defaults to 'rast'). Used for validation in the handler.const ExtractRasterValueSchema = z.object({ table_name: z.string(), longitude: z.number(), latitude: z.number(), raster_column: z.string().optional().default("rast"), });
- server.ts:936-951 (registration)Registration of the 'extract-raster-value' tool in the ListToolsRequestHandler response. Defines the tool name, description, and inputSchema matching the Zod schema.name: "extract-raster-value", description: "Belirli koordinattaki raster değerini çıkar", inputSchema: { type: "object", properties: { table_name: { type: "string", description: "Raster tablosu" }, longitude: { type: "number", description: "Boylam" }, latitude: { type: "number", description: "Enlem" }, raster_column: { type: "string", description: "Raster kolonu (varsayılan: rast)", }, }, required: ["table_name", "longitude", "latitude"], }, },