[R-sig-Geo] polygons to grid?

Robert J. Hijmans r.hijmans at gmail.com
Sat Nov 21 22:05:18 CET 2009


Hi Agus,

In this function, and in all other functions in 'raster', the values
of a new RasterLayer object are written to disk if they cannot be
stored in memory (they are saved in a temporary file that is erased
the next time you load the package). To force writing to disk, and to
a more permanent file, you can provide an argument "filename=  "  (and
"format= " to choose the file format).

Robert

On Sat, Nov 21, 2009 at 11:28 AM, Agustin Lobo <Agustin.Lobo at ija.csic.es> wrote:
> Perfect,
> this is what I do:
> #Equivalent to
> #v.to.rast input=visit output=visitCODEQP use=attr column=CODI_EQP
> visitCODEQP <- raster(extent(visit))
> res(visitCODEQP) <- 100
> visitCODEQP <- polygonsToRaster((spPolys=visit,
> raster=visitCODEQP,field="CODI_EQP")
> [1] "Found 39 regions and  39 polygons"
> [1] "finished in  0 minutes, at 0 seconds/row"
>
> Just a concern: is the new raster (visitCODEQP in the example) loaded into
> memory? Potentially, it could be very large.
>
> Thanks a lot!
>
> Agus
>
> Robert J. Hijmans wrote:
>>
>> Agus,
>>
>> Please see   raster::polygonsToRaster
>>
>> Let 'p' be a SpatialPolygonsDF. Create an appropriate RasterLayer
>> object, for example use the extent of the polygons and set the
>> resolution.
>>
>> r <- raster(extent(p))
>> res(r) <- 1
>>
>> # then:
>> r <- polygonsToRaster(p, r)   # there are additional arguments to consider
>>
>> # to coerce into a SPGDF
>> spg <- as(r, 'SpatialGridDataFrame')
>>
>>
>> There was a discussion earlier this year, I believe, where there was
>> also an example to do this entirely in sp (using point in polygon
>> overlays)
>>
>> Robert
>>
>>
>> On Sat, Nov 21, 2009 at 5:20 AM, Agustin Lobo <alobolistas at gmail.com>
>> wrote:
>>>
>>> Hi?
>>>
>>> Is it possible to perform a vector to raster conversion in R,
>>> from SpatialPolygonsDataFrame to a SpatialGrid (providing the final
>>> resolution?
>>>
>>> In particular, is it possible to do it using package raster?
>>>
>>> (I know this can be done using gdal or grass etc, but I'm trying
>>> to find an "only R" solution)
>>>
>>> Thanks
>>>
>>> Agus
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at stat.math.ethz.ch
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>
> --
> 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