QGIS Python (PyQGIS) - Calculate Field Values (Field Calculator)

  Рет қаралды 13,726

Geospatial School

Geospatial School

4 жыл бұрын

Learn to add fields to a vector layer and populate attribute fields with the QGIS Python (PyQGIS) API. This tutorial will take you through an example of adding fields to a vector layer and calculating a field value from existing fields. Additionally, you will learn how to troubleshoot common problem you may experience.
Visit opensourceoptions.com for more content and courses

Пікірлер: 21
@jalineliam4567
@jalineliam4567 3 жыл бұрын
Just what I needed, thank you!
@geospatialschool
@geospatialschool 3 жыл бұрын
Happy to help!
@mteixeira87
@mteixeira87 3 жыл бұрын
Just what I needed, thank you![2]
@geospatialschool
@geospatialschool 3 жыл бұрын
You're welcome!
@PLRaeva
@PLRaeva 4 жыл бұрын
Hi. Thank you for the videos. I really appreciate it that they are focused on geospatial analysis. I also like the way you 'make mistakes'. It teaches me even more. Keep the good work going. Thank you!
@geospatialschool
@geospatialschool 4 жыл бұрын
Glad you like them!
@sriramab
@sriramab Ай бұрын
Hi, Is there a group by and summarize possibility on vector attribute table using pyqgis?
@trunghieubui4896
@trunghieubui4896 4 жыл бұрын
Hi Mr. Konrad, Please help me, How can i concatenate two field by field calculator
@miidrob
@miidrob 3 жыл бұрын
genial....! thanks
@geospatialschool
@geospatialschool 3 жыл бұрын
You're welcome!
@GIS-Engineer
@GIS-Engineer 4 жыл бұрын
How to kml convert shapefile. Kml have table tag.
@MerlinMalin
@MerlinMalin 4 жыл бұрын
Thank you for this video. I used the method to create a map for which i needed to include a set of almost 200 expression. I'm still quite new to PyQGIS. Is there a way to create a list of all the defined expressions and afterwards loop over them? I don't want to copy-paste this code 200 times: with edit(layer): for f in layer.getFeatures(): context.setFeature(f) f['NewVariable'] = expression1.evaluate(context) layer.updateFeature(f) I appreciate any hint or answer! Thank you in advance!
@geospatialschool
@geospatialschool 4 жыл бұрын
Yes. You will need to create a list that has all your expressions as strings, and a list that has the names of the new fields to create. Then you can create another loop after context.setFeature that loops through the expression strings, creates a QgsExpression then evaluates the expression. So you'll have to move around the order of the code from the video a little bit, but you should be able to do it.
@driesdams4093
@driesdams4093 3 жыл бұрын
Thanks a lot Konrad! Can you please make a video on conditional statements (if, elif, else) in the pyQGIS console?
@geospatialschool
@geospatialschool 3 жыл бұрын
Hi Dries. I'll put it on my list but I'm not sure when I'll be able to get to it. Condition statements in PyQGIS are going to work the same way as conditionals in regular Python. So if you need to figure something out quickly check out regular Python tutorials.
@driesdams4093
@driesdams4093 3 жыл бұрын
@@geospatialschool Thanks for the answer! :)
@iqbaltriputra628
@iqbaltriputra628 4 жыл бұрын
Hi Mr. Konrad, How if we want to calculate using the existed field/column of the layer?
@geospatialschool
@geospatialschool 4 жыл бұрын
You can use the same procedure. You just won't need to create any new fields.
@allanmazimwe7417
@allanmazimwe7417 4 жыл бұрын
Hi how do i run this in qgis3 processing script??
@geospatialschool
@geospatialschool 4 жыл бұрын
Just as shown in the video. Once you have a vector layer variable you can access, create, and calculate attributes the same way.
@allanmazimwe7417
@allanmazimwe7417 4 жыл бұрын
@@geospatialschool well this script works on python console data='/home/geoportal/qgis/lizmapwps/lizmap/instances/VulnerabilityTool/data1/default_vulnerability.shp' ​ #layer= QgsVectorLayer(data, 'dd', 'ogr') layer= iface.addVectorLayer(data, 'dd', 'ogr') ​ pv=layer.dataProvider() pv.addAttributes([QgsField('rawvul', QVariant.Double),\ QgsField('customvul', QVariant.Double)]) ​ layer.updateFields() expression1=QgsExpression('"LoACapacit" * 0.33 + "sensitivit" * 0.44 + "exposure" * 0.27' ) expression2=QgsExpression('expression1-minimum(expression1)/(maximum(expression1)-minimum(expression1))') context = QgsExpressionContext() context.appendScopes(QgsExpressionContextUtils.globalProjectLayerScopes(layer)) ​ with edit(layer): for f in layer.getFeatures(): context.setFeature(f) f['rawvul'] = expression1.evaluate(context) f['customvul'] = expression2.evaluate(context) layer.updateFeature(f) with edit(layer): for f in layer.getFeatures(): context.setFeature(f) f['customvul'] = expression2.evaluate(context) layer.updateFeature(f) # however i would like to change it to qgsProcessing script .. am stuck at this... pleasse help please....
QGIS Python (PyQGIS) - Raster Calculator in a Python Script
14:35
Geospatial School
Рет қаралды 10 М.
QGIS Python (PyQGIS) - Add layer to a map layout
13:50
Geospatial School
Рет қаралды 12 М.
这是王子儿子吗
00:27
落魄的王子
Рет қаралды 20 МЛН
Spot The Fake Animal For $10,000
00:40
MrBeast
Рет қаралды 196 МЛН
Survive 100 Days In Nuclear Bunker, Win $500,000
32:21
MrBeast
Рет қаралды 114 МЛН
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 28 МЛН
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
pixegami
Рет қаралды 256 М.
QGIS User 0025 - Complex Labels
17:11
Klas Karlsson
Рет қаралды 22 М.
Stop, Intel’s Already Dead!
13:47
Linus Tech Tips
Рет қаралды 200 М.
QGIS Field Calculator Basics
15:07
Samara Ebinger
Рет қаралды 62 М.
QGIS Python (PyQGIS) - Create features (point)
10:04
Geospatial School
Рет қаралды 11 М.
QGIS Python (PyQGIS) - Loading and symbolizing vector layers
18:22
Geospatial School
Рет қаралды 16 М.
QGIS User 0021 - Dynamic Layout Calculations
20:34
Klas Karlsson
Рет қаралды 12 М.
The moment we stopped understanding AI [AlexNet]
17:38
Welch Labs
Рет қаралды 860 М.
QGIS Python - Use Processing Tools in a Python Script
7:23
Geospatial School
Рет қаралды 24 М.
Bluetooth connected successfully 💯💯
0:16
Blue ice Comedy
Рет қаралды 2 МЛН
iPhone 15 Pro в реальной жизни
24:07
HUDAKOV
Рет қаралды 503 М.
Ускоряем ваш TV🚀
0:44
ARTEM_CHIBA
Рет қаралды 418 М.
My iPhone 15 pro max 😱🫣😂
0:21
Nadir Show
Рет қаралды 1,9 МЛН
Looks very comfortable. #leddisplay #ledscreen #ledwall #eagerled
0:19
LED Screen Factory-EagerLED
Рет қаралды 13 МЛН
Новые iPhone 16 и 16 Pro Max
0:42
Romancev768
Рет қаралды 2,4 МЛН