Read Geographical Information in Graph Format

Share:

Description

Reads the geographical information provided in a file in graph format and stores it in a map object.

Usage

1
read.gra(file, sorted = FALSE, sep = " ")

Arguments

file

the file path of the graph file to be read.

sorted

logical. Should the regions be ordered by the numbers specifying the region names (sorted = TRUE)?

sep

the field separator character. Values on each line of the file are separated by this character.

Details

A graph file stores the nodes and the edges of a graph and is a convenient way to represent the neighborhood structure of a geographical map. The structure of a graph file is given by:

  • The first line of the graph file specifies the total number of nodes.

  • The subsequent three lines correspond to the node with the name given in line 2, the number of neighbors in line 3 and the neighboring node identity numbers in line 4.

Note that the note identity numbering starts with 0. Example taken from the package example file Germany.gra:

309
1001
1
1
1059
3
0 3 4
1002
2
5 4
1051
3
4 1 9
1058
7
2 6 3 5 1 10 9
...

Hence, this graph file contains of 309 regions. The first region with name 1001 has 1 neighbor with neighboring node identity number 1. The last region in this example, region 1058, has 7 neighbors with neighboring node identity numbers 2 6 3 5 1 10 9.

In addition, graph files using the following format may be imported:

  • The first line of the graph file specifies the total number of nodes.

  • The subsequent lines start with the node name followed by the number of neighbors and the neighboring node identity numbers.

Example:

309
1001 1 2
1059 3 1 4 5
1002 2 6 5
1051 3 5 2 10
1058 7 3 7 4 6 2 11 10
...

Value

Returns an adjacency matrix that represents the neighborhood structure defined in the graph file. The diagonal elements of this matrix are the number of neighbors of each region. The off-diagonal elements are either -1 if regions are neighbors else 0.

Author(s)

Thomas Kneib, Felix Heinzl, rewritten by Nikolaus Umlauf.

References

BayesX Reference Manual, Chapter 5. Available at http://www.BayesX.org.

See Also

write.gra, read.bnd, write.bnd, get.neighbor, add.neighbor, delete.neighbor.

Examples

1
2
file <- file.path(find.package("R2BayesX"), "examples", "Germany.gra")
germany <- read.gra(file)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.