This was copied from https://github.com/steventlamb/OpenTreeMap-cloud/blob/7b6e1c8b5622bf6ed7a1d66eb6c7e548a5354d82/opentreemap/treemap/udf.py#L1029

I don't know exactly what it does. I'll look into it.