Arihant
Arihant

Reputation: 589

R: Text xyz to multiple raster

I have a comma delimited text files with the header names

lat,long,z1,z2,z3,z4,z5

These columns contain the lat, long and multiple height values(z1, z2,z3, z4). The lat and long data is spaced at an equal interval of 5 meters.

What is the most efficient way to convert the data into individual rasters or an R raster stack each having the z values, given the projection information is UTM, zone 18.

The sample data can be accessed here.

Upvotes: 1

Views: 846

Answers (1)

Robert Hijmans
Robert Hijmans

Reputation: 47591

You can do this:

x <- data.frame(lon=1:11, lat=5:15, z1=runif(11), z2=11:1)
library(raster)
b <- rasterFromXYZ(x)

#> b
#class       : RasterBrick 
#dimensions  : 11, 11, 121, 2  (nrow, ncol, ncell, nlayers)
#resolution  : 1, 1  (x, y)
#extent      : 0.5, 11.5, 4.5, 15.5  (xmin, xmax, ymin, ymax)
#coord. ref. : NA 
#data source : in memory
#names       :         z1,         z2 
#min values  : 0.08495835, 1.00000000 

Upvotes: 3

Related Questions