2

I have a list of our sales lead locations in Excel with their coordinates.

What I wish to do is that I need to sort those coordinates as per the condition if they lie within a certain polygon or not. So suppose I have two polygons for two cities then I need to mark the coordinates in the sheet like they’re in polygon 1 or 2 or NIL.

I had been doing this manually in QGIS by selecting the points outside polygons and deleting them and then exporting and then again sorting the sheet but this is now taking a lot of time since the number of entries is increasing.

Could someone suggest a better, simpler and quicker way to do this, irrespective of the method used? I don’t care if, as per your suggestion, it can be done in Excel itself, QGIS, or with the help of some other software. I need to mark in the next column to which polygon the coordinates belong.

input image

output image

5
  • 2
    Run join attributes by location and discard all points which had no attributes joined. Or select by location all points falling within a polygon, then reverse the selection and discard all now selected points.
    – Erik
    Commented Oct 25, 2023 at 15:17
  • select by location? youtube.com/watch?v=CU1A86JJMIk
    – Mapperz
    Commented Oct 25, 2023 at 15:17
  • This is what i was doing till now. But it isnt feasible. Since if lets say I have 10 polygons, then I have to repeat the steps 10 times. I was looking further into ways currently, so heres the update, in QGIS, I have one layer of the coordinates, imported form a delimited (CSV) file. Two layers of polygons of two cities. Now if you go to properties of the points layer > Fields > Field Calculator, there's an option to set output fields there, and you can enter a expression/function in the same to set the output. So could someone tell what we can enter in the expression field.
    – VVstack43
    Commented Oct 25, 2023 at 16:48
  • If you export the points layer, then the output field set is present in the exported file. So if in this output field, we can set some expression to mention the polygon/layer name, then it will solve the problem.
    – VVstack43
    Commented Oct 25, 2023 at 16:49
  • 4
    Using overlay_intersect should work, see this for a related exemple : gis.stackexchange.com/questions/466752/…
    – J.R
    Commented Oct 25, 2023 at 17:26

1 Answer 1

3

I mocked up some input data similar to yours, and loaded it as Lat/Lon using Add Layer -> Add Delimited Text Layer...:

enter image description here

I loaded a layer of Indian states/territories since I don't have your particular polygon data:

enter image description here

I then used the Field Calculator to add a Polygon field of output type = Text using the following expression. overlay_intersects('Indian_States',"Name",limit:=1)[0]

enter image description here

Output seems to be what you are looking for:

enter image description here

5
  • Hi Tom, Your answer seems quite perfect for the problem. However, when I tried the same, I couldnt get the output. I have 3 layers currently one for points 2 for polygons. Now in the expression part, how do I include the two polygons in the expression? I've attached photos of the layer and edited expression for reference. drive.google.com/drive/folders/…
    – VVstack43
    Commented Oct 26, 2023 at 9:43
  • I tried multiple ways. But couldnt get the name of the layer in polygon output. At max I was able to get either true & false or 1 & 0. Also, this was for one layer only. Was unable to include two or more layers.
    – VVstack43
    Commented Oct 26, 2023 at 10:56
  • Looks like you have the output type set to Integer - it needs to be Text if you want the name Commented Oct 26, 2023 at 19:58
  • 3
    Is there a reason that you need two polygon layers? If there's no difference other than the polygons, you could merge the two layers into one. Otherwise, remember to update the original question with that fact. Screenshots and links to actual data will also help get the best answer Commented Oct 26, 2023 at 20:02
  • Ok I merged the polygon layer and I found the error. The issue was not in the points layer or expression. It was in the polygon layer. It had a default "id" field of integer and when creating polygon I assigned the id as 1. Hence it was giving output of 1. I changed it to string and then while creating polygons in the same layer, I named them as per their cities and then exported. So it worked. The expression {overlay_intersects('polygon_layer_name',"Name",limit:=1)[0]} you gave was correct. Thanks a lot.
    – VVstack43
    Commented Oct 27, 2023 at 5:54

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.