Тёмный

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

Geospatial School
Подписаться 25 тыс.
Просмотров 14 тыс.
50% 1

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

Наука

Опубликовано:

 

18 ноя 2019

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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
@GIS-Engineer
@GIS-Engineer 4 года назад
How to kml convert shapefile. Kml have table tag.
@miidrob
@miidrob 3 года назад
genial....! thanks
@geospatialschool
@geospatialschool 3 года назад
You're welcome!
@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.
@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! :)
@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....
Далее
ПАЛОЧКА В НОС (СЕКРЕТ)
00:40
Просмотров 93 тыс.
QGIS Python (PyQGIS) - Add layer to a map layout
13:50
Google Data Center 360° Tour
8:29
Просмотров 5 млн
More QGIS Field Calculator Basics
9:48
Просмотров 7 тыс.
QGIS Field Calculator Basics
15:07
Просмотров 62 тыс.
QGIS User 0021 - Dynamic Layout Calculations
20:34
Просмотров 12 тыс.
Копия iPhone с WildBerries
1:00
Просмотров 8 млн