Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Finding which cell a point belongs to given that the cells are not of the same size

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading