| writeNetwork | R Documentation |
Write a SpatNetwork to disk as a GDAL Geographic Network Model (GNM) dataset. Use netw(filename) to read it back in.
A GNM dataset stores the network topology, the node and edge geometries, the edge weights, the directedness flag and the network's spatial reference in a self-contained directory (filetype="GNMFile") or single OGR-compatible database (filetype="GNMDatabase"). It is the only widely-supported on-disk format that round-trips a topological network with both geometry and attributes.
## S4 method for signature 'SpatNetwork,character'
writeNetwork(x, filename, filetype="GNMFile", overwrite=FALSE, options=NULL, ...)
x |
|
filename |
character. Path to write to. For |
filetype |
character. One of |
overwrite |
logical. If |
options |
character. Optional driver-specific creation options, formatted as |
... |
additional arguments (currently ignored). |
A "GNMFile" dataset is a directory containing two "class" layers (nodes and edges) plus the GNM system layers (_gnm_meta, _gnm_graph, _gnm_features, _gnm_srs.prj). The default backend is ESRI Shapefile, so a freshly-written network is just a directory of .shp/.dbf/.shx/.prj/.dbf files plus the system files.
What round-trips through GNM and what doesn't:
Preserved exactly: node coordinates, edge geometries, the topology incidence list, the edge length cache, the edge weight cache, directedness, and the network's CRS.
Lost: source_id attribution and any user-attached columns on net_edges() or net_nodes() that go beyond the GNM-defined fields. (GNM has no concept of user attribute schemas on its class layers.)
GNM support requires GDAL \geq 2.4 built with the GNM component enabled. If your GDAL was built without GNM, this function fails with a message and netw(filename) cannot read GNM datasets back in.
Invisibly TRUE on success. On failure terra raises an error.
netw, shortestPath
## Not run:
v <- vect(rbind(
"LINESTRING(0 0, 10 10)",
"LINESTRING(0 10, 10 0)"
), crs = "EPSG:32633")
n <- netw(v)
dst <- file.path(tempdir(), "mynet")
writeNetwork(n, dst, overwrite = TRUE)
# Read back through netw():
n2 <- netw(dst)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.