diff --git a/R/abimo.R b/R/abimo.R index 4358876..27fdc8f 100644 --- a/R/abimo.R +++ b/R/abimo.R @@ -202,16 +202,12 @@ makeVG <- function(rawdir, return(vg) } -# read dbf results file, join with input shapefile and write output shapefile -# including ABIMO results +# read dbf results file, join with input shapefile #' abimo: postprocess -#' @description read dbf results file, join with input shapefile and write -#' output shapefile including ABIMO results -#' @param rawdir rawdir -#' @param nameABIMOin nameABIMOin -#' @param nameABIMOout nameABIMOout -#' @param ABIMOjoinedName ABIMOjoinedName -#' @return write shapefile with name "ABIMOjoinedName" to "rawdir" +#' @description read dbf results file and joins with input shapefile +#' @param path_input path of ABIMO input shapefile +#' @param abimo_output path of ABIMO output DBF file +#' @return #' @export #' #' @importFrom foreign read.dbf @@ -219,21 +215,17 @@ makeVG <- function(rawdir, #' @importFrom dplyr left_join #' @importFrom magrittr "%>%" #' -postProcessABIMO <- function(rawdir, nameABIMOin, - nameABIMOout, ABIMOjoinedName){ +postProcessABIMO <- function(path_input, + path_output){ # read files - ABIMOin <- raster::shapefile(x=file.path(rawdir, nameABIMOin), stringsAsFactors=FALSE) - ABIMOout <- foreign::read.dbf(file=file.path(rawdir, nameABIMOout), as.is=TRUE) - - ## set CODE in subcatchment data to padded CODE - #ABIMOin$CODE <- padCODE(ABIMOin@data$CODE) + ABIMOin <- raster::shapefile(x = path_input, stringsAsFactors=FALSE) + ABIMOout <- foreign::read.dbf(file = path_output, as.is=TRUE) # join ABIMOjoined <- ABIMOin ABIMOjoined@data <- ABIMOin@data %>% dplyr::left_join(ABIMOout, by='CODE') - # write out joined table output as shapefile - raster::shapefile(x=ABIMOjoined, filename=file.path(rawdir, ABIMOjoinedName), overwrite=TRUE) + ABIMOjoined } diff --git a/man/postProcessABIMO.Rd b/man/postProcessABIMO.Rd index 25fd40b..c71cc83 100644 --- a/man/postProcessABIMO.Rd +++ b/man/postProcessABIMO.Rd @@ -4,21 +4,16 @@ \alias{postProcessABIMO} \title{abimo: postprocess} \usage{ -postProcessABIMO(rawdir, nameABIMOin, nameABIMOout, ABIMOjoinedName) +postProcessABIMO(path_input, path_output) } \arguments{ -\item{rawdir}{rawdir} +\item{path_input}{path of ABIMO input shapefile} -\item{nameABIMOin}{nameABIMOin} - -\item{nameABIMOout}{nameABIMOout} - -\item{ABIMOjoinedName}{ABIMOjoinedName} +\item{abimo_output}{path of ABIMO output DBF file} } \value{ -write shapefile with name "ABIMOjoinedName" to "rawdir" + } \description{ -read dbf results file, join with input shapefile and write -output shapefile including ABIMO results +read dbf results file and joins with input shapefile } diff --git a/vignettes/workflow_beijing.Rmd b/vignettes/workflow_beijing.Rmd index 052cfb8..ce896e6 100644 --- a/vignettes/workflow_beijing.Rmd +++ b/vignettes/workflow_beijing.Rmd @@ -278,35 +278,27 @@ message(cat(sprintf("Run ABIMO executable manually: abimo_inp_path, abimo_out)) ) - -kwb.utils::hsOpenWindowsExplorer(paths$abimo_exe) - -abimo_out_joined <- sprintf('abimo_%sout_joined.dbf', paths$site) +} +kwb.utils::hsOpenWindowsExplorer(dirname(paths$abimo_exe)) # postprocessing ---------------------------------------------------------------- # post-process ABIMO output file -> join it with input shape file for # visualization in GIS -urbanAnnualRunoff::postProcessABIMO(rawdir = paths$abimo, - nameABIMOin = abimo_inp, - nameABIMOout = abimo_out, - ABIMOjoinedName = abimo_out_joined - +abimo_inpout <- urbanAnnualRunoff::postProcessABIMO( + path_input = file.path(paths$abimo, abimo_inp), + path_output = file.path(paths$abimo, abimo_out) ) -abimo_inpout <- kwb.abimo::abimo_comb_in_out( - file_ABIMO_out = file.path(paths$abimo, abimo_out), - file_ABIMO_in = abimo_inp_dbf_path -) -} - -} +# kwb.abimo::abimo_comb_in_out() works only with DBF as input +# abimo_inpout <- kwb.abimo::abimo_comb_in_out( +# file_ABIMO_out = file.path(paths$abimo, abimo_out), +# file_ABIMO_in = abimo_inp_dbf_path +# ) # compute emissions Tongzhou with OgRe AMC (annual mean concentration) database cDataFile <- file.path(paths$emissions_input, "annual_mean_conc.csv") -outFile <- file.path(paths$emissions_output, "emissionsTz.shp") - # grab AMC from OgRe x_conc <- read.table(file = cDataFile, @@ -345,12 +337,15 @@ loads <- sapply(X = c_heavy_metals_means$conc_mean, }) # add computed loads to ABIMO dataset -abimo_inpout <- cbind(abimo_inpout, loads) +abimo_inpout_emissions <- cbind(abimo_inpout, loads) # write out joined table output as shapefile -raster::shapefile(x = abimo_inpout, +outFile <- file.path(paths$emissions_output, + sprintf("abimo_%s_emissions.shp", paths$site)) + +raster::shapefile(x = abimo_inpout_emissions, filename = outFile, overwrite = TRUE) - +} ```