0

I have a polygon of the extent I would like to rasterize and i have a raster with the projection and pixelsize etc that I want to use for the polygon, but the raster is smaller than the polygon.

I need to have a new raster with the extent of the polygon but also with the pixelsize and pixel order and place like the smaller raster.

Maria123
  • 13
  • 3
  • Can you make your question reproducible and show what you've tried so far (see [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example))? Also, did you know there's a [GIS SE site](https://gis.stackexchange.com/)? What I would maybe do is [create a larger raster](https://www.rdocumentation.org/packages/raster/versions/2.9-23/topics/extend) based on your small one and then mask it using the polygon. – Roman Luštrik Aug 24 '19 at 06:10

1 Answers1

0

Example data

library(raster)
p <- readRDS(system.file('external/lux.rds', package='raster'))
r <- raster(p[4,])
res(r) <- 0.05

Say you want to rasterize all of p. r has the desired resolution, but the extent is too small.

To get a larger raster, you can do

 rr1 <- setExtent(r, extent(p)+res(r), keepres=TRUE, snap=TRUE)
 #or
 rr2 <- extend(r, extent(p)+res(r))

followed by

 x <- rasterize(p, rr1)     

You can also do something a variation on this

 r2 <- raster(xmn=5.7, xmx=6.6, ymn=49.4, ymx=50.2)
 res(r2) <- 0.03

 y <- rasterize(p, r2)     
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63