Validate a directed movement ledger before drawing arrows, preserve reciprocal flows, and avoid false straight-line paths near the dateline.
Flow maps: separate direction, magnitude and geographic route
A map does not repair a broken movement ledger
A geographic flow map places directed movements between locations. The link may represent shipments, journeys or messages, but it needs a declared unit and time window. Define whether 47 means shipments, parcels, people or distinct vehicles; these are different grains and cannot share a width scale. One record needs a stable origin, destination, direction and nonnegative magnitude. Reciprocal routes are not one undirected line: 47 units eastward and 23 westward have different operational meaning even if they use the same endpoints. Aggregate only records with the same directed pair and compatible time and unit definitions. Compare the sum of mapped links with the source ledger before rendering. Any excluded route, unknown endpoint or local movement needs an explicit count. Sankey reconciliation and directed chord flows expose the same accounting risks without geography.
Treat coordinates as locations, not routes
The endpoints are geographic facts; the line between them is often just a schematic connection. An aircraft, truck or fiber packet may not follow the shortest path. If the chart uses straight projected segments, label them as connections rather than surveyed routes. A great-circle arc gives a spherical shortest connection, yet a map projection bends that arc and may split it at the antimeridian. Drawing a straight line between longitude 179 and longitude minus 178 on a world map can send a three-degree connection almost all the way around the display. The code validates longitude and latitude, computes a wrapped longitude difference and estimates great-circle distance as a diagnostic. It does not claim the movement actually followed that path. Use a projection-aware renderer to interpolate, clip and draw the arc. Dateline handling is required before global deployment.
Encode magnitude without losing the small flows
Arrow width should follow a published scale and unit. Linear width makes a route of 40 units twice as thick as one of 20, but the total ink area also depends on route length; never ask users to infer volume from ink area. If a square-root width scale prevents large links from dominating, say so and show the numeric values beside the map. Two-way traffic needs offset curves, paired arrows or an interactive direction filter so the reciprocal links do not hide each other. Dense hubs can become opaque even when the ledger is correct. Filter by origin, destination or period, then retain the full route table and its total. Grouping minor routes into an unnamed Other line with no endpoint creates a false geographic path. Proportional symbols and linked filters help when destinations crowd together.
Expose the ledger next to the map
A useful flow map includes a table with origin, destination, direction, magnitude, unit, period and any route method. A keyboard user should reach that table without trying to select a hairline arrow. A reader should be able to sort by largest flow and see the same filters that shaped the map. If positions are deliberately jittered to separate overlapping links, keep the true coordinates in the export and say that the display geometry was adjusted. Do not publish precise coordinates for sensitive facilities when aggregated regions answer the question; the mapped grain itself is a disclosure choice. For before-and-after comparisons, freeze the projection, viewport and width scale so movement in the graphic reflects changed data rather than changed camera settings. Accessible chart controls and export manifests cover the delivery layer.
Worked contract
from collections import Counter
from math import asin, cos, isfinite, radians, sin, sqrt
def prepare_transfer_flows(sites, transfers):
if not sites or not transfers:
raise ValueError("sites and transfers are required")
for site, point in sites.items():
if (not site or not isinstance(point, tuple) or len(point) != 2 or
any(isinstance(value, bool) or not isinstance(value, (int, float))
or not isfinite(value) for value in point) or
not -180 <= point[0] <= 180 or not -90 <= point[1] <= 90):
raise ValueError(f"invalid coordinate: {site}")
directed = Counter()
for origin, destination, units in transfers:
if (origin not in sites or destination not in sites or origin == destination or
isinstance(units, bool) or not isinstance(units, int) or units <= 0):
raise ValueError("invalid directed transfer")
directed[(origin, destination)] += units
routes = []
for (origin, destination), units in sorted(directed.items()):
west_lon, west_lat = sites[origin]
east_lon, east_lat = sites[destination]
delta_lon = ((east_lon - west_lon + 180) % 360) - 180
delta_lat = east_lat - west_lat
arc = sin(radians(delta_lat) / 2) ** 2 + (
cos(radians(west_lat)) * cos(radians(east_lat)) *
sin(radians(delta_lon) / 2) ** 2)
distance_km = 2 * 6371.0088 * asin(min(1.0, sqrt(arc)))
routes.append((origin, destination, units, round(distance_km, 1)))
assert sum(route[2] for route in routes) == sum(row[2] for row in transfers)
return routes
sites = {"West sensor": (179, -17), "East sensor": (-178, -16),
"Inland hub": (-176, -15)}
transfers = [("West sensor", "East sensor", 31),
("West sensor", "East sensor", 16),
("East sensor", "West sensor", 23),
("West sensor", "Inland hub", 11)]
routes = prepare_transfer_flows(sites, transfers)
assert sum(route[2] for route in routes) == 81
assert any(route[:3] == ("West sensor", "East sensor", 47) for route in routes)
assert any(route[:3] == ("East sensor", "West sensor", 23) for route in routes)Performance and operating cost
With E transfer rows and V site records, coordinate checks and directed aggregation take O(V + E) expected time and O(V + R) space, where R is the number of unique directed pairs. Sorting the aggregated pairs for stable export adds O(R log R) time. The distance calculation is constant work per pair and is only a spherical diagnostic, not an observed itinerary. The worked ledger totals 81 units across three directed routes, including 47 eastward and 23 westward between the same two sites. A projection-aware drawing library still has to sample and clip each route according to the chosen map projection.
Common Mistakes
- Combining reciprocal movements into one undirected route.
- Drawing a long straight line across the map when a short connection crosses the dateline.
- Calling a schematic or great-circle connector the observed travel path.
- Changing arrow-width scale between panels while comparing periods.
- Dropping unknown endpoints or self-movements without reconciling the excluded total.
Validation drill
Take 47 directed dispatch records, including reverse movements and a route near the antimeridian. Reconcile the displayed sum with the ledger, label the connection method, and provide a sortable route table before adding arrow geometry.
