11

Introducing QGPT Agent: The Ultimate Plugin for QGIS

 11 months ago
source link: https://joets.medium.com/introducing-qgpt-agent-the-ultimate-plugin-for-qgis-20c08e21cc7
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

AI GIS

Introducing QGPT Agent: The Ultimate Plugin for QGIS

QGIS 🗺️+ QGPT Agent 🤖

1*Iko8m0kzMkdf-wRsigGihw.png
Image created by DALL·E

Say hello to QGPT Agent, the revolutionary new plugin that lets you control QGIS with natural language commands. 🤩 Powered by OpenAI’s GPT natural language processing technology, QGPT Agent will streamline your workflow and make it easier than ever to complete GIS tasks. 🤖

Installation:

  1. Open QGIS and go to the “Plugins” menu.
  2. Select “Manage and Install Plugins”.
  3. In the “All” tab, search for “QGPT Agent”.
  4. Click on “Install Plugin” to install QGPT Agent.

Hint: Make sure you enable “Show also Experimental Plugins” in your Plugins Settings

1*ZUf2FdEuhdDQ09xeSSDGmw.png
Screenshot by Author

Usage:

Just click on the QGPT Agent icon on your QGIS toolbar.

1*LLsefx2TDGNt03zF0tCtZg.png
Screenshot by Author

Example 1: Download Open Source Data

Prompt: “Download the World country polygon and open it.”

1*Whpd3011HI9BWYYNK1nqTg.png
Screenshot by Author

And, that’s it! Impressive.

After prompting in a command, the QGPT Agent uses OpenAPI to automatically write a Python script for the task based on PyQGIS, run it, and show the result in your QGIS Window directly.

If you wonder, how the Python script generated from QGPT looks like. Just select an option to show the script in the settings.

For example, this is the generated Python script from the above command:

import urllib.request
import tempfile

# Download the world country polygon
url = 'https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_0_countries.zip'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
req = urllib.request.Request(url, headers=headers)
response = urllib.request.urlopen(req)

# Save the file to temp directory
temp_dir = tempfile.gettempdir()
file_name = temp_dir + '/ne_10m_admin_0_countries.zip'
with open(file_name, 'wb') as f:
f.write(response.read())

# Open the file
iface.addVectorLayer(file_name, 'World Country Polygon', 'ogr')

Let’s do Another Try with more complex input:

Example 2: Download Open Source Data (2)

Prompt: “Download building footprint data from OSM in the area of Esslingen, Germany and then open it

1*UxhmS1Mn6UcoOv2xJCGqUg.png
Screenshot by Author

It is good enough. Let’s check…

This is the script QGPT generated in the backend:

import urllib.request
import tempfile

# Set the user agent
user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'

# Set the URL
url = 'https://overpass-api.de/api/map?bbox=9.14,48.7,9.25,48.78'

# Set the headers
headers = {'User-Agent': user_agent}

# Create the request
req = urllib.request.Request(url, headers=headers)

# Open the URL
response = urllib.request.urlopen(req)

# Read the response
data = response.read()

# Save the response to a file
temp_dir = tempfile.gettempdir()
file_name = 'building_footprint_data.osm'
file_path = temp_dir + '/' + file_name

with open(file_path, 'wb') as f:
f.write(data)

# Open the file
iface.addVectorLayer(file_path, 'Building Footprint Data', 'ogr')

And you can see that QGPT tries its best to use Python script to download OSM data. The BBOX of the area is generated automatically and used as an input to query OSM data from Overpass API.

However, it does not fully fulfil the command by skipping the feature type filtering as we specify to query only the “Building Footprint”.

Example 3: Basic Map Data Interaction

Prompt: “Change current CRS to 3857”

1*OK7wgs5xtW9e_o6JMN1oPQ.png
Screenshot by Author

Prompt: “From the World Countries Layer, filter only 5 most population countries based on the ‘POP_EST’ field.”

1*h21kYn-9VTZYEq9DYCP6mA.png
Screenshot by Author

Prompt: “Remove World Country Polygon Layer”

1*UwJ7P_7n3j3oCNkFWks7sQ.png
Screenshot by Author

From the examples above, the QGPT can do basic map data interactions like filter and summarize by field and export very well.

Conclusion

The QGPT plugin has the potential to revolutionize GIS tasks in QGIS. Its ability to quickly download Open Source data of any city or country, filter data and other basic mappings has already demonstrated its usefulness. Though it is still in its infancy, with further development, I believe this AI-GIS concept should be capable of performing most GIS tasks, greatly increasing the efficiency of GIS Analysts.

Now it is your turn. You are encouraged to try it!

About me & All my blog content here.

Wanna chat with me? Contact me via LinkedIn.

Be Safe and Healthy!
Thank you for Reading. 👋😄


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK