optimized version of spatial join query