Difference in coordinates to country conversion

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Difference in coordinates to country conversion

Miluji Sb
I have a set of coordinates at 1° x 1°  which look like this:

structure(list(longitude = c(-179L, -178L, -177L, -177L, -177L,
-176L), latitude = c(-15L, -15L, -14L, 51L, 52L, -22L)), .Names =
c("longitude",
"latitude"), row.names = c("1", "2", "3", "4", "5", "6"), class =
"data.frame")

I am trying to obtain country names for them and tried the following two
methods. There are some difference (mostly between USA and Canada). While
sometimes method 1 provides a country name but method 2 cannot.

Is there a way to say if either of the methods are more accurate? Or
another more accurate method? Or am I doing something wrong?

Thanks!

Sincerely,

Shouro

library(raster)
library(tmap)
library(rworldmap)
library(countrycode)

# Method 1

{
  countriesSP <- getMap(resolution='low')
  #countriesSP <- 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(coord_dams,
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)
}

# Method 2
pts_dams <- SpatialPoints(coord_dams,proj4string=CRS(proj4string(worldmap)))
indices_dams <- over(pts_dams, worldmap,na.rm=TRUE)
indices <- cbind(indices_dams, coord_dams)

#Keep only ISO3, log, lat
foo_dams<-indices[,c(3,12,13)]

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo