SHARE
TWEET

Point-to-grid gis.stackexchange

a guest Jan 18th, 2013 554 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # For illustrative purpose plot the points on a map
  2. # Load suitable library and plot the area of interest.
  3. library(rworldmap)
  4. newmap <- getMap(resolution = "high")
  5.  
  6. # Plot refined to Africa
  7. plot(newmap,
  8.      xlim = c(-25,60),
  9.      ylim = c(-35, 37),
  10.      asp = 1)
  11.  
  12. # A more accurate plot can be get by using the extreme points of the continent
  13. library(ggmap)
  14. africa.limits <- geocode(c("Iles des Chiens, Tunisia",
  15.                            "Cape Agulhas, South Africa",
  16.                            "Santa Antão, Cape Verde Islands",
  17.                            "Rodrigues, Mauritius")
  18. )
  19. africa.limits
  20.  
  21. plot(newmap,
  22.      xlim = range(africa.limits$lon),
  23.      ylim = range(africa.limits$lat),
  24.      asp = 1
  25. )
  26.  
  27. # Import the customised ACLED dataset
  28. acled<-read.csv("/home/R/acled_1997-2011.csv", header=TRUE)
  29. head(acled)
  30.  
  31. # Plot the points on the map
  32. points(acled$lon,acled$lat,col="red",cex=0.3)
  33.  
  34. # Load shapefile with the 1x1 degree grid
  35. library("sp")
  36. library("rgdal")
  37. # Set the correct working directory
  38. setwd("/home/R/Shapefiles")
  39. # Check layers
  40. ogrListLayers("ne_10m_graticules_1.shp")
  41. # Load the shapefile
  42. shape<-readOGR(dsn="/home/R/Shapefiles",layer="ne_10m_graticules_1")
  43. plot(shape,add=TRUE)
  44.  
  45. # TODO: Aggregate points-to-grid
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top