I would like to determine whether a polygon could or could not fit inside another polygon. This latter polygon can be translated arbitrarily. A Python example:
from shapely.geometry import Polygon import geopandas as gpd p = Polygon([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]) q0 = Polygon([[1.5, 1.6], [2, 1.6], [2, 2],[1.5, 1.6]]) q1 = Polygon([[1.4, -0.45], [1.6, -0.45], [1.95, 1.4], [1.4, 1.4], [1.4, -0.2]]) q2 = Polygon([[1.1, -0.05], [1.2, -0.05], [1.2,1.05],[1.1,1.05],[1.1,-0.05]]) gpd.GeoSeries([p,q0,q1,q2]).plot(color=['r','g','b','y'],alpha=0.5)
Clearly, the red square (
p0) can be translated to contain the green triangle (
q0). The blue trapezoid (
q1) and the yellow rectangle (
q2) cannot be contained, no matter how we translate the square. (Rotation is not allowed in this example.) Given GeoSeries:
qs = gpd.GeoSeries([q0,q1,q2])
p, I am looking for function
does_it_fit, which, when applied to
qs.geometry.apply(lambda row: does_it_fit(row,p))
0 True 1 False 2 False dtype: bool
def does_it_fit(q,p): ### what comes here? ### return result
Related but different questions:
how to fit polygon inside another polygon [closed]: here polygons are allowed to be rotated too
How to determine if one polygon is contained in another?: translations not allowed. Not in Python.
How to judge if a polygon is inside another polygon in Python?: translations not allowed
What algorithms can I use to check if a polygon fits inside of another polygon?: rotation also allowed, unlike in my case.
This problem was inspired by the interesting task of finding parcels on a map which can contain a building with certain size & orientation. Notebook to play with the above example here.