I have a dataframe with lat, lon columns in WGS84.
I also have a multipolygon layer (GeoJSON, I can also convert it to a SHP) with all countries' boundaries, where the name of the country is in the attribute table.
I would like to add to the dataframe a column where for each lat, lon I'll have the country name.
What would be the efficient way to do that (assuming I have 2000 lat lon pairs)?
UPDATE:
Thanks toWith help from @BERA I've created this function:
import geopandas as gpd
from shapely.geometry import Point
df_countries = gpd.read_file(r"C:\countries.geojson")
def get_countries(df, lat_col, lon_col,df_countries):
df_latlon = df[[lat_col,lon_col]].copy()
df_latlon['Coordinates'] = list(zip(df_latlon[lon_col], df_latlon[lat_col]))
df_latlon['Coordinates'] = df_latlon['Coordinates'].apply(Point)
df_latlon = gpd.GeoDataFrame(df_latlon, geometry='Coordinates')
df_latlon = df_latlon.set_crs(epsg=4326)
df_latlon = gpd.sjoin(df_latlon, df_countries[['CNTRY_NAME','geometry']], how='left')
return df_latlon