Skip to content
Back to formatted view

Raw Message

Message-ID: <468CE963.5090209@ija.csic.es>
Date: 2007-07-05T12:51:47Z
From: Agustin Lobo
Subject: vector to raster
In-Reply-To: <468CDC55.1080902@geo.uu.nl>

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