def get_buildings_in_buffer(buf, buildings, ids, idx):
    """
    Input the buffer polygon and building geometries to check
    if the building intersects with the buffer. Return all
    buildings within the buffer (based on ID). An R-tree
    is used to speed up things.
    """
    bld_in_buffer = {}

    for i in idx.intersection(buf.bounds):
        if buf.intersects(buildings[i]):
            bld_in_buffer[ids[i]] = buildings[i]

    return bld_in_buffer