Reputation: 767
I have a shapefile which I would like to extend (basically adding some NA rows and cols). Is there any function which does that like raster::extend
? Unfortunately this only works for raster
objects.
I can crop it using raster::crop
, which has a method for SpatialPolygonsDataFrame
, but I am not able to find anything for extending.
Upvotes: 1
Views: 5064
Reputation: 797
I found a way to do this!
The extent data of a SpatialPolygons seems to be stored in a slot called bbox. Inside the slot (which you can access via my.polygon@bbox
), you will find a simple matrix like this one:
min max
x -81 -80
y 11 12
Simply replacing that matrix with another one that looks like the one you want to get will change the extent of your SpatialPolygons. You can even use the extent of your other polygon or raster to make the matrix:
my.polygon@bbox <- as.matrix(extent(my.raster))
It is not as neat as raster's extend... but it works the same :) Hope it is not too late!
Upvotes: 7