Dear R Researcher,
I need some suggestions to finish to write the "layer/bins density index"
because, this is the true, some part is over my capacity.
I write this index for a points (shapefile format) inside my experimental
plots and this index write. The code of this index for my plots 11 is the
following (sorry if I don't use loop):
# Canopy Density (D): is compute as the proportions of first pulse laser
hits above fraction no. 0(> 2 m), 1, . . .., 9 to total
# number of first pulses. Fraction is obtain divide the canopy column into
10 vertical layers/bins by(Hmax-2)/10
# create and save a new shapefile with only the column: "ID" and "H"
canopy_plots_all <- readOGR(".", "canopy_plots_all")
canopy_plots <- canopy_plots_all[, c("ID","H")]
proj4string(canopy_plots) <- CRS("+init=epsg:26911")
# max value of plot points 11
Hmax.canopy_plots11 <- max(canopy_plots11$H)
# calculate the Height of each layer/bins "Hbins=(H max - 2)/10"
Hbins_plots11 <- (Hmax.canopy_plots11-2)/10
# number of hits (laser pulses) inside the plots 11 (this code gives me the
count numbers of laser hits)
sum.canopy_plots11 <- sum(canopy_plots11$H <= Hmax.canopy_plots11)
# Canopy Density: is a cumulative density of number of hits (laser pulses)
above the layer/bin-i
D.canopy_plots11_0 <- (sum(canopy_plots11$H > 2))/sum.canopy_plots11
D.canopy_plots11_1 <- (sum(canopy_plots11$H > 2 +
Hbins_plots11))/sum.canopy_plots11
D.canopy_plots11_2 <- (sum(canopy_plots11$H > 2 +
Hbins_plots11*2))/sum.canopy_plots11
D.canopy_plots11_3 <- (sum(canopy_plots11$H > 2 +
Hbins_plots11*3))/sum.canopy_plots11
D.canopy_plots11_4 <- (sum(canopy_plots11$H > 2 +
Hbins_plots11*4))/sum.canopy_plots11
D.canopy_plots11_5 <- (sum(canopy_plots11$H > 2 +
Hbins_plots11*5))/sum.canopy_plots11
D.canopy_plots11_6 <- (sum(canopy_plots11$H > 2 +
Hbins_plots11*6))/sum.canopy_plots11
D.canopy_plots11_7 <- (sum(canopy_plots11$H > 2 +
Hbins_plots11*7))/sum.canopy_plots11
D.canopy_plots11_8 <- (sum(canopy_plots11$H > 2 +
Hbins_plots11*8))/sum.canopy_plots11
D.canopy_plots11_9 <- (sum(canopy_plots11$H > 2 +
Hbins_plots11*9))/sum.canopy_plots11
Now in my patch area I am creating 10 Density grid(s) with 10x10 m of
resolution (each for a layer/bin). The code I wrote:
# Patch - 2644147
canopy2644147 <- readOGR(".", "canopy2644147")
proj4string(canopy2644147) <- CRS("+init=epsg:26911")
dcm.area2644147 <-
(canopy2644...@bbox[1,2]-canopy2644...@bbox[1,1])*(canopy2644...@bbox[2,2]-c
anopy2644...@bbox[2,1])
dcm.pixelsize2644147 <- 10 #resolution
dcm.pixelsize2644147
dcm.grid2644147 <-
GridTopology(cellcentre.offset=c(canopy2644...@bbox[1,1],canopy2644...@bbox[
2,1]), cellsize=c(dcm.pixelsize2644147,dcm.pixelsize2644147),
cells.dim=c(round((canopy2644...@bbox[1,2]-canopy2644...@bbox[1,1])/dcm.pixe
lsize2644147,0),round((canopy2644...@bbox[2,2]-canopy2644...@bbox[2,1])/dcm.
pixelsize2644147,0)))
dcm.grid2644147
dcm2644147 <- as(SpatialGrid(dcm.grid2644147, proj4string =
CRS(as.character(NA))), "SpatialGridDataFrame")
ID <-
as.factor(1:([email protected][1]*[email protected][2]))
dcm2644...@data <- as.data.frame(ID)
proj4string(dcm2644147) <- CRS("+init=epsg:26911")
str(dcm2644147["ID"])
# first overlay points over the grid and then derive summary measures
canopy2644147.ov <- overlay(dcm2644147["ID"], canopy2644147)
canopy2644147.ov$H <- canopy2644147$H
# Hmax
canopy2644147max.H <- aggregate(canopy2644147.ov$H,
by=list(canopy2644147.ov$ID), FUN="max")
names(canopy2644147max.H)[1] = "ID"
# calculate the Height of each layer/bins "Hbins=(H max - 2)/10"
# create a copy of "canopy2644147max.H" because we need after
Hbins_canopy2644147 <- canopy2644147max.H
Hbins_canopy2644147$x <- (Hbins_canopy2644147$x -2)/10
Here start my limit. I tried two day several solution with obtain the total
number with aggregate() and after to use the similar expression above.
Sorry If I was not clear
Thanks for suggestion and help
Alessandro
[[alternative HTML version deleted]]
_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo