# Identify the most isolated location’s Location Id

#1

Hello All,

I am facing a problem in one of my project. I have given a data set with 4 columns (Country,Longitude,Latitude,LocationId). I need to

1. identify the most isolated location’s Location Id and
2. identify the most isolated location’s Location Id for each country

I am not sure where to start. The code could be either in python or in R. Can anyone help me please?

How to handle Lat/Lon features in a model?
#2

@mishumsa
If by “isolated” you mean “the location is far from other locations” then you would need to :

1. Loop through each location point and find its mean distance from all other points. That is if point ‘A’ is surrounded by ‘B’, ‘C’ and ‘D’ you would calculated distance of A from all the three and then take the “mean” of them.

2. Then you would need to compare the mean distances of all points and find the point with maximum mean distance. This point will be your most isolated location.

Python has a very useful library geopy that lets you calculate distance between two locations based on their latitude and longitude.

Install geopy:

``````pip install geopy
``````

Distance between two cities:

``````from geopy.distance import great_circle

#Set Coordinates
bangalore = (12.9716, 77.5946)
delhi = (28.7041, 77.1025)

#distance in miles
print(great_circle(bangalore,delhi).miles)
1087.77728599
``````

Hope this helps,