-2

How can I sort a list of geographical coordinates into different lists based on the country and save each list as a separate CSV file?

Koforidua_ANUC,6.109N,0.302W
Kuching,1.491N,110.349E
Kuopio,62.892N,27.634E
Kuwait_University,29.325N,47.971E

Edit: The comments from tripleee were helpful


Is it possible to add regional mountain ranges to my plot, such as the Atlas Mountains or the Hoggar Mountains in Nigeria, without using Geopandas or similar libraries? Unfortunately, these features are not readily available in the Geopandas database. Since I don't have access to maps APIs or software like QGIS or GDAL, I'm limited to using freely available databases.

S.Kociok
  • 168
  • 1
  • 14
  • If you can map from station name to country, then the rest is trivial. What did you search for, and what did you find? What did you try, and how did it fail? – tripleee Feb 10 '23 at 13:15
  • https://stackoverflow.com/questions/44208780/find-the-county-for-a-city-state has some solutions for getting a country from coordinates. If you have a simple database of your stations (I'm guessing weather stations?) and their country then the problem is much simpler, of course. – tripleee Feb 10 '23 at 13:18
  • https://www.ncdc.noaa.gov/cdo-web/datasets looks vaguely promising but the links I tried were 404. – tripleee Feb 10 '23 at 13:21

1 Answers1

0

The following lines solved my problem:

    from geopy.geocoders import Nominatim 
geolocator = Nominatim(user_agent="Geolocation")
    
    def get_country(station, lat, lon):
        location = geolocator.reverse(f"{lat}, {lon}", exactly_one=True)
        return location.raw['address'].get('country', 'unknown')
    
    stations = [
        ['Ouagadougou', 12.424, -1.487],
        ['Ouarzazate', 30.928, -6.913],
        ['Oujda', 34.653, -1.898],
        ['Oukaimeden', 31.209, 7.864],
        ['Pitres', 36.936, 3.326],
        ['Quarzazate', 30.939, 6.909] ]
    
    for station in stations:
        name, lat, lon = station
        country = get_country(name, lat, lon)
        print(f"Station: {name}, Latitude: {lat}, Longitude: {lon}, Country: {country}")

After that you can sort it after countries and save them into csv.

S.Kociok
  • 168
  • 1
  • 14