Skip to content

Commit

Permalink
new functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
j-miszczyszyn committed May 7, 2024
1 parent 621b05f commit aba6ad9
Show file tree
Hide file tree
Showing 13 changed files with 252 additions and 0 deletions.
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export(calculate_MSAVI)
export(calculate_NDVI)
export(calculate_TGI)
export(calculate_new_position)
export(cliping_cloud_to_aoi)
export(create_CHM_from_LAS)
export(define_AOI)
export(define_blue)
export(define_coastal_blue)
Expand All @@ -19,4 +21,8 @@ export(define_red)
export(define_rededge)
export(define_yellow)
export(dem_download_big_area_rgugik)
export(detect_tops_in_CHM)
export(normalize_height_in_clouds)
export(ortho_download_big_area_rgugik)
export(thin_cloud)
export(tops_in_folder_to_shp)
28 changes: 28 additions & 0 deletions R/cliping_cloud_to_aoi.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@


#' Title
#'
#' @param las_path
#' @param aoi
#' @param folder
#' @param crs_def
#' @param save_las
#'
#' @return
#' @export
#'
#' @examples
cliping_cloud_to_aoi=function(las_path, aoi, folder, crs_def, save_las){
las=lidR::readLAS(las_path)
sf::st_crs(aoi)=crs_def
lidR::crs(las)=crs_def
las=lidR::clip_roi(las, aoi)
name=basename(las_path)
name=str_replace(name, ".las","")
if (save_las==TRUE){
lidR::writeLAS(las, paste0(folder,"/", name,"_AOI.las"))
}
return(las)
}


23 changes: 23 additions & 0 deletions R/create_CHM_from_LAS.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

#' Title
#'
#' @param res_par
#' @param p2r_par
#' @param save_chm
#' @param output_folder
#' @param las_path
#'
#' @return
#' @export
#'
#' @examples
create_CHM_from_LAS=function(las_path,res_par,p2r_par,save_chm, output_folder){
x=lidR::rasterize_canopy(las_path, res = res_par, algorithm = lidR::p2r(p2r_par))
name=basename(las_path)
name=str_replace(name, ".las","")
if (save_chm==TRUE){
raster::writeRaster(x, paste0(output_folder,"/",name,"_CHM.tif"))
}


}
21 changes: 21 additions & 0 deletions R/detect_tops_in_CHM.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

#' Title
#'
#' @param CHM_path
#' @param ws_par
#' @param hmin_par
#' @param output_folder
#' @param save_tops
#'
#' @return
#' @export
#'
#' @examples
detect_tops_in_CHM=function(CHM_path,ws_par,hmin_par, output_folder, save_tops){
x=lidR::find_trees(CHM_path, algorithm = lidR::lmf(ws = ws_par, hmin = hmin_par), uniqueness = "incremental")
name=basename(CHM_path)
name=str_replace(name, ".tif","")
if (save_tops==TRUE){
raster::shapefile(x, paste0(output_folder,"/", name,"_TREES.shp"),overwrite=TRUE)
}
}
21 changes: 21 additions & 0 deletions R/normalize_height_in_clouds.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

#' Title
#'
#' @param las_path
#' @param folder
#' @param save_las
#'
#' @return
#' @export
#'
#' @examples
normalize_height_in_clouds=function(las_path, folder, save_las){
las=lidR::readLAS(las_path)
las_norm=lidR::normalize_height(las, lidR::tin(),use_class =c(2L) )
name=basename(las_path)
name=str_replace(name, ".las","")
if (save_las==TRUE){
lidR::writeLAS(las_norm, paste0(folder,"/", name,"_NORM.las"))
}
return(las_norm)
}
20 changes: 20 additions & 0 deletions R/thin_cloud.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#' Title
#'
#' @param folder
#' @param save_las
#' @param las_path
#'
#' @return
#' @export
#'
#' @examples
thin_cloud=function(las_path, folder, save_las){
las_thined=lidR::readLAS(las_path, filter = "-keep_class 4 5" )
name=basename(las_path)
name=str_replace(name, ".las","")
if (save_las==TRUE){
lidR::writeLAS(las_thined, paste0(folder,"/", name,"_THINED.las"))
}
}

41 changes: 41 additions & 0 deletions R/tops_in_folder_to_shp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#' Title
#'
#' @param folder_path
#' @param ws_par
#' @param hmin_par
#' @param crs_def
#' @param output_folder
#' @param save_tops
#' @param save_SHP
#'
#' @return
#' @export
#'
#' @examples
tops_in_folder_to_shp=function(folder_path,ws_par,hmin_par,crs_def, output_folder, save_tops, save_SHP){

l_CHM=list.files(folder_path, full.names = T, pattern="\\.tif$")
trees_finded=data.frame()

for (i in 1:length(l_CHM)) {
tryCatch({
r=raster(l_CHM[i])
t=detect_tops_in_CHM(CHM_path=folder_path,ws_par,hmin_par, output_folder, save_tops)
temp=data.frame(t)
temp$ID_NUMBER=1+i

# Dodaj wyniki do istniejącego obiektu typu sf
trees_finded <- rbind(trees_finded, temp)
}, error = function(e) {
# Przechwyć błąd, ale kontynuuj działanie pętli
cat("Błąd w iteracji", i, ":", conditionMessage(e), "\n")
})
}

trees_finded=st_as_sf(trees_finded, coords = c("coords.x1","coords.x2"))
st_crs(trees_finded)=crs_def
if( save_SHP==TRUE){
st_write(trees_finded,paste0(output_folder,"ALL_TTOPS.shp"), overwrite=T)
}
return(trees_finded)
}
14 changes: 14 additions & 0 deletions man/cliping_cloud_to_aoi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/create_CHM_from_LAS.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/detect_tops_in_CHM.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/normalize_height_in_clouds.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/thin_cloud.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions man/tops_in_folder_to_shp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aba6ad9

Please sign in to comment.