"To be going to do something" is another way to speak about some actions in the future. You shouldn't confuse it with the present continuous for the future. We use "to be going to + infinitive" in the following cases.
1. Speaking about intentions
"To be going to do something" means you have made a decision to do something in the future and you intend to do so.
I'm going to take driving lessons. → I haven't started the lessons yet but I have decided to start taking them.
Bill and Rose are going to get married. → They haven't got married yet but they have decided to do so.
Alex is going to buy a new car. → He hasn't bought a car yet but he has already made up his mind to buy it.
2. Something is about to happen
We use "to be going to" when we are sure that something is about to happen, we can see the signs of it.
Do you see those dark clouds? It's going to rain. → It isn't raining now but I can see the signs of the coming rain. It will be raining very soon.
Mark is on the ladder and he has lost balance. He is going to fall down. → He hasn't fallen down yet but there are signs that he's just about to fall.
I haven't studied for the test. I'm going to fail. → I haven't failed yet but that is very probable that I will.
Don’t confuse "to be going to + infinitive" with the verb "to go" in the present continuous tense:
I am going to the cinema tomorrow. → present continuous
I am going to move to Prague. → to be going to