Files
MicrOBU/obu-firmware/external/vanetza-idf/tools/country-data/plot.py
T
Ashin Walpola d107534eb2 Keep vanetza-idf in obu-firmware, so a plain clone builds the firmware
obu-firmware builds against the vanetza-idf C-ITS library, which until now
came from the colleague's microbu-esp32c5 tree beside the repository and was
not tracked here, so a clone of this repository could not build the firmware
it ships. The library alone is now part of obu-firmware, as
obu-firmware/external/vanetza-idf: their external/vanetza-idf at commit
cf4b99f, unchanged (9775 files; see its PROVENANCE.md). CMake takes it from
there by default; -DVANETZA_IDF_DIR still points the build elsewhere.

The rest of the colleague's tree (their own VAM firmware, PKI tooling,
station-link Python tools, the V2X2MAP bridge) stays out of this repository
and gitignored; nothing is pushed to their repository. NOTES.md, docs/06,
TODO.md and the pcap verifier's usage line point at the new location.
2026-09-24 10:56:05 +02:00

69 lines
1.9 KiB
Python

#!/usr/bin/env python3
# /// script
# requires-python = ">=3.9"
# dependencies = ["matplotlib", "shapely"]
# ///
"""Plot country polygons from a Vanetza country data binary file."""
import argparse
import colorsys
import struct
import sys
import matplotlib.pyplot as plt
from shapely import wkb
EXPECTED_FORMAT_VERSION = 1
def main():
parser = argparse.ArgumentParser(description="Plot country polygons from .bin file")
parser.add_argument("input", help="Path to country_data.bin")
args = parser.parse_args()
fig, ax = plt.subplots(figsize=(16, 8))
with open(args.input, "rb") as f:
data = f.read()
if len(data) < 2:
print("Error: file too short to contain version header", file=sys.stderr)
sys.exit(1)
version, = struct.unpack_from("<H", data, 0)
if version != EXPECTED_FORMAT_VERSION:
print(f"Error: unsupported country data format version {version}", file=sys.stderr)
sys.exit(1)
offset = 2
while offset < len(data):
m49, = struct.unpack_from("<H", data, offset)
offset += 2
wkb_size, = struct.unpack_from("<I", data, offset)
offset += 4
geom = wkb.loads(data[offset:offset + wkb_size])
offset += wkb_size
h = (m49 * 0.618) % 1.0
s = 0.5 + (hash(m49) % 50) / 100.0
l = 0.4 + (hash(m49 * 7) % 30) / 100.0
color = colorsys.hls_to_rgb(h, l, s)
for polygon in geom.geoms:
x, y = polygon.exterior.xy
ax.fill(x, y, alpha=0.4, edgecolor="black", linewidth=0.3, facecolor=color)
if polygon.area > 1.0:
centroid = polygon.centroid
ax.text(centroid.x, centroid.y, str(m49),
fontsize=5, ha="center", va="center")
ax.set_aspect("equal")
ax.set_xlabel("Longitude")
ax.set_ylabel("Latitude")
ax.set_title("Country Polygons")
plt.tight_layout()
plt.show()
if __name__ == "__main__":
main()