Skip to main content
Glama

zoom_to_layer

Focus the map view on a specific layer's extent in QGIS. This tool centers the display around selected geographic data for better visualization and analysis.

Instructions

Zoom to the extent of a specified layer.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
layer_idYes

Implementation Reference

  • MCP tool handler for 'zoom_to_layer' that proxies the command to the underlying QGIS socket server via get_qgis_connection().
    @mcp.tool() def zoom_to_layer(ctx: Context, layer_id: str) -> str: """Zoom to the extent of a specified layer.""" qgis = get_qgis_connection() result = qgis.send_command("zoom_to_layer", {"layer_id": layer_id}) return json.dumps(result, indent=2)
  • Exact implementation of the zoom_to_layer logic in the QGIS plugin, which sets the layer active and zooms the map canvas to it.
    def zoom_to_layer(self, layer_id, **kwargs): """Zoom to a layer's extent""" project = QgsProject.instance() if layer_id in project.mapLayers(): layer = project.mapLayer(layer_id) self.iface.setActiveLayer(layer) self.iface.zoomToActiveLayer() return {"zoomed_to": layer_id} else: raise Exception(f"Layer not found: {layer_id}")
  • Registration of the 'zoom_to_layer' handler in the QGIS MCP server's command handlers dictionary.
    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