Calculate local density