I have a dataset consisting of 2,2 million houses in a Norway, and I want to find the distance to the coast for each dwelling. The location of the house is made up by latitude and longitude coordinates, and I have downloaded a shapefile of Europe with all the coastlines from (Could not find a shapefile for only Norway): https://www.eea.europa.eu/data-and-maps/data/eea-coastline-for-analysis-1/gis-data/europe-coastline-shapefile
Which have the coastline in both MULTILINESTRING and POLYGON format.
Then I try using the nearest point function from the shapely library, but it only assign the same value for each point, and it takes too long to run.
import geopandas as gpd
from shapely.geometry import Point
from shapely.ops import nearest_points
def findClosestCoastline(df):
#assign Point from the coordinates of dwelling
df['point'] = [Point(x, y) for x, y in zip(df['coord_x'].astype(float),
df['coord_y'].astype(float))]
#Load shapefile with MULTILINESTRING format
map_2= gpd.read_file("Europe_coastline.shp")
for i in range(df)
#TODO: Fix this, get the closest point from the MULTISTRINGLINE
np = nearest_points(map_2.iloc[0]['geometry'], df.iloc[i]['point'])[0]
df.loc[i, 'closestPoint_Coast'] = np
#TODO generate the distance in KM
df.loc[i, 'distance_To_Coast'] =
return df