isInArea: Find which nodes fall in a given area

isInAreaR Documentation

Find which nodes fall in a given area

Description

The generic function isInArea finds which nodes fall in a given area. Nodes can be specified in different ways, including by providing a gGraph or a gData object. Different format for the output are also available.

Usage

isInArea(x, ...)

## S4 method for signature 'matrix'
isInArea(
  x,
  reg = "current",
  res.type = c("logical", "integer", "character"),
  buffer = 0
)

## S4 method for signature 'data.frame'
isInArea(
  x,
  reg = "current",
  res.type = c("logical", "integer", "character"),
  buffer = 0
)

## S4 method for signature 'gGraph'
isInArea(
  x,
  reg = "current",
  res.type = c("logical", "integer", "character"),
  buffer = 0
)

## S4 method for signature 'gData'
isInArea(
  x,
  reg = "current",
  res.type = c("logical", "integer", "character"),
  buffer = 0
)

Arguments

x

a matrix, a data.frame, a valid gGraph, or a valid gData object. For matrix and data.frame, input must have two columns giving longitudes and latitudes of locations being considered.

...

further arguments passed to specific methods.

reg

a character string or a list indicating the area ('reg' stands for 'region'). Character strings can be "current" (current user window, default) or "zoom" (current zoom). If the argument is a list, is has to have two components, both being numeric vectors of length two, giving x and y limits of the area. Note that such list can be produced by locator, so locator(1) is a valid value for reg.

res.type

a character string indicating what kind of output should be produced. See value.

buffer

a numeric value giving a buffer adding extra space aroung the area, as a proportion of current area's dimensions.

Value

The output depends on the value of the argument res.type:

  • logical: a vector of logicals having one value for each node of the input.

  • integer: a vector of integers corresponding to the indices of nodes falling within the area.

  • character: a vector of characters corresponding to the names of the nodes falling within the area.

Functions

  • isInArea(matrix): Method for matrix

  • isInArea(data.frame): Method for data.frame

  • isInArea(gGraph): Method for gGraph object

  • isInArea(gData): Method for gData object

Examples


plot(worldgraph.10k, reset = TRUE)

## zooming in
geo.zoomin(list(x = c(-6, 38), y = c(35, 73)))
title("Europe")


## different outputs of isInArea
head(isInArea(worldgraph.10k)) # logical
length(isInArea(worldgraph.10k))
sum(isInArea(worldgraph.10k))
head(which(isInArea(worldgraph.10k))) # which nodes are TRUE ?

head(isInArea(worldgraph.10k, res.type = "integer")) # node indices

head(isInArea(worldgraph.10k, res.type = "character")) # node names


## use isInArea to have a subset of visible nodes
x <- worldgraph.10k[isInArea(worldgraph.10k)]
plot(x, reset = TRUE)


thibautjombart/geograph documentation built on Jan. 27, 2024, 10 p.m.