Gains:
- Ability to use AI in code and workflow generation for spatial data processing with QGIS and Python (libraries such as GeoPandas)
- Ability to test the spatial code produced by AI on small sample data and verify it against coordinate system and geometry errors
- Ability to understand data confidentiality and the need to check the AI-generated script before running it on real project data.
Repetitive spatial tasks in a planning unit (trimming layers, drawing buffers, calculating areas, combining tables) take hours and produce errors when done manually. There are two powerful, free and open source tools that automate these tasks: QGIS (a desktop GIS software) and Python (a programming language with libraries for spatial data such as GeoPandas, Shapely, Rasterio). AI is incredibly fast at generating code and workflow for these tools: it drafts a working script from a one-sentence request. But AI writes code with assumptions you can't see — wrong coordinate system, wrong unit, an operation that silently deletes elements. That's why every spatial code that AI produces must be read and tested on a small sample before being run on real project data. This unit teaches safe spatial automation with AI, even if you don't know how to code.
Why QGIS and Python
QGIS lets you analyze by clicking; It is easy to learn and includes a Python console. Python, on the other hand, allows you to write repetitive tasks once and run them in hundreds of files. GeoPandas is the most practical library for planners, combining tabular data (pandas) with geography: reads layers, filters, draws buffers, calculates areas with one line of code. AI writes GeoPandas code very well; But code that looks good isn't always the right code.
Caution: A script written by an AI can run without error and still produce completely wrong results. “Worked” and “correct” are two different things. Validation is not that the code fails to fail, but that the result matches a known reference.
Another important concept is reproducibility: an analysis you make in a public institution should be able to be repeated with the same steps by someone else months later. Actions made by clicking manually are not remembered and cannot be audited; whereas a Python script is both a record of the work and reproduces the same result. Storing the code you produce with AI along with its comments strengthens both accountability and corporate memory. So aim for "readable, commented and stored code", not "working code". A good habit is to add a short description block at the beginning of each script, stating what data it runs on, on what date, and for what purpose.
Golden rules of generating code with AI
- Give the context. File format, CRS, column names, what you want to do.
- Ask for small. A shortcode that does a single job is safer than a giant script.
- Ask for clarification. Print to the AI what each line of code does; Don't run code you don't understand.
- Test it on the sample. First try it on a sample data of 10-20 records.
- Compare with reference. Compare an area/distance to a known value.
- Back up. Never overwrite master data; work in copy.
Step by step: A secure spatial script with AI
- Clarify the task. "Select green areas from the parcel layer, calculate their areas, write the area above 5000 m² into a separate file."
- Identify the data. Format (GeoPackage/Shapefile), CRS, relevant column name.
- Print code + description to AI. Comment line by line.
- Have CRS and unit control done. Area in m² or layer in metric CRS?
- Run on sample data. Check the result visually.
- Verify with a reference. Compare the area of a parcel to its title deed value.
- Run it on the master data, write the output to the new file.
Weak prompt / Strong prompt
Weak prompt: "Calculate area of parcels."
AI writes without knowing the coordinate system, format and column; The field may appear in the wrong unit or the wrong CRS.
Strong prompt: "With GeoPandas, read a GeoPackage layer ('parcels.gpkg', a metric national system such as CRS: EPSG:5254) and write the area of each parcel in m² into a new 'area_m2' column. Comment each line of the code. Add a line before the area calculation that checks that the layer is in a metric CRS; warn if it is not. Write the output to a new file, do not change the original."
The second prompt produces auditable, secure code because it contains CRS, unit, secure output, and description.
Four copyable templates
Task: Write a short Python code that does the following task with GeoPandas. Comment each line in Turkish. Action: [...]Input file: [...] (format, CRS: [...], relevant column: [...])Rule: Do not change original file, write output to NEW file.Check CRS is metric before operation; If not, warn.
Task: Explain the following Python/GeoPandas code line by line and mark the RISKS: which line can delete/overwrite data, which operation assumes CRS or volume, which step would be slow on big data. Changing the code; just explain and warn.Code: [...]
Task: Write a small TEST plan before running this code on real data. With what sample data, with what expected result, with what reference value should it be validated? Give a checklist. Code/action: [...]
Task: Describe the following QGIS action (click steps) as both the QGIS menu path and the equivalent Python/GeoPandas code. Specify differences and points of interest (CRS, unit).Process: [...]
A table: frequent spatial operations and their pitfalls
transaction
What does
Trap in AI code
verification
Field account
Finds polygon area
Field is meaningless in Geographic CRS
Comparison with known area
Buffer
region around the border
Unit (degree/meter) error
Metric CRS + measurement
spatial aggregation
Associates layers
Incorrect key/duplicate registration
Record count control
Clip
cuts with area
Out-of-bounds data loss
Compare input/output
reprojection
CRS replaces
Wrong target CRS
EPSG code confirmation
three mini cases
Case 1 — Silent overwriting. A planner runs a script written by the AI directly on the base layer. The code incorrectly applies a filter, deletes half of the layer, and saves it in the same file. Because there is no backup, data that lasts for days is lost. Lesson: output always to new file, master data always redundant.
Case 2 — Buffer with wrong unit. One team requests a 500-foot access buffer to schools. AI code runs on geo CRS; The 500 "degree" buffer covers the entire map. Since the team tests on a small sample, it catches the error before it passes into the main data; Adds and fixes projection to metric CRS. The habit of testing prevents disaster.
Case 3 — Explanatory learning. A planner who doesn't know code produces a join code by having the AI interpret each line. He sees "this row drops unmatched records" in the description and realizes this will lose some parcels; It asks the AI for a version that also keeps non-matches. Understanding the code is a prerequisite for using it safely.
Common mistakes
- Running directly on master data. Always work on the copy, writing the output to the new file.
- Mistaking "worked" for "correct". Error-free code may produce incorrect results; Verify with reference.
- Assuming CRS and volume. Always check the metric CRS for area and distance operations.
- Running code you don't understand. It's risky to run it without asking for explanations and without knowing what the lines do.
- Skip the little test. Switching to big data without trying sample data is the most common source of error.
- Giving confidential data to cloud devices without thinking. Do not share real parcel/person data when generating code; Use sample/anonymous data.
In summary
QGIS and Python (especially GeoPandas) automate repetitive spatial tasks in planning; AI quickly generates code for these tools. But AI writes code with assumptions you can't see: wrong CRS, wrong volume, operations that silently delete data. Safe usage is based on six rules: give context, ask for a small, get clarification, test in example, verify by reference, back up. “Worked” is not the same as “correct.” Even if you don't know code, you can do secure spatial automation with AI by understanding every line and without sharing confidential data.
Application task
Choose a repetitive spatial task (e.g. calculating areas in a layer and separating the top of a threshold). (1) Print code + line description to AI with first template. (2) Check the risks of the same code as the second template and find at least one "may erase data/assumes CRS" line. (3) Output a test plan with the third template: which sample data, which reference value. (4) Write down three security steps you will take before running the code on real data.
checklist
- [ ] I gave AI the format, CRS and column context.
- [ ] I explained every line of the code; I didn't run code I didn't understand.
- [ ] I wanted short, single-function code.
- [ ] I tested it on small sample data and visually checked the result.
- [ ] I verified the result with a known reference value.
- [ ] I have backed up the master data; I wrote the output to the new file.
- [ ] I did not give the actual confidential data to the cloud appliance; I used anonymous/sample data.