geospatial - R: How to extract values from contiguous raster cells that are not touched by SpatialLines? -


i've been trying extract values single attribute raster (area, in m2) overlaps lines (that is, .shp spatiallines).

the problem that, along these lines, raster goes 1 several contiguous cells in directions. using extract function values cells touched lines extracted. thus, when add extracted values lines significant amount of area (m2) lost due cells not touched line , therefore values not extracted.

i tried work around by:

step 1 - first aggregating raster lower resolution (i.e. increasing fact argument) , step 2 - rasterizing lines using aggregated raster (created in step 1) mold make sure rasterized lines thick enough cover horizontal spread of cells in original resolution raster. step 3 - resample rasterized lines (created in step 2) original resolution started with. step 4 - finally, extracted values resampled rasterized lines (created in step 3).

however, didn't quite work total area (m2) varies according fact="" value use when first aggregating raster (in step 1).

i appreciate if has dealt similar problem , can me out here. here codes i've been running try work:

# input raster file g.025 <- raster("ras.asc") g.1 <- aggregate(g.025, fact=2, fun=sum)  # input spatiallines spline1 <- readogr("/users/xxxxx.shp") spline2 <- readogr("/users/xxxxx.shp") spline3 <- readogr("/users/xxxxx.shp")  # rasterizing using low resolution raster (aggregated) c1 <- rasterize(spline1, g.1, field=spline1$type, fun=sum) c2 <- rasterize(spline2, g.1, field=spline2$type, fun=sum) c3 <- rasterize(spline3, g.1, field=spline3$type, fun=sum)  # resampling higher resolution c1 <- resample(c1, g.025) c2 <- resample(c2, g.025) c3 <- resample(c3, g.025)  # preparing extract area (m2) values raster “g.025” c1tab <- as.data.frame(c1, xy=t) c2tab <- as.data.frame(c2, xy=t) c3tab <- as.data.frame(c3, xy=t) c1tab <- c1tab[which(is.na(c1tab$layer)!=t),] c2tab <- c2tab[which(is.na(c2tab$layer)!=t),] c3tab <- c3tab[which(is.na(c3tab$layer)!=t),]  # extracting area (m2) values raster “g.025” c1tab[,4] <- extract(g.025, c1tab[,1:2]) c2tab[,4] <- extract(g.025, c2tab[,1:2]) c3tab[,4] <- extract(g.025, c3tab[,1:2]) names(c1tab)[4] <- "area_m2" names(c2tab)[4] <- "area_m2" names(c3tab)[4] <- "area_m2"  # sum total area (m2) c1_area <- sum(c1tab$area_m2) c2_area <- sum(c2tab$area_m2) c3_area <- sum(c3tab$area_m2) tot_area <- sum(c1_area, c2_area, c3_area) 

thanks!

andre


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -