Trending

World technology news

→
Splitting a GeoJSON route at the antimeridian
Software Engineering · 2016
Software Engineering2016

Splitting a GeoJSON route at the antimeridian

A local RFC 7946 experiment splits a ferry leg and checks a bounding box that crosses the antimeridian.

Archive retrospective · Topic year 2016

Developer's JournalPublished: Dec 4, 20266 min read
Reading progress0%
In this article
  1. A ferry leg with two plausible drawings
  2. Work on one continuous longitude interval
  3. When west is numerically greater than east
  4. What the Windows run actually checks
  5. Keep source fixes and derived cuts separately
  6. Acceptance tests for a wider route service

A ferry leg with two plausible drawings

A fictional ferry export contains a fix at longitude 179 and latitude 12, followed by a fix at longitude minus 179 and latitude 14. Plot the numbers as ordinary points on a flat chart and the line can appear to travel almost around the world. The dispatch team would see a very different area of operation. RFC 7946, published in August 2016, gives GeoJSON a common coordinate contract. Longitude precedes latitude and coordinates use decimal degrees. A device that supplies latitude first needs an explicit adapter at the ingestion boundary. A pair of known ports is a more useful ingestion fixture than range validation on its own. Both fields can fall in their shared legal range even when the application has swapped them.

Illustrative diagram of a ferry leg split at the 180° and −180° edges.

Work on one continuous longitude interval

For this eastbound example, temporarily express minus 179 as 181. The cut at 180 lies halfway between 179 and 181, giving latitude 13 by linear interpolation in coordinate space. End the first line on positive 180 and start the second on negative 180 at that same latitude. Store the result as one feature with a MultiLineString geometry. The duplicated boundary position represents two coordinate descriptions of the same meridian. This operation makes a portable drawing from the supplied positions. A maritime routing problem would have to account for a different set of facts. The two input positions provide no evidence about elapsed time, distance travelled, an intermediate port or a safe sailing corridor. Those belong to the voyage and its measurements.

Application flowConceptual sketch · summary of the article's technical flow

When west is numerically greater than east

For this feature the intended bounding box is 179, 12, minus 179, 14. Sorting the longitudes would give a width of 358 degrees and make a narrow crossing look like an almost global query. RFC 7946 allows the east coordinate of an antimeridian-crossing box to be numerically smaller than its west coordinate. One application can implement the query with two longitude ranges, keeping the same latitude filter in both. Deduplicate by the feature identifier after merging the results, since a stored leg can have geometry in both ranges. A collection that crosses the line in several places needs a separately specified query policy. Test equality at the meridian and confirm that the spatial index and the display layer follow the same convention.

What the Windows run actually checks

The Python 3.12 program checks both expected line components, the box values and the maximum longitude jump within each component. It then prints a single feature containing the two arrays and a shared latitude of 13 at the cut. Giving the helper an ordinary segment away from the meridian raises the expected ValueError. That failure is part of the small experiment. The helper deliberately handles one eastbound crossing with known inputs, so the same call does not silently transform a segment it does not understand. This run exercised a current interpreter against rules from the 2016 specification. It did not run a period mapping library. An integration test can parse the printed object and compare numeric values, so whitespace or equivalent number formatting does not obscure the geometry.

import json
from math import isfinite

def eastbound_crossing(a, b):
    """One demonstrative eastbound crossing, with input in WGS 84."""
    x1, y1 = a
    x2, y2 = b
    if not all(isfinite(v) for v in (*a, *b)):
        raise ValueError("non-finite position")
    if not (0 < x1 < 180 and -180 < x2 < 0 and x1 - x2 > 180
            and all(-90 <= y <= 90 for y in (y1, y2))):
        raise ValueError("expected eastbound antimeridian crossing")
    east = x2 + 360
    cut = y1 + (y2 - y1) * ((180 - x1) / (east - x1))
    return {
        "type": "Feature",
        "geometry": {"type": "MultiLineString", "coordinates": [
            [a, [180, cut]], [[-180, cut], b],
        ]},
        "bbox": [x1, min(y1, y2), x2, max(y1, y2)],
        "properties": {"fixture": "synthetic-ferry-leg"},
    }

feature = eastbound_crossing([179, 12], [-179, 14])
assert feature["geometry"]["coordinates"] == [
    [[179, 12], [180, 13.0]], [[-180, 13.0], [-179, 14]],
]
assert feature["bbox"] == [179, 12, -179, 14]
assert all(abs(a[0] - b[0]) <= 180
           for a, b in feature["geometry"]["coordinates"])
try:
    eastbound_crossing([25, 12], [35, 14])
except ValueError:
    print("ordinary segment rejected by this specialized example")
else:
    raise AssertionError("this example only handles one crossing direction")
print(json.dumps(feature, separators=(",", ":")))

Keep source fixes and derived cuts separately

The dispatch archive should retain the reported fixes in acquisition order. If it stores the computed meridian point alongside the original data, the record should also identify that point as derived. During a subsequent reprocessing pass, treating it as a third observation could change the count of measurements or introduce an invented timestamp. Preserve the voyage identifier when splitting the geometry, so a search on each side of the meridian can still return one trip. A transformation revision is useful when rebuilding old exports under a new geometry policy. The fixture property in the demonstration marks synthetic data. A real adapter would associate provenance with the source fixes and keep the rendered shape reproducible from those inputs.

Acceptance tests for a wider route service

Add westbound movement, an endpoint exactly on the meridian, a path along the meridian and a route that crosses more than once. Specify how each preserves point order and whether a degenerate segment should be omitted. A map also needs a sensible center when zooming to the object. The arithmetic mean of 179 and minus 179 is zero, so evaluate the camera in a continuous interval near the route before wrapping the result. Check that searches on both edges return the same feature identity and that a Greenwich query does not match this fixture. With those checks in place, a screenshot confirms the presentation after the data contract has already been tested.

322 reads ✎ Write a comment

Reader discussion

Discussion prompt

What is the most important unanswered question about this topic?

No comments yet. Be the first to contribute.

Write a comment

Comments are real visitor contributions. Repeated, link-heavy or abusive submissions may be limited.