### End-to-End QGIS Workflow Example via Natural Language Source: https://context7.com/ethology-github/qgis_mcp/llms.txt This example demonstrates a user prompt to Claude AI for executing a comprehensive geospatial analysis workflow in QGIS. The prompt outlines steps from project creation and data loading to complex analyses like centroid calculation and choropleth map generation, culminating in map rendering and project saving. ```plaintext User prompt to Claude: "You have access to the tools to work with QGIS. You will do the following: 1. Ping to check the connection. If it works, continue with the following steps. 2. Create a new project and save it at: 'C:/GIS_Projects/analysis.qgz' 3. Load the vector layer: 'C:/Data/boundaries/districts.shp' and name it 'Districts'. 4. Load the raster layer: 'C:/Data/elevation/dem.tif' and name it 'Elevation' 5. Zoom to the 'Elevation' layer. 6. Execute the centroid algorithm on the 'Districts' layer. Save the output to 'district_centroids.geojson'. 7. Execute code to create a choropleth map using the 'POPULATION' field in the 'Districts' layer. Use the quantile classification method with 5 classes and the Spectral color ramp. 8. Render the map to 'C:/GIS_Projects/final_map.png' 9. Save the project." Claude will then execute each step using the MCP tools, handling errors and providing feedback on the progress of each operation. ``` -------------------------------- ### get_qgis_info - Retrieve QGIS Installation Details Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Gets version information and profile details from the connected QGIS instance. ```APIDOC ## get_qgis_info - Retrieve QGIS Installation Details ### Description Gets version information and profile details from the connected QGIS instance. ### Method `get_qgis_info()` ### Endpoint N/A (Internal command) ### Parameters None ### Request Example ```python # MCP tool usage info = get_qgis_info(ctx) # Direct client usage client = QgisMCPClient() client.connect() info = client.get_qgis_info() print(json.dumps(info, indent=2)) ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation, e.g., "success". - **result** (object) - Contains the QGIS information. - **qgis_version** (string) - The version of QGIS installed. - **profile_folder** (string) - The path to the QGIS user profile folder. - **plugins_count** (integer) - The number of installed QGIS plugins. #### Response Example ```json { "status": "success", "result": { "qgis_version": "3.22.0-Białowieża", "profile_folder": "C:/Users/USER/AppData/Roaming/QGIS/QGIS3/profiles/default", "plugins_count": 12 } } ``` ``` -------------------------------- ### Install uv Package Manager (Bash/PowerShell) Source: https://github.com/ethology-github/qgis_mcp/blob/main/README.md Installs the 'uv' package manager using provided shell commands. This is a prerequisite for installing other project dependencies. It offers distinct commands for macOS (Homebrew) and Windows (PowerShell). ```bash brew install uv ``` ```powershell powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### get_project_info - Get Current Project Information Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Retrieves detailed information about the currently loaded QGIS project including layers, CRS, and metadata. ```APIDOC ## get_project_info - Get Current Project Information ### Description Retrieves detailed information about the currently loaded QGIS project including layers, CRS, and metadata. ### Method `get_project_info()` ### Endpoint N/A (Internal command) ### Parameters None ### Request Example ```python # MCP tool usage info = get_project_info(ctx) ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation, e.g., "success". - **result** (object) - Contains detailed information about the current QGIS project. - **project_name** (string) - The name of the current project. - **file_path** (string) - The file path of the current project. - **crs** (string) - The Coordinate Reference System of the project. - **layers** (array) - An array of objects, each describing a layer in the project. - **name** (string) - The name of the layer. - **type** (string) - The type of the layer (e.g., 'vector', 'raster'). - **source** (string) - The data source of the layer. - **metadata** (object) - Any metadata associated with the project. #### Response Example ```json { "status": "success", "result": { "project_name": "City Planning", "file_path": "/home/user/projects/city_planning.qgz", "crs": "EPSG:4326", "layers": [ { "name": "Roads", "type": "vector", "source": "/data/roads.shp" }, { "name": "Buildings", "type": "vector", "source": "/data/buildings.gpkg" } ], "metadata": { "author": "GIS Department", "creation_date": "2023-10-27" } } } ``` ``` -------------------------------- ### Save QGIS Project using MCP Tools and Client Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Provides examples for saving the current QGIS project. This includes using the `save_project` MCP tool function with a specified path and using the `save_project` method of the QgisMCPClient to save to a new location or the current path. Dependencies include the `ctx` object for MCP tools and the `QgisMCPClient`. ```python # MCP tool usage result = save_project(ctx, path="C:/GIS_Projects/updated_project.qgz") ``` ```python # Direct client usage - save to new location client = QgisMCPClient() client.connect() response = client.save_project("C:/Backup/project_backup.qgz") print(response["result"]["saved"]) ``` ```python # Save to current project path response = client.save_project() print(f"Project saved to: {response['result']['saved']}") ``` -------------------------------- ### Zoom Map to Layer Extent using MCP Tools and Client Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Demonstrates how to adjust the QGIS map canvas view to focus on a specific layer's extent. Examples are provided for the `zoom_to_layer` MCP tool function and the `zoom_to_layer` method of `QgisMCPClient`. The client example shows how to dynamically find a layer ID. Requires `ctx` for MCP tools and `QgisMCPClient`. ```python # MCP tool usage result = zoom_to_layer(ctx, layer_id="counties_a3c9e8f0") ``` ```python # Direct client usage client = QgisMCPClient() client.connect() project_info = client.get_project_info() first_layer_id = project_info["result"]["layers"][0]["id"] response = client.zoom_to_layer(first_layer_id) print(f"Zoomed to: {response['result']['zoomed_to']}") ``` -------------------------------- ### Remove Layer from Project using MCP Tools and Client Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Provides examples for removing a layer from the QGIS project by its ID. It showcases the `remove_layer` MCP tool function and the `remove_layer` method of `QgisMCPClient`. The client usage includes a preliminary step to get layer IDs. Requires `ctx` for MCP tools and `QgisMCPClient`. ```python # MCP tool usage result = remove_layer(ctx, layer_id="roads_7b2d4f91") ``` ```python # Direct client usage client = QgisMCPClient() client.connect() # First get layers to find the ID layers = client.get_layers() layer_to_remove = layers["result"]["id"] response = client.remove_layer(layer_to_remove) print(f"Removed layer: {response['result']['removed']}") ``` -------------------------------- ### Retrieve All Project Layers using MCP Tools and Client Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Shows how to get a list of all layers within the current QGIS project. Both the `get_layers` MCP tool function and the `get_layers` method of `QgisMCPClient` are demonstrated. The output includes layer name, type, visibility, and feature count for vector layers. Requires `ctx` for MCP tools and `QgisMCPClient`. ```python # MCP tool usage layers = get_layers(ctx) ``` ```python # Direct client usage client = QgisMCPClient() client.connect() response = client.get_layers() layers_list = response["result"] for layer in layers_list: print(f"{layer['name']}: {layer['type']} (visible: {layer['visible']})") if layer['type'].startswith('vector'): print(f" Features: {layer['feature_count']}") ``` -------------------------------- ### Python: Get Current QGIS Project Info Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Retrieves comprehensive information about the currently active QGIS project, including details about its layers, Coordinate Reference System (CRS), and metadata. This data can be accessed via MCP tools or directly using the QgisMCPClient. ```python # MCP tool usage info = get_project_info(ctx) ``` -------------------------------- ### Python: Get QGIS Info Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Retrieves version and profile details from the connected QGIS instance. This function can be invoked through MCP tools or directly via the QgisMCPClient, providing insights into the QGIS environment. ```python # MCP tool usage info = get_qgis_info(ctx) # Direct client usage client = QgisMCPClient() client.connect() info = client.get_qgis_info() print(json.dumps(info, indent=2)) # Output: # { # "status": "success", # "result": { # "qgis_version": "3.22.0-Białowieża", # "profile_folder": "C:/Users/USER/AppData/Roaming/QGIS/QGIS3/profiles/default", # "plugins_count": 12 # } # } ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Connect and Load QGIS Project with Client Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Demonstrates how to initialize the QgisMCPClient, establish a connection, and load a QGIS project file. It then retrieves and prints basic project information. Requires the QgisMCPClient class. ```python client = QgisMCPClient() client.connect() client.load_project("C:/GIS_Data/urban_planning.qgz") project_info = client.get_project_info() print(json.dumps(project_info, indent=2)) ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### load_project - Load Existing QGIS Project Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Loads a QGIS project file (.qgz or .qgs) from the specified file path. ```APIDOC ## load_project - Load Existing QGIS Project ### Description Loads a QGIS project file (.qgz or .qgs) from the specified file path. ### Method `load_project(path)` ### Endpoint N/A (Internal command) ### Parameters #### Path Parameters - **path** (string) - Required - The full path to the QGIS project file to load. ### Request Example ```python # MCP tool usage result = load_project(ctx, path="/home/user/projects/city_planning.qgz") # Direct client usage client = QgisMCPClient() client.connect() response = client.load_project("C:/GIS_Data/watershed_analysis.qgz") if response["status"] == "success": layer_count = response["result"]["layer_count"] print(f"Loaded project with {layer_count} layers") ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation, e.g., "success". - **result** (object) - Contains the result of the operation. - **layer_count** (integer) - The number of layers in the loaded project. #### Response Example ```json { "status": "success", "result": { "layer_count": 5 } } ``` ``` -------------------------------- ### create_new_project - Create and Save New Project Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Creates a new QGIS project, clearing any existing project, and saves it to the specified path. ```APIDOC ## create_new_project - Create and Save New Project ### Description Creates a new QGIS project, clearing any existing project, and saves it to the specified path. ### Method `create_new_project(path)` ### Endpoint N/A (Internal command) ### Parameters #### Path Parameters - **path** (string) - Required - The full path where the new QGIS project file (.qgz) will be saved. ### Request Example ```python # MCP tool usage result = create_new_project(ctx, path="C:/GIS_Projects/my_project.qgz") # Direct client usage client = QgisMCPClient() client.connect() response = client.send_command("create_new_project", { "path": "C:/Users/USER/Documents/QGIS/my_new_project.qgz" }) print(f"Project created: {response['result']['created']}") ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation, e.g., "success". - **result** (object) - Contains the result of the operation. - **created** (string) - A confirmation message indicating the project was created and saved, including the path. #### Response Example ```json { "status": "success", "result": { "created": "Project created and saved successfully at: C:/Users/USER/Documents/QGIS/my_new_project.qgz" } } ``` ``` -------------------------------- ### Untitled No description -------------------------------- ### Configure Claude Desktop MCP Server (JSON) Source: https://github.com/ethology-github/qgis_mcp/blob/main/README.md Configures the Claude desktop application to recognize and connect to the QGIS MCP server. This JSON snippet specifies the command and arguments to launch the QGIS MCP server using 'uv'. Ensure the path to 'qgis_mcp_server.py' is absolute. ```json { "mcpServers": { "qgis": { "command": "uv", "args": [ "--directory", "/ABSOLUTE/PATH/TO/PARENT/REPO/FOLDER/qgis_mcp/src/qgis_mcp", "run", "qgis_mcp_server.py" ] } } } ``` -------------------------------- ### Claude Desktop Configuration for QGIS MCP Source: https://context7.com/ethology-github/qgis_mcp/llms.txt This JSON configuration sets up the MCP server for QGIS. It specifies the command to run the QGIS MCP server script and its arguments, including the directory where the script is located. This allows Claude AI to communicate with and control QGIS. ```json { "mcpServers": { "qgis": { "command": "uv", "args": [ "--directory", "/absolute/path/to/qgis_mcp/src/qgis_mcp", "run", "qgis_mcp_server.py" ] } } } ``` -------------------------------- ### Untitled No description -------------------------------- ### Python: Create and Save New QGIS Project Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Creates a new QGIS project, discarding any current project, and saves it to a specified file path. This can be controlled via MCP tools or by directly sending a command to the QgisMCPClient. ```python # MCP tool usage result = create_new_project(ctx, path="C:/GIS_Projects/my_project.qgz") # Direct client usage client = QgisMCPClient() client.connect() response = client.send_command("create_new_project", { "path": "C:/Users/USER/Documents/QGIS/my_new_project.qgz" }) print(f"Project created: {response['result']['created']}") # Output: "Project created: Project created and saved successfully at: C:/Users/USER/Documents/QGIS/my_new_project.qgz" ``` -------------------------------- ### Untitled No description -------------------------------- ### Clone QGISMCP Repository (Git) Source: https://github.com/ethology-github/qgis_mcp/blob/main/README.md Clones the QGISMCP project repository from GitHub using the Git command-line interface. This is the standard method for obtaining the project's source code. ```bash git clone git@github.com:jjsantos01/qgis_mcp.git ``` -------------------------------- ### Python: Load Existing QGIS Project Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Loads a QGIS project file (supporting .qgz and .qgs formats) from a given file path. This operation can be triggered by MCP tools or directly through the QgisMCPClient, returning the layer count upon successful loading. ```python # MCP tool usage result = load_project(ctx, path="/home/user/projects/city_planning.qgz") # Direct client usage client = QgisMCPClient() client.connect() response = client.load_project("C:/GIS_Data/watershed_analysis.qgz") if response["status"] == "success": layer_count = response["result"]["layer_count"] print(f"Loaded project with {layer_count} layers") # Output: "Loaded project with 5 layers" ``` -------------------------------- ### ping - Check Server Connectivity Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Simple connectivity test to verify the QGIS server is running and responsive. ```APIDOC ## ping - Check Server Connectivity ### Description Simple connectivity test to verify the QGIS server is running and responsive. ### Method `ping()` ### Endpoint N/A (Internal command) ### Parameters None ### Request Example ```python # MCP tool usage (called by Claude) result = ping(ctx) # Direct client usage client = QgisMCPClient() client.connect() response = client.ping() assert response["status"] == "success" assert response["result"]["pong"] == True ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation, e.g., "success". - **result** (object) - Contains the operation's result. - **pong** (boolean) - True if the server is responsive. #### Response Example ```json { "status": "success", "result": { "pong": true } } ``` ``` -------------------------------- ### Untitled No description -------------------------------- ### Execute QGIS Processing Algorithm - Python Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Runs a QGIS processing algorithm with specified parameters. Supports direct client usage or MCP tool usage via `ctx`. Useful for batch geospatial analysis. ```python # MCP tool usage result = execute_processing( ctx, algorithm="native:centroids", parameters={ "INPUT": "layer_id_here", "OUTPUT": "C:/Output/centroids.geojson" } ) ``` ```python # Direct client usage - Buffer analysis client = QgisMCPClient() client.connect() response = client.execute_processing( algorithm="native:buffer", parameters={ "INPUT": "roads_layer_id", "DISTANCE": 100, "SEGMENTS": 5, "DISSOLVE": False, "OUTPUT": "C:/Analysis/road_buffers.shp" } ) print(f"Algorithm: {response['result']['algorithm']}") print(f"Output: {response['result']['result']['OUTPUT']}") ``` ```python # Centroid calculation response = client.execute_processing( algorithm="native:centroids", parameters={ "INPUT": "polygons_layer_id", "OUTPUT": "memory:centroids" # Store in memory } ) ``` -------------------------------- ### Untitled No description -------------------------------- ### Render Map View to Image - Python Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Exports the current QGIS map canvas to an image file. Allows specifying output path, width, and height. Useful for creating map visualizations and reports. Supports direct client usage or MCP tool usage. ```python # MCP tool usage result = render_map(ctx, path="C:/Maps/output_map.png", width=1920, height=1080) ``` ```python # Direct client usage client = QgisMCPClient() client.connect() # Load project and configure layers first client.load_project("C:/GIS_Data/city_map.qgz") response = client.render_map( path="C:/Export/city_map_export.png", width=3000, height=2000 ) if response["result"]["rendered"]: print(f"Map rendered to: {response['result']['path']}") print(f"Dimensions: {response['result']['width']}x{response['result']['height']}") # Output: # Map rendered to: C:/Export/city_map_export.png # Dimensions: 3000x2000 ``` -------------------------------- ### Add Raster Layer using MCP Tools and Client Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Demonstrates adding a raster layer to the QGIS project using the `add_raster_layer` MCP tool function and the `add_raster_layer` method of the `QgisMCPClient`. Requires `ctx` for MCP tools and `QgisMCPClient`. Inputs include the layer path, provider, and an optional name. ```python # MCP tool usage result = add_raster_layer( ctx, path="C:/Satellite/landsat_2024.tif", provider="gdal", name="Landsat 2024" ) ``` ```python # Direct client usage client = QgisMCPClient() client.connect() response = client.add_raster_layer( path="/data/elevation/dem.tif", name="Digital Elevation Model", provider="gdal" ) raster_info = response["result"] print(f"Raster dimensions: {raster_info['width']}x{raster_info['height']}") ``` -------------------------------- ### Python: Ping QGIS Server Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Performs a simple connectivity test to verify the QGIS server is running and responsive. This function can be called via MCP tools or directly using the QGISMCPClient. ```python # MCP tool usage (called by Claude) result = ping(ctx) # Returns: '{"status": "success", "result": {"pong": true}}' # Direct client usage client = QgisMCPClient() client.connect() response = client.ping() assert response["status"] == "success" assert response["result"]["pong"] == True ``` -------------------------------- ### QGIS Socket Client Source: https://context7.com/ethology-github/qgis_mcp/llms.txt Provides a direct Python interface to communicate with the QGIS plugin server. ```APIDOC ## QGIS Socket Client ### Description Provides a direct Python interface to communicate with the QGIS plugin server without going through the MCP layer. ### Method N/A (Class Usage) ### Endpoint N/A (Direct Connection to localhost:9876) ### Parameters N/A (Class Initialization) ### Request Example ```python from src.qgis_mcp.qgis_socket_client import QgisMCPClient import json # Initialize and connect to QGIS server client = QgisMCPClient(host='localhost', port=9876) if not client.connect(): raise ConnectionError("Could not connect to QGIS MCP server") # Verify connection response = client.ping() print(json.dumps(response, indent=2)) # Get QGIS installation information qgis_info = client.get_qgis_info() print(f"QGIS Version: {qgis_info['result']['qgis_version']}") # Cleanup client.disconnect() ``` ### Response #### Success Response (200) - **response** (object) - The JSON response from the QGIS server. #### Response Example ```json { "status": "success", "result": { "pong": true } } ``` ``` -------------------------------- ### Untitled No description === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.