findLand: Find which nodes are on land

findLandR Documentation

Find which nodes are on land

Description

The generic function findLand uses information from a GIS shapefile to define which nodes are on land, and which are not. Strickly speaking, being 'on land' is in fact being inside a polygon of the shapefile.

Usage

findLand(x, ...)

## S4 method for signature 'matrix'
findLand(x, shape = "world", ...)

## S4 method for signature 'data.frame'
findLand(x, shape = "world", ...)

## S4 method for signature 'gGraph'
findLand(x, shape = "world", attr.name = "habitat", ...)

Arguments

x

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

...

further arguments to be passed to other methods. Currently not used.

shape

a shapefile of the class SpatialPolygonsDataFrame (see readShapePoly in maptools package to import such data from a GIS shapefile). Alternatively, a character string indicating one shapefile released with geoGraph; currently, only 'world' is available (see ?data(worldshape)).

attr.name

a character string giving the name of the node attribute in which the output is to be stored.

Details

Nodes can be specified either as a matrix of geographic coordinates, or as a gGraph object.

Value

The output depends on the nature of the input:
- matrix, data.frame: a factor with two levels being 'land' and 'sea'.

  • gGraph: a gGraph object with a new node attribute, possibly added to previously existing node attributes (@nodes.attr slot).

See Also

extractFromLayer, to retrieve any information from a GIS shapefile.

Examples



## create a new gGraph with random coordinates
myCoords <- data.frame(long = runif(1000, -180, 180), lat = runif(1000, -90, 90))
obj <- new("gGraph", coords = myCoords)
obj # note: no node attribute
plot(obj)

## find which points are on land
obj <- findLand(obj)
obj # note: new node attribute

## define rules for colors
temp <- data.frame(habitat = c("land", "sea"), color = c("green", "blue"))
temp
obj@meta$color <- temp

## plot object with new colors
plot(obj)


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