Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thanks for the carefully constructed question. It required just a couple of line changes to be able to use rworldmap (containing up-to-date countries) see below. I'm not an expert on CRS but I don't think the change I had to make to the proj4string makes any difference. Others might like to comment on that.</p> <p>This worked for me &amp; gave :</p> <pre><code>&gt; coords2country(points) [1] United Kingdom Belgium Germany Austria [5] Republic of Serbia </code></pre> <p>All the best, Andy</p> <pre><code>library(sp) library(rworldmap) # The single argument to this function, points, is a data.frame in which: # - column 1 contains the longitude in degrees # - column 2 contains the latitude in degrees coords2country = function(points) { countriesSP &lt;- getMap(resolution='low') #countriesSP &lt;- getMap(resolution='high') #you could use high res map from rworldxtra if you were concerned about detail # convert our list of points to a SpatialPoints object # pointsSP = SpatialPoints(points, proj4string=CRS(" +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0")) #setting CRS directly to that from rworldmap pointsSP = SpatialPoints(points, proj4string=CRS(proj4string(countriesSP))) # use 'over' to get indices of the Polygons object containing each point indices = over(pointsSP, countriesSP) # return the ADMIN names of each country indices$ADMIN #indices$ISO3 # returns the ISO3 code #indices$continent # returns the continent (6 continent model) #indices$REGION # returns the continent (7 continent model) } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload