2

I'm trying to use a csv table with angle and azimuth values to compute a hillshade on the same area at different dates.

I'm using for and each date to extract the correct values, but it doesn't seem to be working out. It produces rasters with the exact same hillshade (presumably based on the values from the first line).

Date   Angle   Azimuth
Jan01  69.77   225.41
Jan06  70.50   225.56
Jan11  71.32   226.24
for(d in insol$Date){
hillShade(slope, aspect, angle=insol$Angle, direction=insol$Azimuth, filename=paste(d,".tif"))
}

Is there a way to tell R to use the values from each row at a time? The output states (sorry, in Portuguese):

> warnings()
Mensagens de aviso:
1: In cos(slp) * cos(zenith) :
  comprimento do objeto maior não é múltiplo do comprimento do objeto menor
2: In sin(slp) * sin(zenith) :
  comprimento do objeto maior não é múltiplo do comprimento do objeto menor
3: In cos(slp) * cos(zenith) :
  comprimento do objeto maior não é múltiplo do comprimento do objeto menor
4: In sin(slp) * sin(zenith) :
2

Loop over rows of the data frame and extract the i-th element from the vector:

for(i in 1:nrow(nsol)){
  d = nsol$Date[i]
  hillshade(..., nsol$Aspect[i], nsol$Azimuth[i],...etc...)
}
  • Oh great! Thanks! – gvanhavre Aug 12 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.