Title: | Package for road network operation with pgRouting |
---|---|
Description: | This package provides functions for road network operation with pgRouting. |
Authors: | Keisuke ANDO [aut, cre] |
Maintainer: | Keisuke ANDO <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.4 |
Built: | 2025-01-26 04:11:03 UTC |
Source: | https://github.com/NONONOexe/roadnetdb |
Connect to the database.
To disconnect, call disconnect_database()
.
connect_database( user = "admin", password = "p@ssw0rd", host = "localhost", port = 5432, dbname = "roadnetdb" )
connect_database( user = "admin", password = "p@ssw0rd", host = "localhost", port = 5432, dbname = "roadnetdb" )
user |
The user name (default: "admin"). |
password |
The password (default: "admin"). |
host |
The host name (default: "localhost"). |
port |
The port number (default: 5432). |
dbname |
The database name (default: "roadnetdb"). |
A connection to the database.
## Not run: connect_database() ## End(Not run)
## Not run: connect_database() ## End(Not run)
Create a table named osm_roads
in the database.
The osm_roads
manages OpenStreetMap road data and
has the following columns:
osm_id
: The ID of the road in OpenStreetMap
road_type
: The type of the road
road_name
: The name of the road
layer
: The layer of the road.
The layer represents the height of the road.
oneway
: Whether the road is one-way or not
geom
: The geometry of the road
create_table_osm_roads(conn)
create_table_osm_roads(conn)
conn |
A |
The function invisibly returns
TRUE
if the table was successfully created, FALSE
otherwise.
## Not run: create_table_osm_roads(con) ## End(Not run)
## Not run: create_table_osm_roads(con) ## End(Not run)
Disconnect from the database.
disconnect_database(conn)
disconnect_database(conn)
conn |
A |
The function returns
TRUE
if this is connected and disconnecting was done as expected or
FALSE
if this is not connected to the database.
## Not run: disconnect_database(con) ## End(Not run)
## Not run: disconnect_database(con) ## End(Not run)
The function download road data from OpenStreetMap using overpass query. Roads are records have the following values for the key, 'highway' in OpenStreetMap data.
motorway
trunk
primary
secondary
tertiary
unclassified
residential
motorway_link
trunk_link
primary_link
secondary_link
tertiary_link
For one-way roads, the column oneway
is TRUE
.
download_osm_roads(area)
download_osm_roads(area)
area |
A |
OpenStreetMap road data
## Not run: download_osm_roads(toyota) ## End(Not run)
## Not run: download_osm_roads(toyota) ## End(Not run)
Enable database extensions.
enable_postgis(conn) enable_pgrouting(conn)
enable_postgis(conn) enable_pgrouting(conn)
conn |
A |
The function returns
FALSE
if enabling fails or TRUE
if enabling succeeds.
## Not run: enable_postgis(con) enable_pgrouting(con) ## End(Not run)
## Not run: enable_postgis(con) enable_pgrouting(con) ## End(Not run)
The function fetch road data intersecting with the specified area
from osm_roads
table in the database.
fetch_osm_roads(conn, area)
fetch_osm_roads(conn, area)
conn |
A |
area |
A |
A sf with 6 variables:
The ID of the road in OpenStreetMap
The type of the road
The name of the road
The layer of the road. The layer represents the height of the road.
Whether the road is one-way or not
The geometry of the road
OpenStreetMap road data.
## Not run: fetch_osm_roads(con, toyota) ## End(Not run)
## Not run: fetch_osm_roads(con, toyota) ## End(Not run)
The function generates a road network in the specified area. A road network has intersection as nodes and road segments as edges. The function creates two tables representing edges and nodes of the network.
The function generates a road network by the following steps:
Generate road network edges from road data
Generate road network nodes from road network edges
Store the road network edges and nodes into the database
The road network edge table has the following columns:
id
: The ID of the edge
source
: The ID of the source node
target
: The ID of the target node
oneway
: Whether the edge is one-way or not
length
: The length of the edge in meters
parent
: The ID of the original road in OpenStreetMap
geom
: The geometry of the edge
The road network nodes table has the following columns:
id
: The ID of the node
geom
: The geometry of the node
The nodes are computed by pgr_createTopology
function in pgRouting.
If the distance between two nodes is less than 1 meter
in Web Mercator (EPSG 3857), the two nodes are merged into one node.
generate_road_network( conn, area, node_table = "road_nodes", edge_table = "road_edges" )
generate_road_network( conn, area, node_table = "road_nodes", edge_table = "road_edges" )
conn |
A |
area |
A |
node_table |
A |
edge_table |
A |
Number of rows of data updated.
## Not run: generate_road_network(con, toyota) ## End(Not run)
## Not run: generate_road_network(con, toyota) ## End(Not run)
The function generates a segmentized network in the specified area. A segmentized network is a network in which the edges of a road network are divided into segments of a specified length. The function creates two tables representing edges and nodes of the network.
The function generates a segmentized network by the following steps:
Split road network edges into segments as segmentized network edges
Generate segmentized network nodes from segmentized network edges
Store the segmentized network edges and nodes into the database
The node and edge tables of the segmentized network have the same columns as the road network node and edge tables.
generate_segmentized_network( conn, source_table = "road_edges", node_table = "segment_nodes", edge_table = "segment_edges", segment_length = 10 )
generate_segmentized_network( conn, source_table = "road_edges", node_table = "segment_nodes", edge_table = "segment_edges", segment_length = 10 )
conn |
A |
source_table |
A |
node_table |
A |
edge_table |
A |
segment_length |
A |
Number of rows of data updated.
## Not run: generate_segmentized_network(con) ## End(Not run)
## Not run: generate_segmentized_network(con) ## End(Not run)
Launch the database using docker. This function requires docker to be installed beforehand.
launch_database( user = "admin", password = "p@ssw0rd", dbname = "roadnetdb", port = 5432 )
launch_database( user = "admin", password = "p@ssw0rd", dbname = "roadnetdb", port = 5432 )
user |
The user name (default: "admin"). |
password |
The password (default: "p@ssword"). |
dbname |
The database name (default: "roadnetdb"). |
port |
The port number (default: 5432). |
The return code of this process.
## Not run: launch_database() ## End(Not run)
## Not run: launch_database() ## End(Not run)
Register OpenStreetMap road data into the database. If the specified road data has already been registered, this function update the data by specified road data as new data.
register_osm_roads(conn, osm_roads)
register_osm_roads(conn, osm_roads)
conn |
A |
osm_roads |
A data frame of OpenStreetMap road data. |
Number of rows of data updated.
## Not run: toyota_roads <- read_osm_roads(toyota) register_osm_roads(con, toyota_roads) ## End(Not run)
## Not run: toyota_roads <- read_osm_roads(toyota) register_osm_roads(con, toyota_roads) ## End(Not run)
Shutdown the database using docker. This function requires docker to be installed beforehand.
shutdown_database()
shutdown_database()
The return code of this process.
## Not run: shutdown_database() ## End(Not run)
## Not run: shutdown_database() ## End(Not run)