9
I have imported a world map dataset from www.GADM.org using the R package raster. I would like to clip it to a polygon I create to reduce the size of the map. I can retrieve the data and I can create the polygon no problem, but when I use the 'gIntersection' command I get an obscure error message.
Any suggestions on how to clip my World Map dataset?
library(raster)
library(rgeos)
## Download Map of the World ##
WorldMap <- getData('countries')
## Create the clipping polygon
clip.extent <- as(extent(-20, 40, 30, 72), "SpatialPolygons")
proj4string(clip.extent) <- CRS(proj4string(WorldMap))
## Clip the map
EuropeMap <- gIntersection(WorldMap, clip.extent, byid = TRUE)
Error Message:
Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, "rgeos_intersection") : Geometry collections may not contain other geometry collections In addition: Warning message: In RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, "rgeos_intersection") : spgeom1 and spgeom2 have different proj4 strings