Finished implementing the first version of spatial analysis