Skip to main content

2026-11-30 · 6 min read

Kaohsiung traffic accident map: the top hotspot had 10× the runner-up because coordinates were default values, and the four filters that found them

DataNext.jsDebugging

Translated from the Chinese original: read it in Chinese

The Kaohsiung traffic accident map (a tool page in Chinese) is the third page I made from government open data (the first two were Taiwan–Japan air passengers (in Chinese) and the population structure on the election map). The data is the National Police Agency's case-by-case A1 (death at the scene or within 24 hours) and A2 (injury) records, 8 yearly ZIP files from ROC year 107 to 114 (2018 to 2025), about 4.3 GB after unzipping.

One row is not one accident

In the raw data, one row is "one party involved". The same accident has 2 to 16 rows, so first they have to be merged by (date, time, location, latitude/longitude, category) into accidents before they can be counted. The numbers of deaths and injuries are packed in one string (like "deaths 1; injuries 0"). Vehicle types also have two spellings: "passenger car" and "passenger car (including passenger and cargo dual-use)" are the same category, and "person" really means pedestrian.

The top ranking was 10 times the second

The first version snapped coordinates to cells of about 200 meters and counted accidents per cell. The top cell: 8,842 accidents, with 25 A1. The second had 858. More than a thousand accidents a year at one intersection is impossible.

Looking at the location text under that coordinate: 1,284 accidents (in the single year 2018) share the one coordinate (120.30152, 22.62716), yet correspond to 1,161 different location strings. That is the default value filled in when geocoding fails. The same data also has (120.0, 22.0) (out at sea) and (121.518, 25.048) (in Taipei), neither within Kaohsiung.

Four filters, each catching one way of being bad

One rule alone cannot catch them all, because bad coordinates come in several shapes:

  1. Out of range: the coordinate is outside Kaohsiung's latitude/longitude range (the sea, Taipei).
  2. The exact same coordinate matching too many intersections: the same coordinate matches 6 or more different intersections. This catches the 1,284 case above.
  3. Default coordinates with jitter: the 2025 default point had about ±10 meters of noise added, so "exactly the same coordinate" no longer shows it. But within the same 200-meter cell in the same year, a pile of unrelated road names appear, for example one cell with 162 accidents and 82 road names, all roads from all over Lingya District, which is really the district center. A real intersection cell has only 1 to 3 roads. The rule: at least 12 road names in the same cell in the same year, and the number of road names at least 40% of the accident count.
  4. Too far from land: if a cell center is more than about 400 meters from any district polygon, it is a point at sea.

I also specifically checked whether the third filter kills innocent data: of the 455 excluded cell-year groups, nearly half belong to a single district (roads from all over one district piled into one point), and the rest span 2 or more districts; I looked at the groups with the most accidents, and they are all this "a whole district's roads crammed into one point" kind. After exclusion, the top spot became "Zuoying District, Boai 2nd Road / Yucheng Road" with 385 accidents, about 48 a year, and the following ranks are real major intersections too, with numbers that add up.

Unusable accidents are about 13% to 21% each year. These accidents are still counted in totals, time-of-day and cause statistics (which do not depend on coordinates), just not placed on the map or in the hotspot ranking, and the page states this share explicitly.

Verification: make this kind of error shout next time

Two unit tests guard this: across all years the top hotspot is never 2 times or more the second (the typical symptom of default coordinates), and the share of usable coordinates each year must fall between 75% and 99.5% (excluding too much or too little is suspicious either way). The script also has a calibration indicator: the share of accident points that fall inside the polygon of their own district, currently 87.7%; below 75% the whole thing is switched off.

Base map: the election map's township boundaries

For Kaohsiung's district boundaries I directly use the election map's township boundaries instead of adding a mapping library. But its coordinates are not latitude and longitude. I convert with a linear approximation, calibrating the parameters against "the share of accident points falling inside their own district": a grid search over the offset, and the current value is a sharp maximum (with an offset of just 0.01 units, the hit rate drops from 85% to below 68%).

National A1 jumped in 2018 to 2019 at the same time

Kaohsiung's fatal accidents (A1) were 140 in 2018 and 205 in 2019, which looks like a surge. But the whole country did the same: 1,458 to 1,815, then flat for the following years. It looks like a change in statistics or in how cases are recorded, not a real increase. The page puts the national A1 next to the year-by-year table and suggests looking at trends from 2019, without explaining the cause.

A React 19 trap: SVG title must be a single string

The weekday × hour heat map has a <title> in every cell as the hover hint. I wrote it as <title>{DAYS[wd]} {h}:00–{h}:59: {nf.format(v)} accidents</title>, which has several text child nodes. The result was that the "no console errors" check of the production-build E2E failed: React error #418 (hydration mismatch). Changing it to a single string ({`${...}`}) fixed it.

Finding the cause involved a detour too: I read the console in the browser pane and kept seeing the same error, even after I removed the <title> completely. The reason was that the pane had an old cache (the site has a service worker) and I was reading the old version's message. To verify the fix, use a fresh Playwright environment, not the same pane refreshed.

What this page does not do

  • There is no "most dangerous intersection" conclusion: the ranking is accident counts, not divided by traffic volume.
  • The cause is the police's preliminary judgment, not a determination of fault; "party 1" is the registered order 1, not necessarily the one who caused the accident.
  • A1 only counts deaths within 24 hours, and the official 30-day death statistics would be higher.

Type to search projects and posts too