lidar:projetos:rcode_alsmodelo
Diferenças
Aqui você vê as diferenças entre duas revisões dessa página.
| Ambos lados da revisão anteriorRevisão anteriorPróxima revisão | Revisão anterior | ||
| lidar:projetos:rcode_alsmodelo [2023/11/12 16:00] – lcer | lidar:projetos:rcode_alsmodelo [2023/11/27 10:41] (atual) – removida lcer | ||
|---|---|---|---|
| Linha 1: | Linha 1: | ||
| - | [[ lidar: | ||
| - | |||
| - | < | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | # Inventário com dados LiDAR na Fazenda Modelo ~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | # | ||
| - | # Autor: Luiz Carlos Estraviz Rodriguez | ||
| - | # Departamento de Ciências Florestais | ||
| - | # ESALQ/USP - 17/Out/2022 | ||
| - | # | ||
| - | # Inventário florestal da Fazenda Modelo | ||
| - | # - download dos dados mantidos em um repositório público github | ||
| - | # - shape files dos talhões florestais | ||
| - | # - LiDAR multitemporal (2013 e 2014) | ||
| - | # - armazenamento local na pasta C:/LiDAR/: | ||
| - | # | ||
| - | # Linguagem de programação: | ||
| - | # R (v 4.2) | ||
| - | # | ||
| - | # | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | rm(list=ls(all=TRUE)) | ||
| - | gc() | ||
| - | options(timeout=1000) # Reset timeout oferecendo mais tempo de download | ||
| - | |||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | # Instala packages, caso ainda não tenham sido instalados | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | if(!require(tidyverse)) | ||
| - | install.packages(" | ||
| - | library(tidyverse) | ||
| - | if(!require(sf)) | ||
| - | install.packages(" | ||
| - | library(sf) | ||
| - | if(!require(lidR)) | ||
| - | install.packages(" | ||
| - | library(lidR) | ||
| - | if(!require(foreach)) | ||
| - | install.packages(" | ||
| - | library(foreach) | ||
| - | if(!require(kableExtra)) | ||
| - | install.packages(" | ||
| - | library(kableExtra) | ||
| - | |||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | # Download do shape da Fazenda Modelo (2 layers: talhoes e parcelas) | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | gitOnde <- " | ||
| - | gitNome <- " | ||
| - | gitArqv <- file.path(gitOnde, | ||
| - | |||
| - | tmpd <- tempdir(check = TRUE) # diretório temporário | ||
| - | zipf <- file.path(tmpd, | ||
| - | |||
| - | if(!file.exists(zipf)) | ||
| - | download.file(gitArqv, | ||
| - | |||
| - | unzip(zipf, exdir = tmpd) # shape é unziped no diretório temporário | ||
| - | unlink(zipf) | ||
| - | |||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | # Lê atributos dos talhoes | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | shpArq <- paste0(tmpd, | ||
| - | talhoesComGeo <- sf:: | ||
| - | talhoesSemGeo <- tibble(sf:: | ||
| - | |||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | # Lê atributos das parcelas | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | shpArq <- paste0(tmpd, | ||
| - | parcelasComGeo <- sf:: | ||
| - | parcelasSemGeo < | ||
| - | |||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | # Cria coluna IDINV na tabela " | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | talhoes <- | ||
| - | parcelasSemGeo %>% | ||
| - | group_by(SUBTALHAO) %>% | ||
| - | summarise(IDINV = unique(IDINV)) %>% | ||
| - | left_join(talhoesSemGeo) %>% | ||
| - | select(" | ||
| - | arrange(SUBTALHAO) %>% as.data.frame | ||
| - | |||
| - | talhoesComGeo <- inner_join(talhoesComGeo, | ||
| - | select(" | ||
| - | |||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | # Reorganiza colunas da tabela " | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | parcelas <- | ||
| - | parcelasSemGeo %>% | ||
| - | select(SUBTALHAO, | ||
| - | arrange(SUBTALHAO) %>% as.data.frame | ||
| - | |||
| - | # Imprime tabela de talhões | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | AreaTotal <- talhoes$AREA %>% sum | ||
| - | NotaDeRodape <- paste0(": | ||
| - | talhoes %>% | ||
| - | kbl(caption = " | ||
| - | kable_classic(full_width = F) %>% | ||
| - | footnote(general = NotaDeRodape, | ||
| - | | ||
| - | | ||
| - | |||
| - | # Imprime tabela de parcelas | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | parcelas %>% | ||
| - | kbl(caption = " | ||
| - | kable_classic(full_width = F) | ||
| - | |||
| - | # Número Total de Unidades Amostrais (N) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | parcelaAreaMedia <- mean(parcelas$AREAPARCEL) / 10000 # em ha | ||
| - | tamanhoPopulacao <- round(AreaTotal / parcelaAreaMedia , 0) | ||
| - | |||
| - | # Mapa dos talhões com localização das parcelas (EPSG: 31983) | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | ggplot() + # plot dos talhões e parcelas (col por idade) | ||
| - | geom_sf(data = talhoesComGeo, | ||
| - | geom_sf(data = parcelasComGeo, | ||
| - | coord_sf(datum=st_crs(31983)) + # Especifica sistema de coord. | ||
| - | scale_y_continuous(breaks = seq(from=7356500, | ||
| - | scale_x_continuous(breaks = seq(from=206200, | ||
| - | |||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | # Amostragem Casual Simples (ACS): VTCC estimação e inferência | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | # Intervalo de Confiança | ||
| - | calcCI = function(err, | ||
| - | return( | ||
| - | qt(1 - alpha/2, n-1) * err #/ sqrt(n) | ||
| - | ) | ||
| - | } | ||
| - | |||
| - | # Parâmetros de Estimação e Inferência | ||
| - | calcPars = function(df, | ||
| - | means = apply(df, 2, mean) | ||
| - | vars = apply(df, 2, function(y){ | ||
| - | (var(y) / length(y)) * ((N - length(y)) / N) | ||
| - | }) | ||
| - | err = sqrt(vars) | ||
| - | cis = calcCI(err, nrow(df), alpha) | ||
| - | err_pc = 100*cis/ | ||
| - | out = rbind(means, | ||
| - | row.names(out) = c(' | ||
| - | names(out) = names(df) | ||
| - | return(out) | ||
| - | } | ||
| - | |||
| - | variaveisDeInteresse <- c(" | ||
| - | df <- parcelas %>% select(all_of(variaveisDeInteresse)) | ||
| - | |||
| - | simplePars | ||
| - | |||
| - | # Intensidade amostral (ha por parcela) da ACS que garante ~10% de erro | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | tamanhoIdealACS = function(y, N, errDesired=.10, | ||
| - | B = errDesired * mean(y) | ||
| - | qt = qt(1 - alpha/2, length(y)-1) | ||
| - | n = N*var(y)*qt^2 / (N * B^2 + qt^2 * var(y)) | ||
| - | return(n) | ||
| - | } | ||
| - | IA <- round(AreaTotal/ | ||
| - | |||
| - | # Resultados do inventário (estimação + inferência) por ACS | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | IAS <- paste0(" | ||
| - | IAI <- paste0(" | ||
| - | NotaDeRodape <- paste0(IAS, IAI) | ||
| - | simplePars %>% | ||
| - | kbl(caption = " | ||
| - | kable_classic(full_width = F) %>% | ||
| - | footnote(general = NotaDeRodape, | ||
| - | | ||
| - | | ||
| - | |||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | # Amostragem Casual Estratificada (ACE): VTCC estimação e inferência | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | # Grupos de estratificação | ||
| - | grupos = c(" | ||
| - | rightAges = talhoes$IDINV < 6 & talhoes$IDINV > 2 | ||
| - | |||
| - | # Box-plot das variáveis de interesse por nível de estratificação | ||
| - | par(mfrow=c( length(grupos), | ||
| - | attach(parcelas) | ||
| - | for(i in grupos){ | ||
| - | for(j in variaveisDeInteresse){ | ||
| - | plot( get(i) %>% factor , get(j), main = j, sub=i) | ||
| - | } | ||
| - | } | ||
| - | detach(parcelas) | ||
| - | |||
| - | # Estimativa da população para amostragem estratificada | ||
| - | popFromStrata = function(factorStrataList){ | ||
| - | popEstimates = foreach(i = factorStrataList, | ||
| - | gpMeans = lapply(i, function(x) x[1,, | ||
| - | gpVars | ||
| - | cols = 1: | ||
| - | popMean | ||
| - | function(x) sum(x*gpMeans$N) ) / | ||
| - | popVar | ||
| - | function(x) sum( x * (gpVars$N/ | ||
| - | popStdErr = sqrt(popVar) | ||
| - | popCI = calcCI(popStdErr, | ||
| - | popPars = data.frame( | ||
| - | media = popMean, | ||
| - | var = popVar, | ||
| - | dp = popStdErr, | ||
| - | ic = popCI, | ||
| - | erro = 100 * popCI / popMean, | ||
| - | n = sum( sapply(i, function(x) mean(x$n)) ) | ||
| - | ) | ||
| - | return(list(popPars)) | ||
| - | } | ||
| - | names(popEstimates) = names(factorStrataList) | ||
| - | return(popEstimates) | ||
| - | } | ||
| - | |||
| - | stratPars = foreach( | ||
| - | grp = grupos, .combine = ' | ||
| - | foreach( | ||
| - | niv = parcelas[, | ||
| - | as.character %>% sort, .combine = ' | ||
| - | ) %do% { | ||
| - | inGroup = talhoes[, | ||
| - | popSize = round( | ||
| - | sum(talhoes[rightAges & !is.na(inGroup) & inGroup, | ||
| - | parcelaAreaMedia) | ||
| - | inGroup = parcelas[, | ||
| - | tempPars = parcelas[inGroup, | ||
| - | inventory = calcPars(tempPars, | ||
| - | inventory$grupo = grp | ||
| - | inventory$nivel = niv | ||
| - | inventory$n | ||
| - | inventory$N | ||
| - | return(inventory) | ||
| - | } | ||
| - | |||
| - | stratPars %<>% base:: | ||
| - | lapply(function(x) split(x, x$nivel)) | ||
| - | globalStratPars = popFromStrata(stratPars) | ||
| - | |||
| - | # Intensidade amostral (ha por parcela) da ACE que garante ~10% de erro | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | tamanhoIdealACE = function(y, g, Nh, errDesired=.05){ | ||
| - | vars = by(y, g, stats::var) | ||
| - | Wh = by(y, g, length) / length(y) | ||
| - | Nh = Nh[ names(Nh) %in% g ] | ||
| - | B = errDesired * mean(y) | ||
| - | n = sum( Nh^2 * vars / Wh ) / ( (sum(Nh)^2 * B^2)/4 + sum(Nh * vars) ) | ||
| - | } | ||
| - | stratAreas <- round( | ||
| - | by(st_area(talhoesComGeo), | ||
| - | (parcelaAreaMedia*10000), | ||
| - | IA <- round(AreaTotal/ | ||
| - | parcelas$IDINV, | ||
| - | |||
| - | # Resultados do inventário (estimação + inferência) por ACE | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | IAS <- paste0(" | ||
| - | IAI <- paste0(" | ||
| - | NotaDeRodape <- paste0(IAS, IAI) | ||
| - | globalStratPars[[grupos]] %>% t %> | ||
| - | kbl(caption = paste0(" | ||
| - | align = " | ||
| - | kable_classic(full_width = F) %>% | ||
| - | footnote(general = NotaDeRodape, | ||
| - | | ||
| - | | ||
| - | |||
| - | # Gráfico para análise da precisão dos métodos amostrais | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | errs = 1:20 | ||
| - | scsPlotn <- tamanhoIdealACS(parcelas$VTCC, | ||
| - | errDesired = errs/100) | ||
| - | cssPlotn <- tamanhoIdealACE(parcelas$VTCC, | ||
| - | errDesired = errs/100) | ||
| - | # dsPlotn = dubleSamplePlotNumber(plotMetrics$PC_VOL_TOT, | ||
| - | # | ||
| - | # | ||
| - | |||
| - | png(' | ||
| - | plot( scsPlotn ~ errs, type=' | ||
| - | ylim=c(0, | ||
| - | axes=F) | ||
| - | lines(errs, cssPlotn, col=' | ||
| - | # lines(errs, dsPlotn, col=' | ||
| - | box() | ||
| - | axis(1) | ||
| - | axis(2, at = c(25, 50, 75, 100, 125, 150, 175, 200)) | ||
| - | abline(v=10, | ||
| - | lines(c(0, | ||
| - | # lines(c(0, | ||
| - | # lines(c(0, | ||
| - | legend(' | ||
| - | | ||
| - | # legend = c(' | ||
| - | dev.off() | ||
| - | |||
| - | # save.image(file=' | ||
| - | # load(' | ||
| - | |||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | # Leitura de dados LidAR | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | |||
| - | # Define os nomes dos tiles LiDAR multitemporais que serão lidos do | ||
| - | # repositório, | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | gitOnde < | ||
| - | gitNome < | ||
| - | " | ||
| - | " | ||
| - | anoData <- c(" | ||
| - | |||
| - | # Cria diretórios e pastas para onde os tiles LiDAR serão copiados | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | lidarDir <- " | ||
| - | lidarDir <- " | ||
| - | |||
| - | # Faz o download dos tiles | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | for (ano in anoData) { | ||
| - | | ||
| - | | ||
| - | for (nome in gitNome){ | ||
| - | gitFile <- paste0(gitOnde, | ||
| - | localFl <- paste0(dirLAZ, | ||
| - | if(!file.exists(localFl)) | ||
| - | download.file(gitFile, | ||
| - | } | ||
| - | } | ||
| - | |||
| - | # Leitura dos dois catálogos de dados LiDAR (2013 e 2014) | ||
| - | # Exibe conteúdo do catálogo e confere se os mapas de tiles são iguais | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | |||
| - | dirLAZ1 <- paste0(lidarDir, | ||
| - | ctg1 <- readLAScatalog(dirLAZ1) | ||
| - | print(ctg1@data) | ||
| - | plot(ctg1) | ||
| - | |||
| - | dirLAZ2 <- paste0(lidarDir, | ||
| - | ctg2 <- readLAScatalog(dirLAZ2) | ||
| - | print(ctg2@data) | ||
| - | plot(ctg2) | ||
| - | |||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | # Amostragem Dupla (AD): VTCC estimação e inferência | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | # Função ldiR | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | metricas < | ||
| - | if (length(z)< | ||
| - | zKeep = z[RN == 1] | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | ) | ||
| - | | ||
| - | " | ||
| - | " | ||
| - | " | ||
| - | | ||
| - | } | ||
| - | |||
| - | # Ajuste dos shapefiles | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | |||
| - | shp1 <- parcelasSemGeo %>% filter(AREAPARCEL == 380.13) | ||
| - | shp2 <- parcelasSemGeo %>% filter(AREAPARCEL == 399.73) | ||
| - | |||
| - | |||
| - | sf1 <- sf:: | ||
| - | plot(sf1[2]) | ||
| - | dub_buffer1 <- st_buffer(sf1, | ||
| - | plot(dub_buffer1[2]) | ||
| - | |||
| - | sf2 <- sf:: | ||
| - | plot(sf2[2]) | ||
| - | dub_buffer2 <- st_buffer(sf2, | ||
| - | plot(dub_buffer2[2]) | ||
| - | |||
| - | parcelasComGeo <- rbind(dub_buffer1, | ||
| - | plot(parcelasComGeo[1]) | ||
| - | |||
| - | pontos | ||
| - | |||
| - | # Gera os pixel metrics | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | #metrics = read.csv(paste0(wrkDir,'/ | ||
| - | opt_chunk_buffer(ctg1) <- 25 | ||
| - | opt_filter(ctg1) <- " | ||
| - | metrics | ||
| - | plot(metrics$zmean) | ||
| - | metrics | ||
| - | resultDir <- paste0(' | ||
| - | dir.create(resultDir) | ||
| - | write.csv(metrics, | ||
| - | metrics | ||
| - | plot(talhoesComGeo) | ||
| - | # Métricas das parcelas | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | opt_chunk_buffer(ctg2) <- 25 | ||
| - | opt_filter(ctg2) | ||
| - | spatialPlotMetrics <- plot_metrics(ctg1, | ||
| - | spatialPlotMetrics <- spatialPlotMetrics %>% st_drop_geometry() | ||
| - | |||
| - | # Funções para a | ||
| - | # Amostragem dupla | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | doubleSampleRegPars = function(y, x, xLarge, alpha=.05){ | ||
| - | n = length(y) | ||
| - | beta = ( sum(y*x, na.rm=T) - ( sum(x, na.rm=T)*sum(y, | ||
| - | |||
| - | rho = cor(y,x) | ||
| - | N = length(xLarge) | ||
| - | |||
| - | ydsr = mean(y, na.rm=T) + beta * ( mean(xLarge, | ||
| - | | ||
| - | | ||
| - | | ||
| - | |||
| - | out = c(media = ydsr, var = vardsr, dp = stderr, ic = ci, erro = 100*ci/ | ||
| - | |||
| - | | ||
| - | } | ||
| - | # ideal number of plots for double sampling | ||
| - | dubleSamplePlotNumber = function(y, x, xLarge, Cpg = 300, errDesired = .05, alpha = .05){ | ||
| - | |||
| - | rho = cor(x,y) | ||
| - | a = var(y) * (1 - rho^2) | ||
| - | b = var(y) * rho^2 | ||
| - | |||
| - | B = errDesired * mean(y) | ||
| - | qt = qt(1 - alpha/2, length(y)-1) | ||
| - | |||
| - | nG = (sqrt( a*b*Cpg ) + b) / (B^2 / qt^2) | ||
| - | nP = (sqrt( a*b/Cpg ) + a) / (B^2 / qt^2) | ||
| - | |||
| - | | ||
| - | } | ||
| - | |||
| - | |||
| - | spatialPlotMetrics | ||
| - | |||
| - | lims = spatialPlotMetrics %>% names %in% c(' | ||
| - | lidarOnly = spatialPlotMetrics[, | ||
| - | |||
| - | interestVars = c(' | ||
| - | corrMat = cor(spatialPlotMetrics[, | ||
| - | corrMat = corrMat[, | ||
| - | |||
| - | handPick = c(' | ||
| - | vars = c(' | ||
| - | handp = as.data.frame(cbind(vars, | ||
| - | doubleSamplePars = foreach(i = interestVars, | ||
| - | aux = corrMat[i,] | ||
| - | #pick = which( aux == max(aux) ) %>% names | ||
| - | pick = handp$handPick[vars == i] | ||
| - | XL = metrics[, | ||
| - | |||
| - | est = doubleSampleRegPars(spatialPlotMetrics[, | ||
| - | #est = doubleSampleRatioPars(spatialPlotMetrics[, | ||
| - | | ||
| - | |||
| - | est %<>% t %>% as.data.frame | ||
| - | | ||
| - | |||
| - | | ||
| - | } | ||
| - | |||
| - | doubleSamplePars <- doubleSamplePars %>% select(-rho) %>% t() | ||
| - | |||
| - | doubleSamplePars %>% | ||
| - | kbl(caption = " | ||
| - | kable_classic(full_width = F) | ||
| - | |||
| - | # Gráfico para análise da precisão dos métodos amostrais | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | errs = 1:20 | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | |||
| - | | ||
| - | plot( scsPlotn ~ errs, type=' | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | box() | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | |||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | # Este script foi criado em Julho/2022 depois de instalar, na seguinte | ||
| - | # sequência, as mais recentes versões do pacote lidR*: | ||
| - | # | ||
| - | # | ||
| - | # | ||
| - | # | ||
| - | # * lidR latest development version | ||
| - | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| - | </ | ||
| - | |||
| - | ---- | ||
| - | Referências sobre o pacote //lidR// para processamento de dados LiDAR: | ||
| - | |||
| - | * [[https:// | ||
| - | * [[https:// | ||
| - | * [[https:// | ||
| - | * [[https:// | ||
| - | |||
| - | e sobre os pacotes //terra// e //sf// para processamento de dados espaciais: | ||
| - | * [[https:// | ||
| - | * [[https:// | ||
lidar/projetos/rcode_alsmodelo.1699804834.txt.gz · Última modificação: (edição externa)
