In QGIS, I have one layer (called 'All data shapefile') which is a shapefile with my entire set of data, and another layer (called 'Y_data') that is also a shape file with a subset of 'All data shapefile'. The subset was determined by making a buffer around certain key data points and extracting all data points within 100m radius of the key points to make this second layer.
In the 'All data shapefile' layer I have a column named 'ID' which gives a unique number ID for each datapoint, however I added this column after creating 'Y_data', so the latter layer does not have the ID column.
How do I append the 'ID' column into the 'Y_data' layer, ensuring that each data point will have the same ID in both layers (i.e. each data point is given its correct ID as determined by 'All data shapefile')?
When I try to use 'Join', the pictures indicate what I end up with in my 'Y_data' attribute table:
Best Answer
Version A: Join attributes by location
Use
Menu Processing / Toolbox / Join attributes by location
. Settings to make (red highlighted on the screenshot):Y_data
asBase layer
andAll data shapefile
asJoin layer
intersects
Join type
, selectTake attributes of the feature with largest overlap only (one-to-one)
.Optional settings (yellow on the screenshot):
Fields to add (leave empty to use all fields)
: select theID
-field.Joined field prefix
to better distinguish the initial attributes from the ones added by the join operation.Version B: field calculator
You could also create a new field with field calculator on the layer
Y_data
and this expression: