Learn R Programming

OCNet (version 0.4.0)

OCN_to_SSN: Transform OCN into SSN object

Description

Function that transforms an OCN into a SpatialStreamNetwork object. It is analogous to function createSSN from package SSN.

Usage

OCN_to_SSN(OCN, level, obsDesign,
  predDesign = noPoints, path, importToR = FALSE)

Arguments

OCN

List as produced by aggregate_OCN.

level

Aggregation level at which the OCN is converted into a SpatialStreamNetwork object. It must be equal to either "FD", "RN" or "AG".

obsDesign

Same as the argument of the same name in createSSN. Note that the length of the argument of the design function must be equal to OCN$N_outlet.

predDesign

Same as the argument of the same name in createSSN. Note that, if a design function is specified, the length of its argument must be equal to OCN$N_outlet.

path

Same as the argument of the same name in createSSN.

importToR

Same as the argument of the same name in createSSN.

Value

A SpatialStreamNetwork object if importToR is TRUE, otherwise NULL.

Details

The generated SpatialStreamNetwork object consists of OCN$N_outlet networks. Note that an error is thrown if, at the selected aggregation level, at least one of these networks is degenerate (i.e. it has less than two nodes). This is typically the case for OCNs generated with option N_outlet = "All".

If OCN$PeriodicBoundaries == FALSE, nodes' locations in the SpatialStreamNetwork object are given by the lattice coordinates (i.e. OCN$level$X, OCN$level$Y); if OCN$PeriodicBoundaries == TRUE, real coordinates are used (i.e. those defined by OCN$FD$X_draw, OCN$FD$Y_draw, see landscape_OCN).

Examples

Run this code
# NOT RUN {
# transform a 20x20 single-outlet OCN (aggregated at the AG level)
# into a SSN object and plot it
OCN <- aggregate_OCN(landscape_OCN(OCN_20), thrA = 4)
ssn1 <- OCN_to_SSN(OCN, "AG", obsDesign = SSN::poissonDesign(10), 
path=paste(tempdir(),"/OCN.ssn", sep = ""), importToR = TRUE)
plot(ssn1)

# }
# NOT RUN {
# 1) create a 50x50 OCN with two outlets and periodic boundaries; 
set.seed(1)
OCN <- create_OCN(50, 50, nOutlet = 2, outletSide = c("S", "N"),
		outletPos = c(1, 50), periodicBoundaries = TRUE)
# aggregate the OCN;
OCN <- aggregate_OCN(landscape_OCN(OCN))
# transform it into a SSN object aggregated at the RN level;
ssn2 <- OCN_to_SSN(OCN, "RN", obsDesign = SSN::binomialDesign(c(10, 10)),
		path = paste(tempdir(),"/OCN2.ssn", sep = ""), importToR = TRUE)
# and plot the SSN object; it is constituted by two networks,
# and nodes' coordinates are the "real" ones  
old.par <- par(no.readonly = TRUE)
par(mai = c(1, 1, 1, 1))
plot(ssn2, xlab = "X", ylab = "Y")
par(old.par)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab