gaia / utils /soil_utils.py
Rim BACCOUR
add prompt to compare both scenarii with and without ombrage
9c23216 unverified
raw
history blame
1.15 kB
import json
import geopandas as gpd
from dotenv import load_dotenv
from geopy.geocoders import Nominatim
from shapely.geometry import Point
load_dotenv()
file_rmqs ='data/soil_data/raw_data/rmqs.geojson'
df = gpd.read_file(file_rmqs)
def get_city_coordinates(city_name):
"""Get latitude and longitude of a city using Nominatim."""
geolocator = Nominatim(user_agent="geo_finder")
location = geolocator.geocode(city_name)
if location:
return (location.longitude, location.latitude)
return None
def find_nearest_point(city_name):
"""Find the closest GPS point in the dataset to the given city."""
city_coords = get_city_coordinates(city_name)
print("city coords", city_coords)
if not city_coords:
return "City not found"
# Iterate through GeoJSON features
df["distance"] = df["geometry"].distance(Point(city_coords[0], city_coords[1]))
closest_point = df.loc[df["distance"].idxmin()]
return closest_point # Returns the closest feature
if __name__ == "__main__":
# Example usage
city = "Paris"
closest_feature = find_nearest_point(city)
print(closest_feature)