Skip to content

Commit ba05061

Browse files
authored
scripts for route (#3490)
1 parent aaf98dd commit ba05061

5 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
These scripts are used to help automate parts of route graph generation process.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import geopandas as gpd
2+
import pandas as pd
3+
import sys
4+
from datetime import datetime
5+
6+
try:
7+
file_prefix = sys.argv[1]
8+
edges = gpd.read_file(sys.argv[2])
9+
nodes = gpd.read_file(sys.argv[3])
10+
except:
11+
raise Exception("Incorrect arguements provided")
12+
13+
now = datetime.now()
14+
15+
graph = pd.concat([nodes, edges])
16+
17+
file_name = file_prefix + "_" + now.strftime("%m_%d_%Y_%H_%M_%S") + ".geojson"
18+
19+
graph.to_file(file_name, driver='GeoJSON')
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
WITH start_points AS
2+
(
3+
SELECT n.id AS node_id
4+
,e.id AS edge_id
5+
,e.geometry AS edge_geometry
6+
FROM edges AS e, nodes AS n
7+
WHERE ST_INTERSECTS(n.geometry, ST_StartPoint(e.geometry))
8+
), end_points AS
9+
(
10+
SELECT n.id AS node_id
11+
,e.id AS edge_id
12+
,e.geometry AS edge_geometry
13+
FROM edges AS e, nodes AS n
14+
WHERE ST_INTERSECTS(n.geometry, ST_EndPoint(e.geometry))
15+
)
16+
SELECT sp.edge_id AS edge_id
17+
,sp.node_id AS start_node
18+
,ep.node_id AS end_node
19+
,sp.edge_geometry AS geometry
20+
FROM start_points AS sp
21+
JOIN end_points AS ep
22+
ON sp.edge_id = ep.edge_id
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"author": "josh",
3+
"exported_at": "2023-03-15T19:27:03",
4+
"expressions": [
5+
{
6+
"description": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n<html><head><style type=\"text/css\">\np, li { white-space: pre-wrap; }\n</style></head><body style=\" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;\">\n<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>",
7+
"expression": "if(maximum(\"id\") is null, 10000, maximum(\"id\")+1)",
8+
"group": "user",
9+
"name": "increment_edge_id",
10+
"type": "expression"
11+
},
12+
{
13+
"description": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n<html><head><style type=\"text/css\">\np, li { white-space: pre-wrap; }\n</style></head><body style=\" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;\">\n<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>",
14+
"expression": "if(maximum(\"id\") is null, 0, maximum(\"id\")+1)",
15+
"group": "user",
16+
"name": "increment_node_id",
17+
"type": "expression"
18+
}
19+
],
20+
"qgis_version": "3.22.4-Białowieża"
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"author": "josh",
3+
"exported_at": "2023-03-15T19:22:14",
4+
"expressions": [
5+
{
6+
"description": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n<html><head><style type=\"text/css\">\np, li { white-space: pre-wrap; }\n</style></head><body style=\" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;\">\n<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>",
7+
"expression": "if(maximum(\"id\") is null, 0, maximum(\"id\")+1)",
8+
"group": "user",
9+
"name": "increment_node_id",
10+
"type": "expression"
11+
}
12+
],
13+
"qgis_version": "3.22.4-Białowieża"
14+
}

0 commit comments

Comments
 (0)