Learn R Programming

geo (version 1.4-3)

inside.reg.lump: Inside region in lumpsucker fishery

Description

Finds regulation area from a position given in dataframe

Usage

inside.reg.lump(data)

Arguments

data
Data frame with columns lat and lon givin postions

Value

Original data with column area added, with index to list of regulation areas in reg.lump.

Details

to be added later

References

Borrows from inside.reg.bc.

See Also

inside.reg.bc, reg.lump.

Examples

Run this code
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (data)
{
    if (nrow(data) > 1)
        tmpdata <- data[, c("lat", "lon")]
    else tmpdata <- as.data.frame(data[, c("lat", "lon")])
    tmpdata$area <- rep(0, nrow(tmpdata))
    i <- 1
    ind <- geoinside(tmpdata, reg = reg.lump[[i]], option = 0,
        robust = FALSE)
    if (length(ind) > 0)
        tmpdata[ind, "area"] <- i
    i <- 2
    j <- tmpdata$area == 0
    j1 <- c(1:length(j))
    j1 <- j1[j == T]
    if (length(j1) > 0) {
        ind <- geoinside(tmpdata[j1, ], reg = reg.lump[[i]],
            option = 0, robust = FALSE)
        if (length(ind) > 0)
            tmpdata[j1[ind], "area"] <- i
    }
    i <- 3
    j <- tmpdata$area == 0
    j1 <- c(1:length(j))
    j1 <- j1[j == T]
    if (length(j1) > 0) {
        ind <- geoinside(tmpdata[j1, ], reg = reg.lump[[i]],
            option = 0, robust = FALSE)
        if (length(ind) > 0)
            tmpdata[j1[ind], "area"] <- i
    }
    i <- 4
    j <- tmpdata$area == 0
    j1 <- c(1:length(j))
    j1 <- j1[j == T]
    if (length(j1) > 0) {
        ind <- geoinside(tmpdata[j1, ], reg = reg.lump[[i]],
            option = 0, robust = FALSE)
        if (length(ind) > 0)
            tmpdata[j1[ind], "area"] <- i
    }
    i <- 5
    j <- tmpdata$area == 0
    j1 <- c(1:length(j))
    j1 <- j1[j == T]
    if (length(j1) > 0) {
        ind <- geoinside(tmpdata[j1, ], reg = reg.lump[[i]],
            option = 0, robust = FALSE)
        if (length(ind) > 0)
            tmpdata[j1[ind], "area"] <- i
    }
    i <- 6
    j <- tmpdata$area == 0
    j1 <- c(1:length(j))
    j1 <- j1[j == T]
    if (length(j1) > 0) {
        ind <- geoinside(tmpdata[j1, ], reg = reg.lump[[i]],
            option = 0, robust = FALSE)
        if (length(ind) > 0)
            tmpdata[j1[ind], "area"] <- i
    }
    i <- 7
    j <- tmpdata$area == 0
    j1 <- c(1:length(j))
    j1 <- j1[j == T]
    if (length(j1) > 0) {
        ind <- geoinside(tmpdata[j1, ], reg = reg.lump[[i]],
            option = 0, robust = FALSE)
        if (length(ind) > 0)
            tmpdata[j1[ind], "area"] <- i
    }
    i <- 8
    j <- tmpdata$area == 0
    j1 <- c(1:length(j))
    j1 <- j1[j == T]
    if (length(j1) > 0) {
        ind <- geoinside(tmpdata[j1, ], reg = reg.lump[[i]],
            option = 0, robust = FALSE)
        if (length(ind) > 0)
            tmpdata[j1[ind], "area"] <- i
    }
    data$area <- tmpdata$area
    return(data)
  }

Run the code above in your browser using DataLab