I've got two dataframes, each with a set of coordinates. Dataframe 1
is a list of biomass sites, with coordinates in columns 'lat' and 'lng'. Dataframe 2
is a list of postcode coordinates, linked to sale price, with coordinates in columns 'pc_lat' and 'pc_lng'.
I've used this stackoverflow question to work out the closest biomass site to each property. This is the code I am using:
def dist(lat1, long1, lat2, long2):
return np.abs((lat1-lat2)+(long1-long2))
def find_site(lat, long):
distances = biomass.apply(
lambda row: dist(lat, long, row['lat'], row['lng']),
axis=1)
return biomass.loc[distances.idxmin(),'Site Name']
hp1995['BiomassSite'] = hp1995.apply(
lambda row: find_site(row['pc_lat'], row['pc_long']),
axis=1)
print(hp1995.head())
This has worked well, in that I've got the name of the closest Biomass generation site, however I want to know the distance calculated between these two sites.
How would I calculate the distance?
What metric would the output distance be in? I am trying to find properties within 2km from the biomass site.