extractFromLayer | R Documentation |
The generic function extractFromLayer
uses information from a GIS
shapefile to define node attributes. For each node, information is retrieved
from the layer and assigned to that node.
extractFromLayer(x, ...)
## S4 method for signature 'matrix'
extractFromLayer(x, layer = "world", attr = "all", ...)
## S4 method for signature 'data.frame'
extractFromLayer(x, layer = "world", attr = "all", ...)
## S4 method for signature 'list'
extractFromLayer(x, layer = "world", attr = "all", ...)
## S4 method for signature 'gGraph'
extractFromLayer(x, layer = "world", attr = "all", ...)
## S4 method for signature 'gData'
extractFromLayer(x, layer = "world", attr = "all", ...)
x |
a matrix, a data.frame, a list, 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. For list, input must have two components being vectors giving longitudes and latitudes of locations. |
... |
further arguments to be passed to other methds. Currently not used. |
layer |
a shapefile of the class |
attr |
a character vector giving names of the variables to be extracted
from the layer. If 'all', all available variables are extracted. In case of
problem, available names are displayed with the error message. Available
data are also stored in |
Nodes can be specified in different ways, including by providing a gGraph or a gData object. Outputs match the input formats.
The output depends on the nature of the input:
- matrix,
data.frame, list
: a data.frame with one row per location, and as many
columns as requested variables ('attributes').
gGraph
: a gGraph object with new node attributes
(@nodes.attr
slot). If nodes attributes already existed, new
attributes are added as new columns.
gData
: a gData object with new data associated to
locations (@data
slot). New information is merge to older information
according to the type of data being stored.
findLand
, to find which locations are on land.
## Not run:
plot(worldgraph.10k, reset = TRUE)
## see what info is available
names(worldshape@data)
unique(worldshape@data$CONTINENT)
## retrieve continent info for all nodes
## (might take a few seconds)
x <- extractFromLayer(worldgraph.10k, layer = worldshape, attr = "CONTINENT")
x
table(getNodesAttr(x, attr.name = "CONTINENT"))
## subset Africa
temp <- getNodesAttr(x, attr.name = "CONTINENT") == "Africa"
temp[is.na(temp)] <- FALSE
x <- x[temp]
plot(x, reset = TRUE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.