Fix bug in spatial query sorting