Disentangling the effects of ecological and environmental processes on the spatial structure of metacommunities