peterson-tim-j/AWAPer

MonthlyAnalysis branch required "CatchID" as a field to extract spatial data

Closed this issue · 2 comments

Hello Tim,

At line 905 in "extractCatchmentData" the code is:
catchmentAvgTmp = data.frame(CatchmentID=rep(catchments$CatchID[i],nGridCells))

This means the user must specify CatchID as a field in their shapefile - either this needs to be specified in the user manual or maybe the following can be used instead:

catchmentAvgTmp = data.frame(CatchmentID=rep(catchments@data[i,1],nGridCells))

I wanted to check with you first before making any changes as I am still getting comfortable with shapefiles in R.

Hi Conrad
Thanks for picking this bug up. Your solution works for me. On this issue, L845 uses a different approach of getting the catchment IDs 9see below). Do you think this line should also be changed using your approach? Either way, could you pls extend the #' @param catchments to state that the first column of a shape file should be a unique site ID?

      catchmentAvgTmp = data.frame(CatchmentID=catchments[i,1],year=as.integer(format(timesteps,"%Y")) ,month=as.integer(format(timesteps,"%m")),day=as.integer(format(timesteps,"%d")),row.names = NULL);

Line 905 changed as proposed and parameter description updated as per your suggestion.
I left Line 845 left as it works and doesn't cause any issues.