I have one layer with polygons (say, countries) and one layer with x and y coordinates of points (say, cities).
Now, for the city table, I want a new column giving me the id of the country it lies in. I believe the general approach would be to create a new field and then use the field calculator, either of the within or contains function and a loop, like this:
Is City A in Country A? No.
Is City A in Country B? No.
Is City A in Country C? Yes. --> Note down ID.
Is City B in Country A? And so forth.
However, I cannot figure out how to write the code. How do you use these functions if your inputs are from different layers/attribute tables? How to specify the point input since it consists of an x and a y variable? Does anyone have a Python code example for how s/he used the within or contains function?