[R-sig-Geo] vector to raster

Agustin Lobo Agustin.Lobo at ija.csic.es
Thu Jul 5 14:51:47 CEST 2007


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ó:
> Agustin Lobo wrote:
>> Dear sig-geos,
>>
>> is there any way of converting from vector
>> (imported with rgdal from a shp) to raster
>> within R?
>>
>> Thanks!
>>
>> Agus
>>
>>   
> 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
> 

-- 
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
LLuis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
email: Agustin.Lobo at ija.csic.es
http://www.ija.csic.es/gt/obster




More information about the R-sig-Geo mailing list