I have two polygon layers, layer A and layer B. Layer B polygons are much bigger than layer A polygons. Now, some of the little polygons from layer A are located in the big polygons from layer B, and some are not. And so, for those little polygons from layer A that are located within the big polygons from layer B, some of those little layer A polygons will be located within different big polygons from layer B. That is the setting here.
Each layer A polygon has a unique Object ID. Same with the layer B polygons.
What I want to do is create a new column in the layer A attribute table called "B_ID".
In this column, and so for each layer A polygon/row, I want to enter the object ID of the layer B polygon it is located within. And so let's say Polygons 24 and 55 from layer A are both located within polygon 75 from layer B. Those rows in the layer A attribute table for polygons 24 and 55 would then show a "75" value under the "B_ID" column. And then, if a polygon from layer A happens to not be located within any layer B polygon, then just it would just show a "FALSE" or "N/A" or some rejection-value for that row under the "B_ID" column.
Here is a diagram example of what I am trying to accomplish:
From this I want to produce the following dataframe/table for layer A:
Object_ID B_ID ------------------------------------ 0 ? 1 ? 2 ? 3 ? ... 24 75 ... 33 N/A ... 36 N/A ... 41 N/A ... 55 75 56 73 57 73 58 73 ... 61 76 62 ? 63 ? 64 ? ...
And so we see which polygons from layer B the polygons from layer A are located within.
How can this be approached in Python? I am thinking this will need to involve the .intersects() function, but I am confused how to reference location within polygons from a different layer and reference it back to the original layer. I am generally confused how to tell Python what exactly to intersect and how to pull the appropriate object ID from layer B.