I have a map that is divided into unequally sized cells. I want to find out which cell a point belongs to. For a grid where the cells are equally shaped, this is fairly simple. However, how do I solve the problem where the cells are unequal?
Specifically: given a pandas dataframe of cells d, with each row of the dataframe containing the index of the cell, the northwest and southeast x,y coordinates, and given px and py, the coordinates of the point we want to investigate, find out which row of the dataframe i.e. which cell the point belongs to.
I tried computing the distance to the center of each cell and assigning the point to the closest center’s cell, but that doesn’t work for points that are near the boundaries of large cells and close to the center of smaller ones.
Edit 1: A single row in a dataframe looks like:
cellID southeastX southeastY northwestX northwestY
and I compute sqrt((px-((southeastX+northwestX)/2))**2+(py-((southeastY+northwestY)/2))**2) for all rows. Whichever cell index has the lowest distance is the cell I assign it to.
>Solution :
Given that the cells are rectangular, the condition that a point is inside a particular cell is
( northwestX < px < southeastX ) and ( southeastY < py < northeastY )