Learn R Programming

graph4lg (version 2.0.0)

graph_to_shp: 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
)

Value

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

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)

Author

P. Savary

Details

Note that exporting shapefile layers can limit the number of digits you can include in numeric fields, as well as the length of column names. Column names are renamed to allow the export but the number of digits can generate errors. You are strongly encouraged to use graph_to_gpkg() in the latter case.

Examples

Run this code
if (FALSE) {
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)
 }

Run the code above in your browser using DataLab