Documentation
¶
Overview ¶
Package route finds sea routes over the Eurostat MARNET network.
The graph is built once with Load and is safe for concurrent use. Positions are [longitude, latitude] in decimal degrees, as in GeoJSON.
Index ¶
- Constants
- Variables
- func BlockCoefficient(t VesselType) (float64, bool)
- func CheckClearance(clearanceNM float64) error
- func CheckVessel(v Vessel) error
- func DataMargin(draughtM float64) float64
- func Distance(a, b Position) float64
- func Mercator(p Position) [2]float64
- func RhumbCourse(a, b Position) float64
- func Squat(cb, speedKn float64, confined bool) float64
- func WriteDepth(w io.Writer, tiles []DepthTile, mask []uint8, date string) error
- type Algorithm
- type Area
- type Datasets
- type Depth
- func (d *Depth) At(p Position) (m float64, known bool)
- func (d *Depth) DeepBand(a, b Position, halfWidthM, minM float64) bool
- func (d *Depth) DeepTiles(a, b Position, minM float64) bool
- func (d *Depth) SegmentMin(a, b Position) (m float64, known bool)
- func (d *Depth) TileMinDepth(p Position) float64
- type DepthLimit
- type DepthTile
- type Graph
- type Hazard
- type Land
- type Leg
- type Notice
- type Options
- type PassageLimit
- type Position
- type Route
- type Scheme
- type Segment
- type Stretch
- type TSS
- type TSSFeature
- type Vessel
- type VesselType
- type Warning
Constants ¶
const ( DefaultClearanceNM = 2.0 MinClearanceNM = 0.5 MaxClearanceNM = 10.0 )
Limits on the clearance option, shared by the REST and MCP front ends.
const ( // TSSAreaNM is the buffer around a scheme's features that makes its area: // inside it, shortcuts are forbidden and OSM TSS data is the authority. TSSAreaNM = 1.0 // TSSCoverageNM is the wider buffer inside which the OSM TSS data is trusted // to be complete. TSSCoverageNM = 20.0 )
const ( DefaultDraughtM = 10.0 DefaultSpeedKn = 14.0 DefaultVesselType VesselType = "bulk" )
Defaults for a vessel that does not name its draught, speed or type.
const MetresPerNM = 1852.0
MetresPerNM is the international nautical mile.
Variables ¶
var ClosedByDefault = []string{"northwest", "northeast"}
ClosedByDefault are passages a route avoids unless Options.Allow opens them: the Arctic routes, which need ice class or a summer window.
var ErrUnknownPassage = errors.New("unknown passage")
ErrUnknownPassage is returned when Avoid or Allow names a passage the network lacks.
var ExtraPassages = []Area{
{Pass: "oresund", MinLon: 12.45, MinLat: 55.45, MaxLon: 12.95, MaxLat: 56.08},
{Pass: "belle_isle", MinLon: -57.3, MinLat: 51.0, MaxLon: -55.6, MaxLat: 51.9},
}
ExtraPassages tags passages that MARNET leaves untagged. A segment that touches the box gets the tag, unless it already has one.
var PassageLimits = map[string]PassageLimit{ "suez": { MaxDraughtM: 20.1, Confined: true, Source: "Suez Canal Authority, 66 ft (20.1 m) maximum draft; beam-dependent in SCA tables", }, "panama": { MaxDraughtM: 15.24, Confined: true, Source: "Panama Canal Authority, Neopanamax locks 50 ft TFW (15.24 m); per plan, unverified: 2026 notices of 49.5 ft not confirmed", }, "kiel": { MaxDraughtM: 9.5, Confined: true, Source: "Kiel Canal (WSV) 9.5 m; holds only up to about 160 m length, smaller allowance for larger ships; per plan, unverified for the length rule", }, "corinth": { MaxDraughtM: 6.5, Confined: true, Source: "Corinth Canal S.A. 2026 commercial brochure, 6.50 m maximum permissible draft (some older sources give 7.3 m)", }, "malacca": { MaxDraughtM: 20.5, Confined: true, Source: "Malaccamax design draught 20.5 m (en.wikipedia.org/wiki/Malaccamax); IMO rules for the Straits of Malacca and Singapore require 3.5 m under-keel clearance for deep-draught vessels (15 m or more). No IMO or MPA document fixes 20.5 m as a limit: unverified; GEBCO cannot resolve the deep-water route", }, "dover": { MaxDraughtM: 0, Confined: true, Source: "per plan, unverified: no fixed draught limit; confined squat applied", }, }
PassageLimits maps passage tags (see Graph.Passages) to their draught rules.
Functions ¶
func BlockCoefficient ¶
func BlockCoefficient(t VesselType) (float64, bool)
BlockCoefficient returns the block coefficient of a vessel type, and false for an unknown type.
func CheckClearance ¶
CheckClearance validates a clearance in nautical miles, already defaulted.
func CheckVessel ¶
CheckVessel validates a vessel's draught, speed and type. It does not apply defaults; NewVessel does that and then calls it.
func DataMargin ¶
DataMargin is the under-keel allowance for depth data error: 2 m, or 10% of the draught when that is larger.
func Distance ¶
Distance is the rhumb-line (loxodrome) distance in metres, the length of a constant-bearing leg between a and b.
func Mercator ¶
Mercator projects p to Mercator (x, y) in radians. Straight lines in this plane are rhumb lines.
func RhumbCourse ¶
RhumbCourse is the constant bearing in degrees true (0 to 360) of the rhumb line from a to b. North is 0, east is 90.
func Squat ¶
Squat is the Barrass squat in metres at speedKn knots: cb × V² / 100 in open water, cb × V² / 50 when confined.
func WriteDepth ¶
WriteDepth writes tiles in the SRDEPTH2 format read by LoadDepth: gzip of the magic line, a JSON header line, per tile zigzag-varint CX and CY, a byte (1 = deep, 0 = cells) and, when not deep, 14400 cell bytes, then the deep-ocean mask (720*360 bytes, see NewDepthMask) when the header says "mask":true. mask may be nil to write none.
Types ¶
type Datasets ¶
type Datasets struct {
Network, Land, TSS, Depth string
}
Datasets names the files LoadAll reads. An empty Land or TSS path turns that feature off.
type Depth ¶
type Depth struct {
Version string // "<date>/gebco2026"
// contains filtered or unexported fields
}
Depth is a conservative water-depth grid over the tiles near the route network. Outside the stored tiles depth is unknown.
func LoadDepth ¶
LoadDepth reads a dataset written by WriteDepth (cmd/depth-import). The file is treated as untrusted: counts and coordinates are bounded and truncation is an error.
func NewDepthMask ¶
NewDepthMask is NewDepth plus the worldwide deep-ocean mask: one byte per 0.5 degree tile (720 columns from 180 W, 360 rows from 90 S), the minimum depth over the tile in the cell encoding. mask must have 720*360 bytes or be nil.
func (*Depth) At ¶
At returns the stored depth in metres at p (0 = land or drying, 255 = 255 m or deeper). known is false outside the stored tiles.
func (*Depth) DeepBand ¶
DeepBand reports whether the band halfWidthM either side of the rhumb leg a-b holds at least minM everywhere in the grid: the leg and lines parallel to it, under one cell apart, are sampled under one cell apart (centre line first, so an obstacle on the track fails fast). A sample outside the stored tiles passes only when its tile is at least deepTileM throughout (the mask). Land and drying cells read 0, so an island the land data lacks fails.
func (*Depth) DeepTiles ¶
DeepTiles reports whether every 0.5 degree tile the rhumb leg a-b passes through has a minimum depth of at least minM. The tiles are found exactly: the leg is cut where it crosses a tile edge (a straight line in Mercator coordinates) and one point inside every piece is tested, so a tile whose corner the leg only clips is never missed. The leg is split at the antimeridian.
func (*Depth) SegmentMin ¶
SegmentMin is kept as the reference oracle for tests (segmentDepth is what the router uses). It is the minimum stored depth along the rhumb leg a-b, sampled every 200 m with both ends included. known is false if any sample lies outside the stored tiles; the minimum over the known samples is still returned (0 when none is known, the conservative value).
func (*Depth) TileMinDepth ¶
TileMinDepth returns the minimum stored depth in metres over the 0.5 degree tile containing p (0 when the mask is absent, so callers treat unknown as shallow).
type DepthLimit ¶
type DepthLimit struct {
DraughtM float64 `json:"draught_m"`
SquatM float64 `json:"squat_m"`
MarginM float64 `json:"margin_m"`
LimitM float64 `json:"depth_limit_m"`
}
DepthLimit is the water depth a vessel needs, with its parts. LimitM is DraughtM + SquatM + MarginM.
type DepthTile ¶
DepthTile is one 0.5 degree tile of the depth grid. Cell values: 0 = land or drying, 1-254 = depth in whole metres rounded down, 255 = 255 m or deeper. M holds depthCellsPerTile^2 cells row-major from the south-west corner (M[j*120+i] is column i from the west edge, row j from the south edge); it is nil when Deep, meaning every cell is 255.
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph is the routing network in compressed adjacency form.
func Load ¶
Load reads a GeoJSON network of LineStrings. A "pass" property tags every segment of the line with that passage. It equals LoadAll(Datasets{Network: path}).
func LoadAll ¶
LoadAll reads the network and, when named, the land and TSS datasets, and builds the TSS-aware graph.
func New ¶
New builds the graph from segments. Zero-length segments are dropped. It equals NewWith(segs, nil, nil).
func NewWith ¶
NewWith builds the graph from segments with optional land and TSS data. With TSS, lanes become one-way edges joined to the network, and MARNET edges that cross a separation zone or line, or run against a lane, are blocked (see applyTSS). Land is used only to drop joins that touch land.
func (*Graph) Edges ¶
Edges returns the number of network segments. Each segment is stored once per direction, so this is half the directed edge count.
type Hazard ¶
type Hazard struct {
From int `json:"from"`
To int `json:"to"`
Start Position `json:"start"` // Path[From]
End Position `json:"end"` // Path[To]
// Severity is "aground" (within the land data tolerance of land),
// "shallow" (less water than the vessel needs, outside a port approach),
// "close" (clear of land, nearer than the clearance), "approach" (any of
// those inside a port approach) or "unchecked" (a segment that leaves the
// area the land data covers through water the depth grid does not vouch
// for as open ocean, so its clearance is unknown).
Severity string `json:"severity"`
// MinClearanceNM is the smallest clearance beyond the land tolerance,
// rounded to 0.1; 0 when aground.
MinClearanceNM float64 `json:"min_clearance_nm"`
Kind string `json:"kind"` // provenance: marnet, osm-tss, connector
Passage string `json:"passage,omitempty"`
Note string `json:"note,omitempty"`
}
Hazard is a run of Route.Path segments that touch land (aground) or pass closer than the requested clearance (close). From and To index Route.Path, as in Stretch. Every segment of the final path is checked, whatever its provenance, so a path edited later can be re-checked the same way.
type Land ¶
type Land struct {
Tolerance float64 // Douglas-Peucker tolerance of the dataset in metres
Version string // "<date>/<tolerance_m>m"
// CorridorNM is the radius around MARNET vertices that the dataset covers
// (header corridor_nm). Land farther from every vertex may be missing. 0
// means full coverage.
CorridorNM float64
// contains filtered or unexported fields
}
Land is a coastline edge set with a 0.25 degree grid index, used to measure how close a straight (rhumb) leg passes to land.
The OSM "split" land polygons contain artificial tile-split edges that lie inside land. They do no harm: distance is the minimum over all edges, and a leg between two sea points that enters land must cross a real coastline edge, so "returns 0 when they intersect" is sufficient.
Gaps are computed in Mercator and converted to metres as R * gap * cos(lat) with lat at the mid-height of the two closest points. The error is second order in the gap (about 1 m per degree of gap at mid latitudes, far below Tolerance for the 2 NM clearances used). Simplification can move the coast by up to Tolerance metres; callers add it to their clearance requirement.
func LoadLand ¶
LoadLand reads a dataset written by cmd/land-import (see its package comment for the format). The file is treated as untrusted: counts are bounded and truncation is an error.
func (*Land) PointDistance ¶
PointDistance is the distance in metres from p to the nearest land edge, capped at limitM.
func (*Land) SegmentClearance ¶
SegmentClearance is the smallest distance in metres from the rhumb leg a-b to any land edge, capped at limitM. It is 0 when the leg touches land. The leg is straight in Mercator coordinates at any length; a leg crossing the antimeridian is checked as two pieces.
type Leg ¶
type Leg struct {
From Position `json:"from"`
To Position `json:"to"`
// Path runs From -> To and includes both ends.
Path []Position `json:"path"`
// DistanceM is the full leg: From -> network, along the network, network -> To.
DistanceM float64 `json:"distance_m"`
// NetworkM is the part along the network. The rest is straight
// connectors at each end, which are not checked against land.
NetworkM float64 `json:"network_m"`
// Passages are the tagged canals and straits the leg uses, in order.
Passages []string `json:"passages"`
// contains filtered or unexported fields
}
Leg is the route between two consecutive requested points.
type Notice ¶
type Notice struct {
Kind string `json:"kind"` // "draught-reroute" | "draught-no-route"
Text string `json:"text"`
ExtraNM float64 `json:"extra_nm"`
Avoided []Position `json:"avoided"`
Passages []string `json:"passages"` // passage tags on the avoided stretch
}
Notice tells the caller that the vessel's draught changed the route.
type Options ¶
type Options struct {
// Avoid lists passage tags the route must not use, e.g. "kiel", "suez".
// See Graph.Passages for the tags in the loaded network.
Avoid []string
// Allow opens passages that are closed by default (ClosedByDefault).
Allow []string
Algorithm Algorithm
// NoTSS routes on the plain MARNET network: lane, join and wrong-way
// edges are skipped and TSS blocks are ignored. Internal; not exposed in
// the UI or APIs.
NoTSS bool
// ClearanceNM is the land clearance hazards are measured against; 0 means 2.
ClearanceNM float64
// Vessel is the ship the route is planned for; zero fields mean the defaults.
Vessel Vessel
}
Options adjust a route request.
type PassageLimit ¶
type PassageLimit struct {
// MaxDraughtM is the deepest draught the passage admits. 0 means no fixed limit.
MaxDraughtM float64
// Confined applies the confined-water squat (Squat with confined true).
Confined bool
// Source cites where MaxDraughtM and Confined come from.
Source string
}
PassageLimit is the draught rule for a tagged passage.
type Position ¶
type Position [2]float64
Position is [longitude, latitude] in decimal degrees.
func RhumbPoint ¶
RhumbPoint is the point a fraction f of the way along the rhumb line from a to b (f=0 gives a, f=1 gives b). The line is straight in the Mercator plane, and the route crosses the antimeridian the short way. Longitudes come back in [-180, 180].
type Route ¶
type Route struct {
Legs []Leg `json:"legs"`
Path []Position `json:"path"`
DistanceM float64 `json:"distance_m"`
Passages []string `json:"passages"`
// Warnings has one entry per scheme whose rules were lifted on any leg.
Warnings []Warning `json:"warnings"`
// Stretches label runs of Path by provenance; From and To index Path.
Stretches []Stretch `json:"stretches"`
// Hazards are runs of Path that touch land or pass closer than the
// clearance. Empty without land data.
Hazards []Hazard `json:"hazards"`
// Depth is the depth the vessel needs in open water; ConfinedDepthM the
// same in confined passages.
Depth DepthLimit `json:"depth"`
ConfinedDepthM float64 `json:"confined_depth_limit_m"`
// Notices report where the draught changed the route.
Notices []Notice `json:"notices"`
}
Route is a sequence of legs through the requested points.
func (Route) DistanceNM ¶
DistanceNM returns the total distance in nautical miles.
type Scheme ¶
type Scheme struct {
ID, Name string
Area []Position
Coverage []Position
Zones [][]Position // closed polygons that must not be crossed
Lines [][]Position // separation lines that must not be crossed
Lanes [][]Position // direction of the polyline is the direction of traffic
// contains filtered or unexported fields
}
Scheme is one traffic separation scheme (a group of OSM ways within 3 NM of each other).
Area and Coverage are closed convex rings (counter-clockwise, first vertex repeated) with longitudes wrapped to [-180, 180]. A scheme whose features span the antimeridian is hulled internally with longitudes shifted into a continuous 0..360 range (negative longitudes get +360), so its exported rings jump across +-180; all queries on the TSS handle this.
type Stretch ¶
type Stretch struct {
From int `json:"from"`
To int `json:"to"`
Flag string `json:"flag"`
Severity string `json:"severity"`
Scheme string `json:"scheme,omitempty"`
}
Stretch labels path[From..To] of Route.Path with where it came from.
type TSS ¶
TSS is the set of schemes in the dataset. Version is the OSM base timestamp the data was extracted at.
func LoadTSS ¶
LoadTSS reads the gzip GeoJSON written by cmd/tss-import. The file is treated as untrusted: feature and coordinate counts are bounded and NaN or out-of-range coordinates are rejected.
func NewTSS ¶
func NewTSS(features []TSSFeature, version string) *TSS
NewTSS groups features by scheme ID and builds the scheme geometry. Feature roles: closed zone/roundabout ways are Zones; line ways are Lines; open lane ways are Lanes; everything else (boundary, crossing, closed lanes, open zones) only widens the scheme's area. Unknown types are ignored.
func (*TSS) InArea ¶
InArea reports whether p is within 1 NM of any scheme feature's hull, and which scheme (index into Schemes) it is in.
func (*TSS) InCoverage ¶
InCoverage reports whether p lies within the 20 NM coverage hull of any scheme, where OSM TSS data is trusted.
func (*TSS) SegmentTouchesArea ¶
SegmentTouchesArea reports whether the rhumb leg a-b touches any scheme area.
type TSSFeature ¶
TSSFeature is one imported OSM way. Type is the seamark type without the "separation_" prefix: lane, zone, line, boundary, roundabout or crossing. A closed ring repeats its first coordinate at the end.
type Vessel ¶
type Vessel struct {
DraughtM float64
SpeedKn float64
Type VesselType
}
Vessel is the ship a route is planned for.
func NewVessel ¶
NewVessel builds a vessel from optional request fields and validates it. A nil pointer or empty type means the default; an explicit value, including 0, is kept as given.
func (Vessel) DepthLimit ¶
func (v Vessel) DepthLimit(confined bool) DepthLimit
DepthLimit applies WithDefaults, then works out the depth the vessel needs in open water or, when confined, in a canal or strait. An unknown type uses the largest block coefficient (0.80), which is the conservative choice.
func (Vessel) WithDefaults ¶
WithDefaults fills zero fields with the defaults.
type VesselType ¶
type VesselType string
VesselType is the hull class, which sets the block coefficient.
const ( Tanker VesselType = "tanker" Bulk VesselType = "bulk" General VesselType = "general" Container VesselType = "container" )