For someone who is spending Shabbat in a city or town, whether its residents are Jewish or non-Jewish, the whole area that is built up contiguously is considered one place, and the 2,000 amot of the teĥum are measured from its perimeter. Even if there is space between the homes, as long as they are surrounded by a fence or an eruv, the entire enclosed area is considered one place, and the 2,000 amot are measured from its perimeter (as will be explained in section 8).
All this pertains to one who spends Shabbat in the city or within its squared-off area. However, one who spends Shabbat in a field near the city is limited to 2,000 amot in each direction, and if his 2,000 amot terminate inside a city, his teĥum ends right there, in the middle of the city. We do not consider the whole city his four amot.[5]