if (1 > 2) { # not run
dem <- readGDAL(file.path(system.file('external',package='hydrosim'),
'watershed1','IDRISI_maps','dem','dem.rst')) # SpatialGridDataFrame
plotGmeta(layer=dem, xlim=662500 + 2500 * c(-1,+1),
ylim=4227500 + 2500 * c(-1,1), zlim='strloc', as.na=0)
# generate some crossing lines
zz <- list()
zz[[1]] <- digitGmeta(layer=dem, type='Lines', ID=1)
zz[[2]] <- digitGmeta(layer=dem, type='Lines', ID=2)
zz[[3]] <- digitGmeta(layer=dem, type='Lines', ID=3)
SL <- SpatialLines(zz)
SG <- sl2sg(SL, getpath=TRUE)
points(SG@v, cex=2) # plot SpatialGraph vertices
apath <- SG@path[[1,2]] # iteratively plot a path as an example
for (iv in 1:length(apath$v)) {
points(SG@v[apath$v[iv],], cex=2,pch=2)
if (iv == length(apath$v))
break
lines(SG@e[apath$e[iv],],col='blue',lwd=2,lty=2)
Sys.sleep(1)
}
# sample a few points [as a matrix] close to some edges
xy <- digit() # sample locations
xych <- pointsToLines(xy, SG@e) # SpatialPointsDataFrame mapping
points(xy, col='blue', pch=3)
points(xych, col='darkgreen', pch=19)
# along-network distance
xyndis <- distSG(SG, xych)
# state-dependent weighted along-network distance
SG@e@data$wxs <- 3+round(runif(nrow(SG@e@data)),2) # [m2] foo wetted cross-section areas
SG@e@data
xywdis <- distSG(SG, xych, wei='wxs')
xywdis <- xywdis$dis * xywdis$wei # Schur weight application into distance estimation
}
Run the code above in your browser using DataLab