Finding the Central City in a Region Using MATLAB

Any two points on a sphere and the center of the sphere form a great circle’s minor arc, which represents the minimum surface distance between these two points. Therefore, can we extend this to find the distance between each pair of points and calculate the sum of distances from a certain point to all other points? This point can be considered the center of all points. When applied to a country or region, we can identify a “central city” in a specific area. Here, the “central city” is defined by me as the city within the region that has the minimum sum of surface distances to all other cities. This calculation assumes an ideal spherical Earth, ignoring topographical influences, with the arc length corresponding to the central angle between two cities considered as the surface distance. The following calculation method is implemented using MATLAB, taking Xinjiang as an example, primarily considering several major cities.
1
Organize the required data for major cities in Xinjiang into a tabular format and import the data into MATLAB.

city

jwd
Urumqi 87.480035,43.905793
Kelamayi 84.957440,45.467231
Turpan 89.102504,43.031556
Hami 93.664135,42.843051
Changji 87.267401,44.014100
Bole 82.303500,44.898354
Kuerle 86.142326,41.622753
Aksu 80.292036,41.263033
Atushi 76.168400,39.716100
Kashgar 76.026633,39.542488
Hotan 79.867859,37.038437
Yining 81.332453,43.957164
Tacheng 83.346030,46.672249
Altay 88.086295,47.751905

The above data is sourced from the internet, except for Changji and Atushi, all others are local airport coordinates.

2
Create a custom function. The function defined here calculates the surface distance between two given cities, as follows:
function D=distance(x,y) % Define a function distance that takes two inputs x and y and returns one output Dx=x/180*pi; % Convert each element in the x array (latitude and longitude) from degrees to radiansy=y/180*pi; % Convert each element in the y array (latitude and longitude) from degrees to radians% Here we calculate the sine of half the angular difference between the two points on the sphere, multiplied by the Earth's radiusD=2*asin(sqrt((sin(x(1)-y(1)))^2+... cos(x(1))*cos(y(1))*(sin(x(2)-y(2)))^2))*6371;end % End of function
3
Calculate the distances between each pair of major cities using a for loop, as follows:
% Initialize a zero matrix D to store distances between citiesD=zeros(length(city));% Iterate over each city in the city listfor i=1:length(city)% Split the current city's latitude and longitude string (assumed to be stored in jwd(i)) by comma and convert to double array% Then flip the array (to place longitude and latitude in the correct order depending on the original data format)x=strsplit(jwd(i),',');x=flip(double(x));% Iterate over each previous city (including itself)for j=1:i% Process the latitude and longitude of the j-th city similarlyy=strsplit(jwd(j),',');y=flip(double(y));% If i equals j, meaning the current city is compared to itself, set distance to 0if i==jD(i,j)=0;% Otherwise, calculate the distance between city i and city j, and store the result in D(i,j) and D(j,i)% Because the distance matrix is symmetric, D(j,i) is also set to the same valueelse D(i,j)=distance(x,y); % The distance function calculates the distance between two pointsD(j,i)=distance(x,y); % Due to the symmetry of the matrix, no need to recalculateend end endD=round(D,2)
After calculation, the relevant data is stored inD.
4
Calculate the sum of distances from each city to all other cities and find the minimum value, identifying the corresponding city index, which gives us the “central city.”
% a is the found minimum value, b is the index of that minimum value when summing D along the columns[a, b] = min(sum(D));% Use index b to get the corresponding city name from the city arraycityName = city(b);% Display or process the found city namefprintf('The city corresponding to the minimum distance is: %s', cityName);
Finally, it turns out that the city is Changji, which is somewhat unexpected.Its sum of distances to all other major cities in the region is 13442 km.However, considering thatChangji has no airport, air travel requires going to Urumqi Diwopu, and the distance between the two places is relatively short, compared to over 10,000 km, it can be ignored.

Finding the Central City in a Region Using MATLAB

Therefore, we can consider Urumqi to be the truly “central city” in the Xinjiang region.

Leave a Comment