How to group objects by distance from edge of another object

How to group objects by distance from edge of another object

Hi, 

I am trying to find a way to sort particles within a larger object in my image by how close they are to the edge of the object in which they are contained. 

For example, I have a square (with rough edges) and all the particles are within the square. I have the square set as layer 1 and the particles set as layer 2. I want to be able to idenitfy how far each layer 2 particle is from the edge of the layer 1 square - and then be able to take measurements such as % area for the particles within a certain distance from the edge of the square. 

Thank you!