Spatial query optimization