A naive solution would be to loop over all the rectangles and check if you are in it. Checking for one rectangle is simple (if you want, I will write it explicitly).
If you have a lot of rectangles and care about performance, you can easily speed up the process by placing the rectangles in the data structure, which will look faster. Looking at the image you sent, one obvious property of your data is that there is a limited number of vertical positions (βrowsβ) there. This means that if you check which line you are on, you only need to check the rectangles inside that line. Finally, to choose which row you are in or inside the row, select which rectangle, save the sorted data structure (for example, some search tree).
Thus, your data structure may be something like a search tree for a row, where each node contains a rectangle search tree along the row.
source share