[R] How to create gridded data

Sarah Goslee @@r@h@go@lee @ending from gm@il@com
Tue Nov 13 15:16:26 CET 2018


If you want an actual spatial dataset, the best place to ask is R-sig-geo

R has substantial capabilities for dealing with gridded spatial data,
including in the sp, raster, and sf packages.

Here's one approach, creating a SpatialGridDataFrame, which can be
exported in any standard raster format using the rgdal package.

DF2 <- DF1
coordinates(DF2) <- ~longitude + latitude
gridded(DF2) <- TRUE
fullgrid(DF2) <- TRUE

I recommend Roger Bivand's excellent book:
https://www.springer.com/us/book/9781461476177

and there are abundant web tutorials.

Sarah
On Tue, Nov 13, 2018 at 2:22 AM lily li <chocold12 using gmail.com> wrote:
>
> Hi R users,
>
> I have a question about manipulating data. For example, I have DF1 as the
> following, how to transform it to a gridded dataset DF2? In DF2, each value
> Precip is an attribute of the corresponding grid cell. So DF2 is like a
> spatial surface, and can be imported to ArcGIS. Thanks for your help.
>
> DF1
> latitude   longitude   Precip
> 45.5           110.5         3.2
> 45.5           111            5.0
> 45.5           111.5         1.8
> 45.5           112            2.0
> 46              110.5         6.1
> 46              111            4.5
> 46              111.5         7.8
> 46              112            5.5
> ...
>
>
> DF2
> 6.1   4.5   7.8   5.5
> 3.2   5.0   1.8   2.0
> ...
>


-- 
Sarah Goslee (she/her)
http://www.numberwright.com



More information about the R-help mailing list