Skip to main content
Glama

render_map

Export the current QGIS map view to an image file with customizable dimensions for sharing or documentation purposes.

Instructions

Render the current map view to an image file with the specified dimensions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
widthNo
heightNo

Implementation Reference

  • Core handler implementing map rendering using QGIS QgsMapSettings and QgsMapRendererParallelJob to capture the current map canvas extent and save as image.
    def render_map(self, path, width=800, height=600, **kwargs): """Render the current map view to an image""" try: # Create map settings ms = QgsMapSettings() # Set layers to render layers = list(QgsProject.instance().mapLayers().values()) ms.setLayers(layers) # Set map canvas properties rect = self.iface.mapCanvas().extent() ms.setExtent(rect) ms.setOutputSize(QSize(width, height)) ms.setBackgroundColor(QColor(255, 255, 255)) ms.setOutputDpi(96) # Create the render render = QgsMapRendererParallelJob(ms) # Start rendering render.start() render.waitForFinished() # Get the image and save img = render.renderedImage() if img.save(path): return { "rendered": True, "path": path, "width": width, "height": height } else: raise Exception(f"Failed to save rendered image to {path}") except Exception as e: raise Exception(f"Render error: {str(e)}")
  • MCP server tool handler for render_map, which proxies the command to the QGIS plugin server via socket connection.
    @mcp.tool() def render_map(ctx: Context, path: str, width: int = 800, height: int = 600) -> str: """Render the current map view to an image file with the specified dimensions.""" qgis = get_qgis_connection() result = qgis.send_command("render_map", {"path": path, "width": width, "height": height}) return json.dumps(result, indent=2)
  • Registration of socket command handlers in QGIS plugin server, mapping 'render_map' to its handler method.
    handlers = { "ping": self.ping, "get_qgis_info": self.get_qgis_info, "load_project": self.load_project, "get_project_info": self.get_project_info, "execute_code": self.execute_code, "add_vector_layer": self.add_vector_layer, "add_raster_layer": self.add_raster_layer, "get_layers": self.get_layers, "remove_layer": self.remove_layer, "zoom_to_layer": self.zoom_to_layer, "get_layer_features": self.get_layer_features, "execute_processing": self.execute_processing, "save_project": self.save_project, "render_map": self.render_map, "create_new_project": self.create_new_project, }

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/syauqi-uqi/qgis_mcp_modify1'

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