Skip to content

vector to raster

4 messages · Agustin Lobo, Rainer M Krug, Edzer Pebesma

#
Dear sig-geos,

is there any way of converting from vector
(imported with rgdal from a shp) to raster
within R?

Thanks!

Agus
#
Agustin Lobo wrote:
I don't know about R, but there definitely is the possibility of using 
grass for doing this. When you are using spgrass6 you can integrate 
these two (grass into R)

Rainer
#
Agustin Lobo wrote:
Yes, using the classes and methods in sp -- you'd first have to create a 
grid e.g. with spsample, sampling type regular or makegrid. Next, if you 
want to have the polygon values at grid cell centres, overlay the 
polygons with the grid, using the overlay method.

 > library(sp)
 > data(meuse.riv)
 > meuse.sr = SpatialPolygons(list(Polygons(list(Polygon(meuse.riv)), "x")))
 >
 > plot(meuse.sr)
 > points(spsample(meuse.sr, n = 1000, "regular"), pch = 3)
 > class(meuse.sr)
[1] "SpatialPolygons"
attr(,"package")
[1] "sp"
 > pts = spsample(meuse.sr, n = 1000, "regular")
 > class(pts)
[1] "SpatialPoints"
attr(,"package")
[1] "sp"
 > gridded(pts)=T
 > class(pts)
[1] "SpatialPixels"
attr(,"package")
[1] "sp"

--
Edzer
#
I think I'm missing something here. Althoug I understand the general 
idea of making a regular grid of points within the boundaries of the
polygon, the final pts object of your example is not quite the idea I 
have of a raster. For example, how could you display pts using image() ? or
  how could you write pts as a geotif using rgdal?

Thanks!

Agus


Edzer J. Pebesma escribi?: