graph_to_shp: Export a spatial graph to shapefile layers

View source: R/graph_to_shp.R

graph_to_shpR Documentation

Export a spatial graph to shapefile layers

Description

The function enables to export a spatial graph to shapefile layers.

Usage

graph_to_shp(
  graph,
  crds,
  mode = "both",
  crds_crs,
  layer,
  dir_path,
  metrics = FALSE
)

Arguments

graph

A graph object of class igraph

crds

(if 'mode = 'spatial”) A data.frame with the spatial coordinates of the graph nodes. It must have three columns:

  • ID: Name of the graph nodes (will be converted into character string). The names must the same as the node names of the graph object of class igraph (igraph::V(graph)$name)

  • x: Longitude (numeric or integer) of the graph nodes in the coordinates reference system indicated with the argument crds_crs.

  • y: Latitude (numeric or integer) of the graph nodes in the coordinates reference system indicated with the argument crds_crs.

mode

Indicates which shapefile layers will be created

  • If 'mode = 'both” (default), then two shapefile layers are created, one for the nodes and another for the links.

  • If 'mode = 'node”, a shapefile layer is created for the nodes only.

  • If 'mode = 'link”, a shapefile layer is created for the links only.

crds_crs

An integer indicating the EPSG code of the coordinates reference system to use. The projection and datum are given in the PROJ.4 format.

layer

A character string indicating the suffix of the name of the layers to be created.

dir_path

A character string corresponding to the path to the directory in which the shapefile layers will be exported. If dir_path = "wd", then the layers are created in the current working directory.

metrics

(not considered if 'mode = 'link”) Logical. Should graph node attributes integrated in the attribute table of the node shapefile layer? (default: FALSE)

Value

Create shapefile layers in the directory specified with the parameter 'dir_path'.

Author(s)

P. Savary

Examples

## Not run: 
data(data_tuto)
mat_w <- data_tuto[[1]]
gp <- gen_graph_topo(mat_w = mat_w, topo = "gabriel")
crds_crs <- 2154
crds <- pts_pop_simul
layer <- "graph_dps_gab"
graph_to_shp(graph = gp, crds = pts_pop_simul, mode = "both",
             crds_crs = crds_crs,
             layer = "test_fonct",
             dir_path = tempdir(),
             metrics = FALSE)
 
## End(Not run)

graph4lg documentation built on Feb. 16, 2023, 5:43 p.m.