They are not interchangeable. I think "dans " is used about delimited or precised space: "Je mange dans la salle à manger"." J'habite dans une grande ville" but we say: "J'habite en ville" "Je vis en France" "En" is used for a vast or general space. But French is very difficult and there are exceptions.
Please, excuse my english, I am French and I learn English
J.K.