TransWikia.com

Add new field in a point layer with an attribute from another layer in QGIS

Geographic Information Systems Asked by Jesús Pinilla on March 14, 2021

I’m working with QGIS 3.16 Hannover under MacOS 10.13 environment. I’ve got a point and a polygon shapefile layers. I want to add a new field to my point layer with the id of the polygon that contains it. Is it possible to do so with the field calculator, instead of creating a new layer?

2 Answers

You can use refFunctions plugin. It adds custom user functions to QGIS Field Calculator. Then, you can add a new field to the point layer with the id of the polygon that contains it using the following expression in Field Calculator for the point layer:

geomwithin( 'polygon_layer_name', 'id_field_of_polygon_layer' )

enter image description here

Correct answer by Kadir Şahbaz on March 14, 2021

There is also a possibility without need to install a plugin, simply using this expression (available since QGIS 3.16):

array_to_string (overlay_within('polygon', id))

Add the function to_int () to get an integer instead of a string as output type.

enter image description here

Answered by Babel on March 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP