2

I am using QGIS 3.24.0. I have a shapefile, called "Map_CorrectionDEF, in which one of the fields is "unitcode". On the other hand, I have a CSV file, called crop_main (no geometry), in which one of the fields is "unitcode". I would like to merge them through the field "unitcode".

I do the following:

enter image description here

However, in my CSV file, there is a variable in which I am interested which is called "cropclass". This variable takes different values within the values of variable "unitcode". For example, for "unitcode" = 12000, it takes values 7 and 16. But when I do the merge, the final output only merge the values when it takes 16. I am not understanding why. This happens several times. It just an example that I show now with picture:

CSV file:

enter image description here

Final output in the Attribute table of my shapefile after doing the join:

enter image description here

[I edit to make clear what is the goal and make it clear why join does not work]

The values from variable "unitcode" in my shape file appears several times. It's a grid cell and the "unitcode" says the country in which the cell belongs. So, all the cells in the same country has the same value of "unitcode". For each cell, which has an associated value of "unitcode", I would like to join every value of my csv file which has the value of "unitcode". More specific, if cell 1 which has a value of "unitcode" 12000, I would like to join all the observations which appears in my csv value where the "unitcode" is equal to 12000.

1 Answer 1

8

QGIS joins are either 1:1 or Many:1. Your join table contains more than one mapping from unitcode=12000 to cropclass but only one of those will be picked up in a join. See https://psqgis.org/joins.html. Perhaps you need to use a relate, discussed at the same link, but that depends on your application.

2
  • Thank you @hgb. I have updated the question with the goal. According to that and to the link you sent to me, should I use a 1:many?
    – OgeiD
    Commented Apr 14, 2022 at 6:40
  • 1
    @OgeiD, your update still doesn't explain what you intend to do once you connect (to avoid the "join" and "relate" terminology) those cropclass records. If you only want to interactively examine the results, then using a relate (1:many) and the identify tool, as described by the link in my answer might be fine. If you want to map a summary of all cropclass records, possibly with yields or other information, then multiple records will be limiting and getting information for each cropclass into its own column in a single record may be more useful. Experiment - then maybe ask a new question.
    – hgb
    Commented Apr 14, 2022 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.