An osm_graph is deliberately thin: tidy sf
nodes and edges. That makes it easy to hand off to the rest of the R
spatial-network ecosystem, or to export for other tools.
The nodes and edges are always available as sf:
parts <- ox_as_sf(g)
parts$edges
#> Simple feature collection with 1191 features and 5 fields
#> Geometry type: LINESTRING
#> Dimension: XY
#> Bounding box: xmin: -34.86427 ymin: -8.019512 xmax: -34.84686 ymax: -7.999988
#> Geodetic CRS: WGS 84
#> First 10 features:
#> u v length highway name
#> 1 3567235794 655141381 143.059872 trunk Avenida Pan Nordestina
#> 2 655141381 1572683340 39.206250 trunk Avenida Pan Nordestina
#> 3 655141381 1572703444 108.819636 residential Rua Honorato do Espírito Santo
#> 4 1572703444 655141381 108.819636 residential Rua Honorato do Espírito Santo
#> 5 655144602 655144717 47.559016 tertiary Rua Lucilo Varejão
#> 6 655144717 655144602 47.559016 tertiary Rua Lucilo Varejão
#> 7 655144602 1446749601 94.315783 tertiary Rua Manuel Clementino Marques
#> 8 1446749601 655144602 94.315783 tertiary Rua Manuel Clementino Marques
#> 9 655144602 7271784016 2.199505 tertiary Rua Manuel Clementino Marques
#> 10 7271784016 655144602 2.199505 tertiary Rua Manuel Clementino Marques
#> geometry
#> 1 LINESTRING (-34.85776 -8.00...
#> 2 LINESTRING (-34.85716 -8.00...
#> 3 LINESTRING (-34.85716 -8.00...
#> 4 LINESTRING (-34.85675 -8.00...
#> 5 LINESTRING (-34.85867 -8.00...
#> 6 LINESTRING (-34.85889 -8.00...
#> 7 LINESTRING (-34.85867 -8.00...
#> 8 LINESTRING (-34.8595 -8.007...
#> 9 LINESTRING (-34.85867 -8.00...
#> 10 LINESTRING (-34.85865 -8.00...Convert to an sfnetwork for the tidygraph
verb workflow, or to a bare tbl_graph:
ox_as_dodgr() returns the column layout
dodgr expects, so you can use its highly optimised routing
directly:
Export edges to GeoJSON, or build a MapLibre GL style fragment that points at the written data:
ox_save_graphml() / ox_load_graphml()
persist the graph in a format compatible with OSMnx, NetworkX and Gephi.
Edge geometry is stored as WKT, so the round-trip is lossless: