If you say 'this', it sounds like you are still in the city, and therefore wouldn't be using a past-tense form, unless you were perhaps looking at an image of it.
It was the first time I had visited that city (I'm not there any more)
It was the first time I had visited the city (I'm not there now and to use 'the', I have probably already told you the name of the city in a previous sentence)
It's the first time I have visited this city (I'm still in this city)
:-)