-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
178 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
# nvdb2xodr | ||
Convert Vegvesen NVDB road network to OpenDrive | ||
Convert Vegvesen NVDB road networks to OpenDRIVE files | ||
|
||
## Usage: | ||
1. Install requirements: `pip install -r requirements.txt` | ||
2. Make a new configuration of the area you want to convert in `run_tools.py` and make sure `run_download_data()` is run in `__main__` | ||
3. Run the download script: `run_tools.py` | ||
4. Make a new configuration in `nvdb_to_opendrive.py` using the same JSON file | ||
5. Run it: `python nvdb_to_opendrive.py` | ||
|
||
## TODO: | ||
- [x] Junctions | ||
- [ ] Fix roundabouts and missing roads | ||
- [ ] Incorporate optional FKB data | ||
- [ ] Handle changing number of lanes properly | ||
- [ ] Infer turn restrictions | ||
- [ ] Incorporate optional road polygon data | ||
- [ ] Expand to OSM dataset | ||
- [ ] Lane access for bus lanes | ||
- [ ] Setting types for exit ramps | ||
- [ ] Setting types for exit ramps | ||
- [x] Fix roundabouts and missing roads | ||
- [x] Junctions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
lxml | ||
numpy | ||
pyproj | ||
requests | ||
shapely | ||
tqdm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,88 @@ | ||
import json | ||
import os | ||
import uuid | ||
from tools import download_data | ||
import nvdb_to_opendrive | ||
from pathlib import Path | ||
from time import time | ||
|
||
download_data.run() | ||
|
||
def run_download_data(): | ||
gløshaugen = ("270000,7039700,271200,7041000", "../Notebooks/veglenkesekvens_gloshaugen.json") | ||
sandmoen = ("267500,7030500,268500,7031500", "../Notebooks/veglenkesekvens_sandmoen.json") | ||
|
||
download_data.run(*sandmoen) | ||
|
||
|
||
def benchmark_function(function, measure_memory=True): | ||
if measure_memory: | ||
import tracemalloc | ||
tracemalloc.start() | ||
|
||
start_time = time() | ||
result = function() | ||
total_time = time() - start_time | ||
|
||
response = {"execution_time": total_time} | ||
if result is not None: | ||
response["result"] = result | ||
|
||
if measure_memory: | ||
memory_usage = tracemalloc.get_traced_memory() | ||
response["memory_usage"] = memory_usage | ||
tracemalloc.stop() | ||
|
||
return response | ||
|
||
|
||
def run_download_data_multi(): | ||
center = (268000, 7031000) | ||
width_min = 500 | ||
width_max = 5000 | ||
width_delta = 100 | ||
def output_file(width): return f"../Notebooks/nvdb_multi_sandmoen/veglenkesekvens_sandmoen_{width}.json" | ||
output_path = "../Notebooks/nvdb_download_times_sandmoen.json" | ||
|
||
Path(output_file("")).parent.mkdir(exist_ok=True) | ||
|
||
benchmark_results = [] | ||
for width in range(width_min, width_max + 1, width_delta): | ||
print(f"Downloading area of size {width}*{width} m^2") | ||
boundary = f"{center[0]-width//2},{center[1]-width//2},{center[0]+width//2},{center[1]+width//2}" | ||
result = benchmark_function(lambda: download_data.run(boundary, output_file(width)), measure_memory=False) | ||
result["width"] = width | ||
benchmark_results.append(result) | ||
|
||
with open(output_path, "w") as f: | ||
json.dump(benchmark_results, f, indent=4) | ||
|
||
|
||
def run_nvdb_to_opendrive_multi(measure_memory=True): | ||
input_path = "../Notebooks/nvdb_multi_sandmoen" | ||
output_path = "../Notebooks/nvdb_execution_times_sandmoen.json" | ||
|
||
files = {} | ||
for file in Path(input_path).glob("*.json"): | ||
width = int(file.stem.split("_")[-1]) | ||
files[width] = file | ||
|
||
benchmark_results = [] | ||
for width, file in sorted(files.items()): | ||
print(f"Running nvdb_to_opendrive.py on area of size {width}*{width} m^2") | ||
output_file = f"temp-{uuid.uuid4()}.xodr" | ||
config = nvdb_to_opendrive.Config(str(file), output_file, "") | ||
|
||
result = benchmark_function(lambda: nvdb_to_opendrive.main(config)) | ||
result["width"] = width | ||
benchmark_results.append(result) | ||
|
||
os.remove(output_file) | ||
|
||
with open(output_path, "w") as f: | ||
json.dump(benchmark_results, f, indent=4) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_download_data() | ||
#run_download_data_multi() | ||
#run_nvdb_to_opendrive_multi() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters