def interiorPoint(shapely_polygon): def dih(a, b): print((a, b)) if (a >= b - 1): return a c = (a + b) / 2 p = shapely_polygon.buffer(-c) if (p.area == 0): return dih(a - 1, c) else: return dih(c, b) threshold = dih(1,50) p = shapely_polygon.buffer(-threshold) print((threshold, shapely_polygon.area, p.area)) cp = Polygon() cp.addContour(p.exterior.coords, False) for i in p.interiors: cp.addContour(i.coords, True) while True: ip = cp.sample(random.random) int_point = (int(round(ip[0])), int(round(ip[1]))) if (shapely_polygon.contains(Point(int_point))): return int_point
def interiorPoint(shapely_polygon): def dih(a, b): print a, b if (a >= b - 1): return a c = (a + b) / 2 p = shapely_polygon.buffer(-c) if (p.area == 0): return dih(a - 1, c) else: return dih(c, b) threshold = dih(1, 50) p = shapely_polygon.buffer(-threshold) print threshold, shapely_polygon.area, p.area cp = Polygon() cp.addContour(p.exterior.coords, False) for i in p.interiors: cp.addContour(i.coords, True) while True: ip = cp.sample(random.random) int_point = (int(round(ip[0])), int(round(ip[1]))) if (shapely_polygon.contains(Point(int_point))): return int_point