-1

I would like to know how to create a raster with a resolution of 10km X 10km that could cover the whole extension of the Brazilian territory in R.

morebru
  • 175
  • 1
  • 9
  • 1
    Hi morebru. Welcome to StackOverflow! Please read the info about [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and how to give a [minimale reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). That way you can help others to help you! – dario Feb 24 '20 at 16:27

1 Answers1

1

You can do something along these lines

Get a polygon for Brazil

library(raster)
bra <- getData("GADM", country="BRA", level=1)

Project it to get meters as units. There might be a coordinate reference system that is a better fit for your purposes.

bcrs <- "+proj=poly +lat_0=0 +lon_0=-54 +x_0=5000000 +y_0=10000000 +ellps=GRS80"
pbra <- sp::spTransform(bra, bcrs)

Create a RasterLayer

r <- raster(pbra, res=10000)

r
#class      : RasterLayer 
#dimensions : 432, 482, 208224  (nrow, ncol, ncell)
#resolution : 10000, 10000  (x, y)
#extent     : 2794657, 7614657, 6265592, 10585592  (xmin, xmax, ymin, ymax)
#crs        : +proj=poly +lat_0=0 +lon_0=-54 +x_0=5000000 +y_0=10000000 +ellps=GRS80 

Display

values(r) <- 1:ncell(r)
plot(r)
lines(pbra)
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63