Convert latitude and longitude coordinates to country name in R

后端 未结 2 2035
长情又很酷
长情又很酷 2020-11-30 08:36

I have a list of latitude and longitude coordinates, and wish to find out which country they all reside in.

I modified an answer from this question about lat-long to

2条回答
  •  醉酒成梦
    2020-11-30 09:20

    You can use my geonames package to lookup from the http://geonames.org/ service:

    > GNcountryCode(51.5,0)
    $languages
    [1] "en-GB,cy-GB,gd"
    
    $distance
    [1] "0"
    
    $countryName
    [1] "United Kingdom of Great Britain and Northern Ireland"
    
    $countryCode
    [1] "GB"
    
    > GNcountryCode(44.5,20)
    $languages
    [1] "sr,hu,bs,rom"
    
    $distance
    [1] "0"
    
    $countryName
    [1] "Serbia"
    
    $countryCode
    [1] "RS"
    

    Get it from r-forge because I'm not sure I bothered to release it to CRAN:

    https://r-forge.r-project.org/projects/geonames/

    Yes, it depends on an external service, but at least it knows what happened to communism... :)

提交回复
热议问题