[R-sig-Geo] apply() proj4string to list of rasters

john polo jpolo at mail.usf.edu
Tue Nov 1 17:37:59 CET 2016


R-folks,

I imported >1000 rasters with

rlist <- list.files(pattern=".ht.laz.bil")

for (i in rlist) { assign(unlist(strsplit(i,"[.]"))[1], raster(i)) }


These rasters do not have a coordinate reference system.

 > ras895500_3965500ht
class       : RasterLayer
dimensions  : 34, 15, 510  (nrow, ncol, ncell)
resolution  : 5, 5  (x, y)
extent      : 895500, 895575, 3965830, 3966000  (xmin, xmax, ymin, ymax)
coord. ref. : NA
data source : k:\outLiDAR\normalized\ras895500_3965500ht.laz.bil
names       : ras895500_3965500ht.laz


The rasters don't have the same extent, I can't use stack().

I tried

epsgm <- make_EPSG()
adpro <- epsgm[3587,"prj4"]
lapply(ls(pattern="ht"), function(x) {proj4string(x) <- adpro})

Error in (function (classes, fdef, mtable)  :
   unable to find an inherited method for function ‘proj4string<-’ for 
signature ‘"character", "character"’

I searched and found a possible solution with mapply():

rrlis <- ls(patter="ht")
 > pfix4
function(x) proj4string(x) <- adpro
 > mapply(pfix4, rrlis)
Error in (function (classes, fdef, mtable)  :
   unable to find an inherited method for function ‘proj4string<-’ for 
signature ‘"character", "character"’

My problem apparently is trying to assign to a character. If I make a 
list of the raster objects, the lists are of characters and the 
functions won't work on those. How can I iterate through the raster 
objects in memory to apply a function?


John


-- 
Men occasionally stumble
over the truth, but most of them
pick themselves up and hurry off
as if nothing had happened.
-- Winston Churchill



More information about the R-sig-Geo mailing list