Navi9500 - PC map tools
=======================

Makes the phone's map file (.NMP) from OpenStreetMap data. The PC does all the
hard work (projection, drawing, anti-aliasing, labels, colour reduction); the
phone only unpacks RLE runs into screen memory.

Python 3 + Pillow + numpy. Fonts: Tahoma / Verdana from C:\Windows\Fonts.

FILES
  uusikaupunki.ini  region: OSM file, box (west,south,east,north), zooms
  osm\query.overpassql   the Overpass query used for the download
  osm\uusikaupunki.osm   OSM extract (122 MB, 2026-10-31); .pickle = parsed cache
  geo.py            Web Mercator helpers ("world units" 0..1, y south)
  osmload.py        OSM XML -> features; multipolygons; coastline -> land polygons
  style.py          colours, road widths per zoom, label rules (edit this to restyle)
  render.py         tiles -> out_<region>\tiles\z\x\y.png (4 processes)
  preview.py        stitch a view, e.g. the 640x200 phone screen
  mappack.py        tiles -> out_<region>\<region>.nmp; --check, --view, --selftest
  navbuild.py       OSM -> out_<region>\<region>.nav: road graph (drive times,
                    one-ways, roundabouts) + search index (streets, house
                    numbers, places). Format at the top of the file.
  navtool.py        reference reader/router for .nav: search, Dijkstra route,
                    route drawn on the map (--png). The phone's navcore.c must
                    give the same costs (phone\tests\navtest.c batch).

STEPS
  1. Download (once; Overpass API, ~2 min):
       see osm\query.overpassql - POST it to https://overpass-api.de/api/interpreter
  2. python render.py uusikaupunki.ini              (~20 min for zooms 10-16)
       --zooms 14-15 / --tile 15/18337/9371 for partial re-renders
  3. python preview.py uusikaupunki.ini 60.800 21.405 15 --size 640x200 --scale 2
  4. python navbuild.py uusikaupunki.ini           (~45 s)
     python navtool.py out_uusikaupunki\uusikaupunki.nav search alinenkatu 5
     python navtool.py out_uusikaupunki\uusikaupunki.nav route 60.784 21.461 60.8 21.404 --png r.png --nmp out_uusikaupunki\uusikaupunki.nmp
  5. python mappack.py uusikaupunki.ini          (zlib tiles, ~49 MB; --codec rle = old 114 MB format)
     python mappack.py --check out_uusikaupunki\uusikaupunki.nmp
     python mappack.py --view out_uusikaupunki\uusikaupunki.nmp 60.8 21.405 15 -o v.png
  6. Vector map of all of Finland (the format the phone will draw):
     python finbuild.py osm\finland\finland-latest.osm.pbf out_finland\finland.nvm   (~75 min, 187 MB, version 1)
     python reland.py osm\finland\finland-latest.osm.pbf out_finland\finland.nvm      (redo only land/sea, ~6 min)
     python shrink.py out_finland\finland.nvm out_finland\finland_v2.nvm --area-tol 2.0 --min-area 128 --line-tol 1.0
                                                     (~20 min, 118 MB, version 2 = the file for the phone)
       ... --drop forest  -> out_finland\finland_v2_noforest.nvm (81.7 MB, no forest areas)
     python shrink.py out_finland\finland.nvm --measure     (sizes of variants, ~3 min)
     python vecview.py out_finland\finland_v2.nvm 60.17 24.94 15 -o v.png
     Formats: version 1 at the top of vecbuild.py, version 2 blocks at the top of nvm2.py.
     python mkvecstyle.py      after editing style.py: writes ..\phone\vecstyle.h for the phone
  7. Routing and search for all of Finland (.nvr, read by ..\phone\navfin.c):
     python navextract.py osm\finland\finland-latest.osm.pbf out_finland\navsrc.pkl   (~16 min, once)
     python poiextract.py osm\finland\finland-latest.osm.pbf out_finland\navpoi.pkl   (~12 min, once: shops etc.)
     python navfin.py out_finland\navsrc.pkl out_finland\finland.nvr --no-tracks       (~7 min, takes navpoi.pkl too)
     python hospextract.py osm\finland\finland-latest.osm.pbf out_finland\navhosp.pkl (once: hospitals' emergency=*)
     python emgbuild.py out_finland\finland.nvr out_finland\navpoi.pkl out_finland\navhosp.pkl out_finland\finland_emg.nvr
                                       (~10 s: adds the emergency section, Hatatiedot; +9 MB)
     python navfinread.py out_finland\finland.nvr search --query "koulukatu 5" --near 60.8,21.41
       ... search --kind 2 --query kalanti   (cities)   ... search --kind 3 --query k-super   (places)
     python navmeasure.py osm\finland\finland-latest.osm.pbf     (road/address counts only)
     Formats: navfin.py (graph, cells, trunk shortcuts) and navfinsearch.py (search).
     Checks: ..\phone\tests\nftest.c (also: nftest FILE emg LAT LON), nfcompare.py (routes vs the true optimum).

  8. Voice prompts: python mkvoice.py [--list]
     ..\Voice\*.wav / *.ogg (ffmpeg decodes them) -> ..\phone\voice.vox (2.8 MB):
     silence trimmed, loudness evened out, 16 kHz 16-bit. Format at the top.

NOTES
  - The sea is the background colour; land comes from natural=coastline ways,
    chained (land on the left) and closed along the data box edge.
  - Outside the data box tiles are grey (no data), not sea.
  - Map data (c) OpenStreetMap contributors, ODbL. The phone app must show this.
  - Format of the .NMP file: see the top of mappack.py.
