diff --git a/NAMESPACE b/NAMESPACE index 5e17796..8378535 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) @@ -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) diff --git a/R/cliping_cloud_to_aoi.R b/R/cliping_cloud_to_aoi.R new file mode 100644 index 0000000..a5ce009 --- /dev/null +++ b/R/cliping_cloud_to_aoi.R @@ -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) +} + + diff --git a/R/create_CHM_from_LAS.R b/R/create_CHM_from_LAS.R new file mode 100644 index 0000000..ac1140b --- /dev/null +++ b/R/create_CHM_from_LAS.R @@ -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")) + } + + +} diff --git a/R/detect_tops_in_CHM.R b/R/detect_tops_in_CHM.R new file mode 100644 index 0000000..7cd5fe1 --- /dev/null +++ b/R/detect_tops_in_CHM.R @@ -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) + } +} diff --git a/R/normalize_height_in_clouds.R b/R/normalize_height_in_clouds.R new file mode 100644 index 0000000..712e9cf --- /dev/null +++ b/R/normalize_height_in_clouds.R @@ -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) + } diff --git a/R/thin_cloud.R b/R/thin_cloud.R new file mode 100644 index 0000000..1b30d3a --- /dev/null +++ b/R/thin_cloud.R @@ -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")) + } +} + diff --git a/R/tops_in_folder_to_shp.R b/R/tops_in_folder_to_shp.R new file mode 100644 index 0000000..ecfdbc3 --- /dev/null +++ b/R/tops_in_folder_to_shp.R @@ -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) +} diff --git a/man/cliping_cloud_to_aoi.Rd b/man/cliping_cloud_to_aoi.Rd new file mode 100644 index 0000000..14d39c9 --- /dev/null +++ b/man/cliping_cloud_to_aoi.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cliping_cloud_to_aoi.R +\name{cliping_cloud_to_aoi} +\alias{cliping_cloud_to_aoi} +\title{Title} +\usage{ +cliping_cloud_to_aoi(las_path, aoi, folder, crs_def, save_las) +} +\arguments{ +\item{save_las}{} +} +\description{ +Title +} diff --git a/man/create_CHM_from_LAS.Rd b/man/create_CHM_from_LAS.Rd new file mode 100644 index 0000000..91692cb --- /dev/null +++ b/man/create_CHM_from_LAS.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/create_CHM_from_LAS.R +\name{create_CHM_from_LAS} +\alias{create_CHM_from_LAS} +\title{Title} +\usage{ +create_CHM_from_LAS(las_path, res_par, p2r_par, save_chm, output_folder) +} +\arguments{ +\item{las_path}{} +} +\description{ +Title +} diff --git a/man/detect_tops_in_CHM.Rd b/man/detect_tops_in_CHM.Rd new file mode 100644 index 0000000..7dae184 --- /dev/null +++ b/man/detect_tops_in_CHM.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/detect_tops_in_CHM.R +\name{detect_tops_in_CHM} +\alias{detect_tops_in_CHM} +\title{Title} +\usage{ +detect_tops_in_CHM(CHM_path, ws_par, hmin_par, output_folder, save_tops) +} +\arguments{ +\item{save_tops}{} +} +\description{ +Title +} diff --git a/man/normalize_height_in_clouds.Rd b/man/normalize_height_in_clouds.Rd new file mode 100644 index 0000000..46fada8 --- /dev/null +++ b/man/normalize_height_in_clouds.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/normalize_height_in_clouds.R +\name{normalize_height_in_clouds} +\alias{normalize_height_in_clouds} +\title{Title} +\usage{ +normalize_height_in_clouds(las_path, folder, save_las) +} +\arguments{ +\item{save_las}{} +} +\description{ +Title +} diff --git a/man/thin_cloud.Rd b/man/thin_cloud.Rd new file mode 100644 index 0000000..d4a4f1b --- /dev/null +++ b/man/thin_cloud.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/thin_cloud.R +\name{thin_cloud} +\alias{thin_cloud} +\title{Title} +\usage{ +thin_cloud(las_path, folder, save_las) +} +\arguments{ +\item{las_path}{} +} +\description{ +Title +} diff --git a/man/tops_in_folder_to_shp.Rd b/man/tops_in_folder_to_shp.Rd new file mode 100644 index 0000000..1cda658 --- /dev/null +++ b/man/tops_in_folder_to_shp.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tops_in_folder_to_shp.R +\name{tops_in_folder_to_shp} +\alias{tops_in_folder_to_shp} +\title{Title} +\usage{ +tops_in_folder_to_shp( + folder_path, + ws_par, + hmin_par, + crs_def, + output_folder, + save_tops, + save_SHP +) +} +\arguments{ +\item{save_SHP}{} +} +\description{ +Title +}