1

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.

Arihant
  • 589
  • 9
  • 24

1 Answers1

3

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 
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63