In this section
- Geo Core transform · ventus-grid-engine / engine/geo-core.js lines 1–95
- Geo GeoJSON geodesy · ventus-grid-engine / engine/geo-geojson.js lines 1–27
- Geo Shapes geodesy · ventus-grid-engine / engine/geo-shapes.js lines 1–46
- Route Obstacles transform · ventus-grid-engine / engine/route-obstacles.js lines 1–262
- V9 Geodesy geodesy · ventus-grid-engine / engine/v9-geodesy.js lines 1–141
Geo Core
A JavaScript module in Ventus Grid Engine that works with haversine UK (`haversineUK`) and calculates great-circle distances and angles.
transformventus-grid-engine / engine/geo-core.js · lines 1–95 of 95 · Entry point · pattern haversine (shared by 24 files)
- What it does
- It calculates its inputs. Defines haversine, haversineUK.
- Why it exists in the grid workflow
- Domain stage site_feasibility (topic 'maps-gis'): substation-to-site feasibility (terrain, LiDAR and connection evidence before design), a journey named in Ventus Ltd's brief.
- Inputs & outputs
- Coordinate systems named: WGS84 / EPSG:4326.
- Downstream impact
- Used directly by 6 files: Geo Area (ventus-grid-engine); Geo Shapes (ventus-grid-engine); Geodesy Proof (ventus-grid-engine); Build Graph (ventus-grid-engine, https://ventusltd.github.io/ventus-grid-engine/genome/); and 2 more. Reached from 7 other entry points, including Grid Engine — Site Geometry Page (globalgrid2050, https://globalgrid2050.com/grid_engine/202609060238-site-geometry/); Grid Engine — Solar Farm Page (globalgrid2050, https://globalgrid2050.com/grid_engine/202609060318-solar-farm/); Homepage V090 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v090.html).
- What it achieves
- It is built from the haversine step (`haversine`) and the haversine UK helper (`haversineUK`). The one distance primitive, and the earth model it stands on.
- Why it matters
- Loaded by the Genome page at https://ventusltd.github.io/ventus-grid-engine/genome/. Also imported by 5 files, including Geo Area, Geo Shapes and Geodesy Proof.
- Application
- ventus-grid-engine · engine · JavaScript module
- Uses
- none found
- Used by
- imported by Geo Area (import), imported by Geo Shapes (import), imported by Geodesy Proof (import), named by URL in Build Graph (estate URL), imported by V9 Engine Proof (import), named by URL in Ventus Grid Engine — Genome Page (estate URL)
- Produces
- EARTH_RADIUS_KM, R_ATLAS, R_UK, R_MEAN, MAX_RADIUS_KM, DEG_TO_RAD, haversine, haversineUK
- Defines here
- haversine, haversineUK
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- ventus-grid-engine@ad566356a44e006682e956483d569f31ddbb9630 engine/geo-core.js:1-95 · blob 9d47bb03d35676f217c2004cb64db667ae24be78 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: site_feasibility · users: IPP_developer, landowner_planner · canonical: production_core
/* geo-core — the one distance primitive, and the earth model it stands on.
*
* Extracted verbatim from globalgrid2050/repd_grid_atlasv8/ventus-corev8engine.js
* at globalgrid2050 HEAD 7d00781b6993b9038a1a8bedf2c88a4eb0109ad4:
* lines 32-33 EARTH_RADIUS_KM, MAX_RADIUS_KM
* line 36 DEG_TO_RAD
* lines 45-50 haversine
*
* The only edit is `export` plus an optional radius argument that defaults to
* the V8 value, so existing behaviour is bit-identical. No formula was
* rewritten. This cluster had no closure dependency in the original, which is
* why it extracts cleanly.
*
* ── On the radius ────────────────────────────────────────────────────────────
* The estate has already decided this, in grid-distance-maths/docs/EARTH-MODEL.md,
* and the decision is not the obvious one. It is restated here because the
* obvious assumption — "6378.137 is the equatorial radius, so it must be the
* wrong choice for a mean-radius formula" — is wrong, and acting on it would
* make every distance in the estate worse rather than better.
*
* At GB latitudes the best single sphere is the Gaussian mean radius of
* curvature, about 6384.7 km at 54N. Measured against that:
*
* 6371.0088 IUGG mean -2,194 ppm mean error, 206 m worst
* 6378.137 WGS84 equatorial -1,078 ppm mean error, 141 m worst
* 6384.7272 UK Gaussian -46 ppm mean error, 102 m worst
*
* BOTH deployed constants are too small here. 6378.137 is not the sloppy
* choice — it is the more accurate of the two actually in use, by a factor of
* two, and switching to the IUGG mean radius would double the error.
*
* So the estate's decision, followed exactly here:
* - R_ATLAS (6378.137) stays the default, because every deployed tool uses
* it and every published Ventus figure depends on it. Changing it silently
* would move numbers already quoted from the Atlas, the sandbox and
* Pipeline News.
* - R_UK (6384.7272) is for new work where accuracy matters more than
* agreement with existing output. It cuts mean error by a factor of 23.
* - R_MEAN (6371.0088) should NOT be used in new code. It is exported only so
* existing Turf-based results can be reproduced and compared.
*
* And the honest proportion: the gap between R_ATLAS and the truth is about one
* part in a thousand, which is well inside the uncertainty of a REPD site
* centroid — that can sit hundreds of metres from the actual point of
* connection. The radius is not the dominant error. Measuring to a sampled
* vertex instead of to the line is, and it is five times larger. Nothing in
* this module fixes that one.
*/
/** WGS84 semi-major (equatorial) axis, km. The estate default: R_ATLAS. */
export const EARTH_RADIUS_KM = 6378.137;
/** Alias under the estate's own name, for code that reads better with it. */
export const R_ATLAS = EARTH_RADIUS_KM;
/** Gaussian mean radius of curvature at 54N, km. For new accuracy-led work. */
export const R_UK = 6384.7272;
/** IUGG mean radius, km. Reproduction of Turf-based results only. Not for new code. */
export const R_MEAN = 6371.0088;
/** Half the circumference on the default model — the antipodal distance. */
export const MAX_RADIUS_KM = Math.PI * EARTH_RADIUS_KM; // 20037.508 km
export const DEG_TO_RAD = Math.PI / 180;
/**
* Great-circle distance between two points, in km.
*
* Verbatim from ventus-corev8engine.js:45-50, including its argument order,
* which is (lon, lat) pairs — GeoJSON order, not the (lat, lon) order most
* haversine implementations take. Getting this backwards is silent and wrong,
* so the order is asserted by proofs/geodesy.proof.mjs rather than trusted.
*
* @param {number} lon1 degrees east
* @param {number} lat1 degrees north
* @param {number} lon2 degrees east
* @param {number} lat2 degrees north
* @param {number} [radiusKm] earth radius; defaults to the estate's R_ATLAS
* @returns {number} km
*/
export function haversine(lon1, lat1, lon2, lat2, radiusKm = EARTH_RADIUS_KM) {
const R = radiusKm, r = Math.PI / 180;
const dLat = (lat2 - lat1) * r, dLon = (lon2 - lon1) * r;
const a = Math.sin(dLat / 2) ** 2 + Math.cos(lat1 * r) * Math.cos(lat2 * r) * Math.sin(dLon / 2) ** 2;
return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
}
/**
* The same distance on the UK Gaussian radius — the accurate option for new
* work that does not have to agree with already-published Ventus figures.
*/
export function haversineUK(lon1, lat1, lon2, lat2) {
return haversine(lon1, lat1, lon2, lat2, R_UK);
}Geo GeoJSON
A JavaScript module in Ventus Grid Engine that works with circle feature collection (`circleFeatureCollection`). It is built from the circle feature collection helper (`circleFeatureCollection`).
geodesyventus-grid-engine / engine/geo-geojson.js · lines 1–27 of 27 · Entry point
- What it does
- It calculates its inputs. Defines circleFeatureCollection.
- Why it exists in the grid workflow
- Domain stage site_feasibility (topic 'maps-gis'): substation-to-site feasibility (terrain, LiDAR and connection evidence before design), a journey named in Ventus Ltd's brief.
- Downstream impact
- Used directly by 3 files: Geodesy Proof (ventus-grid-engine); Build Graph (ventus-grid-engine, https://ventusltd.github.io/ventus-grid-engine/genome/); Ventus Grid Engine — Genome Page (ventus-grid-engine, https://ventusltd.github.io/ventus-grid-engine/genome/). Reached from 1 other entry point, including Genome Workflow (ventus-grid-engine).
- What it achieves
- GeoJSON shaping, kept out of the maths modules.
- Why it matters
- Loaded by the Genome page at https://ventusltd.github.io/ventus-grid-engine/genome/. Also imported by Geodesy Proof and Build Graph.
- Application
- ventus-grid-engine · engine · JavaScript module
- VEDIC
- DRAW GEODESIC CIRCLE (GG2050-VEDIC-000075): Ventus Grid Engine · Geospatial and terrain intelligence. lon, lat, radiusKm → GeoJSON FeatureCollection containing one polygon.
- Uses
- Geo Shapes (import)
- Used by
- imported by Geodesy Proof (import), named by URL in Build Graph (estate URL), named by URL in Ventus Grid Engine — Genome Page (estate URL)
- Produces
- circleFeatureCollection
- Defines here
- circleFeatureCollection
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- ventus-grid-engine@ad566356a44e006682e956483d569f31ddbb9630 engine/geo-geojson.js:1-27 · blob 38e27d5743d16a4c19b2e849260aa8845423c45b · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: site_feasibility · users: IPP_developer, landowner_planner · canonical: production_core
/* geo-geojson — GeoJSON shaping, kept out of the maths modules.
*
* createGeoJSONCircle (ventus-corev8engine.js:727-740) did two jobs: generate
* the ring, and wrap it as a FeatureCollection. The ring generation moved to
* geo-shapes.js because zone-draw wants points and not GeoJSON. The wrapping
* is here, so a caller that only wants coordinates does not depend on a
* GeoJSON shape it never reads.
*/
import { destinationCirclePoints, circleVertexCount } from './geo-shapes.js';
/**
* A closed circle as a GeoJSON FeatureCollection containing one Polygon.
* The ring is explicitly closed (first point repeated last), as GeoJSON requires.
*/
export function circleFeatureCollection(lon, lat, radiusKm) {
const ring = destinationCirclePoints(lon, lat, radiusKm, circleVertexCount(radiusKm));
ring.push(ring[0]);
return {
type: 'FeatureCollection',
features: [{
type: 'Feature',
properties: { radius_km: radiusKm, centre: [lon, lat] },
geometry: { type: 'Polygon', coordinates: [ring] }
}]
};
}Geo Shapes
A JavaScript module in Ventus Grid Engine that works with destination circle points (`destinationCirclePoints`) and circle vertex count (`circleVertexCount`) and calculates great-circle distances and angles.
geodesyventus-grid-engine / engine/geo-shapes.js · lines 1–46 of 46 · Entry point · pattern destinationCirclePoints (shared by 2 files)
- What it does
- It calculates its inputs. Defines destinationCirclePoints, circleVertexCount.
- Why it exists in the grid workflow
- Domain stage site_feasibility (topic 'maps-gis'): substation-to-site feasibility (terrain, LiDAR and connection evidence before design), a journey named in Ventus Ltd's brief.
- Downstream impact
- Used directly by 4 files: Geo GeoJSON (ventus-grid-engine); Geodesy Proof (ventus-grid-engine); Build Graph (ventus-grid-engine, https://ventusltd.github.io/ventus-grid-engine/genome/); Ventus Grid Engine — Genome Page (ventus-grid-engine, https://ventusltd.github.io/ventus-grid-engine/genome/). Reached from 1 other entry point, including Genome Workflow (ventus-grid-engine).
- What it achieves
- It is built from the destination circle points helper (`destinationCirclePoints`) and the circle vertex count helper (`circleVertexCount`). Walking a circle of points around a centre on the sphere.
- Why it matters
- Loaded by the Genome page at https://ventusltd.github.io/ventus-grid-engine/genome/. Also imported by Geo GeoJSON, Geodesy Proof and Build Graph.
- Application
- ventus-grid-engine · engine · JavaScript module
- VEDIC
- TRACE GEODESIC CIRCLE (GG2050-VEDIC-000103): Ventus Grid Engine / Geometry · Mathematics / Spherical geometry. lon, lat, radiusKm, n, earthRadiusKm → Open ring of n [lon, lat] degree pairs evenly spaced in bearing around the centre.
- Uses
- Geo Core (import)
- Used by
- imported by Geo GeoJSON (import), imported by Geodesy Proof (import), named by URL in Build Graph (estate URL), named by URL in Ventus Grid Engine — Genome Page (estate URL)
- Produces
- destinationCirclePoints, circleVertexCount, ZONE_DRAW_VERTICES
- Defines here
- destinationCirclePoints, circleVertexCount
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- ventus-grid-engine@ad566356a44e006682e956483d569f31ddbb9630 engine/geo-shapes.js:1-46 · blob 914d215adca63ad1258858e49c17eac3dc43d96b · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: site_feasibility · users: IPP_developer, landowner_planner · canonical: production_core
/* geo-shapes — walking a circle of points around a centre on the sphere.
*
* The fourth duplication, and the cleanest to collapse. From
* globalgrid2050/repd_grid_atlasv8/ventus-corev8engine.js at HEAD
* 7d00781b6993b9038a1a8bedf2c88a4eb0109ad4:
*
* lines 122-132 _zoneDrawCirclePoints(lon, lat, radiusKm, n) n fixed at 24
* lines 727-740 createGeoJSONCircle(lon, lat, radiusKm) n chosen by radius
*
* Both contain the same destination-point-on-a-sphere formula. Checked, not
* assumed: called with identical arguments they agree to 0 absolute difference
* over 64 points. The difference between them was never the maths — it was how
* many points each wanted and whether the result got wrapped as GeoJSON.
*
* So the formula lives once, here, and the point count becomes an argument.
*/
import { EARTH_RADIUS_KM } from './geo-core.js';
/**
* n points evenly spaced around a geodesic circle, as [lon, lat] degree pairs.
* The ring is NOT closed — the first point is not repeated at the end.
*/
export function destinationCirclePoints(lon, lat, radiusKm, n, earthRadiusKm = EARTH_RADIUS_KM) {
const R = earthRadiusKm, DEG = Math.PI / 180;
const ad = radiusKm / R;
const lat1 = lat * DEG;
return Array.from({ length: n }, (_, i) => {
const b = (i / n) * 2 * Math.PI;
const lat2 = Math.asin(Math.sin(lat1) * Math.cos(ad) + Math.cos(lat1) * Math.sin(ad) * Math.cos(b));
const lon2 = lon * DEG + Math.atan2(Math.sin(b) * Math.sin(ad) * Math.cos(lat1), Math.cos(ad) - Math.sin(lat1) * Math.sin(lat2));
return [lon2 / DEG, lat2 / DEG];
});
}
/**
* The vertex count V8 chose for a rendered radius circle, preserved exactly so
* a rendered ring stays comparable with V8. From createGeoJSONCircle's own
* branch at ventus-corev8engine.js:727-740.
*/
export function circleVertexCount(radiusKm) {
return radiusKm > 5000 ? 128 : radiusKm > 500 ? 96 : 64;
}
/* ZONE_DRAW_VERTICES, as V8 fixed it. */
export const ZONE_DRAW_VERTICES = 24;Route Obstacles
A JavaScript module in Ventus Grid Engine that works with motorways, cables and A roads, using haversine.
transformventus-grid-engine / engine/route-obstacles.js · lines 1–262 of 262 · pattern crossingSchedule (shared by 2 files)
- What it does
- It calculates motorways, cables and A roads. Defines positive, crossingLengthM, crossingSchedule, routeEstimate.
- Why it exists in the grid workflow
- Domain stage field_execution (path word 'route'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work. Domain terms in the code: motorways, cables, A roads.
- Downstream impact
- Used directly by 3 files: Grid Engine — Route Obstacles Page (globalgrid2050, https://globalgrid2050.com/grid_engine/202609060213-route-obstacles/); Route Obstacles Proof (ventus-grid-engine); Build Graph (ventus-grid-engine, https://ventusltd.github.io/ventus-grid-engine/genome/). Reached from 4 other entry points, including Homepage V090 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v090.html); Homepage V091 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v091.html); Homepage V093 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v093.html).
- What it achieves
- It routes estimate (`routeEstimate`) and is built from the positive step (`positive`) and the crossing length m helper (`crossingLengthM`). What actually gets in the way of a cable route, and what each obstacle costs in length and in method.
- Why it matters
- Loaded by the page of the same name in GlobalGrid2050 at https://globalgrid2050.com/grid_engine/202609060213-route-obstacles/. Also imported by Route Obstacles Proof and Build Graph.
- Application
- ventus-grid-engine · engine · JavaScript module
- Uses
- none found
- Used by
- linked from Grid Engine — Route Obstacles Page (link), imported by Route Obstacles Proof (import), named by URL in Build Graph (estate URL)
- Produces
- schema, OBSTACLES, crossingLengthM, crossingSchedule, routeEstimate, NOT_COMPUTED
- Defines here
- positive, crossingLengthM, crossingSchedule, routeEstimate
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- ventus-grid-engine@ad566356a44e006682e956483d569f31ddbb9630 engine/route-obstacles.js:1-262 · blob 36ab4d0b96d35c92691a048705dde56a27679f38 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: production_core
/**
* Module: route-obstacles
*
* APPLIED ENGINEERING. What actually gets in the way of a cable route, and
* what each obstacle costs in length and in method.
*
* WHY THIS MODULE EXISTS — A REAL DEFECT, NAMED.
* `corridor-estimate.js` turns a straight-line kilometre into a highway-
* corridor screening estimate by multiplying by 1.245. It is well calibrated
* on 95 GB cable circuits and it stays exactly as it is: the straight line
* remains the first pass and this module does not touch it.
*
* But `forCable()` takes ONE SCALAR KILOMETRE. It has no coordinates. It
* therefore cannot know what the line crossed, and a land/sea test inside it
* is structurally impossible — every one of its checks operates on the same
* scalar, so none of them could ever go red for a route across open water.
* The measured consequence: South Antrim to the Western HVDC converter is
* 142.21 km of mostly Irish Sea, and was printed as a 177.05 km "highway
* corridor" — a road route that does not exist, stated with the confidence of
* a calibrated number.
*
* This module is where the coordinates and the crossings live. It does not
* replace the corridor factor; it decides whether that factor is applicable at
* all, and adds what the crossings cost.
*
* THE CROSSINGS THAT ACTUALLY DECIDE A ROUTE.
* A motorway, a railway, a navigable river, a canal, a trunk road: each is an
* asset with an owner, a crossing agreement and a method constraint. You do
* not open-cut a live motorway or a running railway — those are trenchless
* crossings, horizontal directional drilling or auger bore, with launch and
* reception pits set back from the asset boundary. So the drill is always
* substantially longer than the obstacle is wide, and the setback is the
* dominant term for a narrow obstacle: a 30 m motorway is not a 30 m drill.
*
* WHY WIDTHS AND SETBACKS ARE INPUTS AND NOT CONSTANTS.
* Every network owner publishes its own minimum cover, setback and separation
* requirements, and they differ — between Network Rail and a highways
* authority, and between one utility's plant and another's. Inventing a
* default here would produce a plausible number that no owner would accept.
* The module therefore takes the width and the setback from the caller, and
* refuses a crossing that declares neither.
*
* WHAT IT REFUSES.
* It will not route around anything: there is no pathfinder here, because a
* real one needs the obstacle geometry, land ownership, ground conditions and
* consenting constraints, none of which are in this module. It will not price
* a crossing. It will not tell you a crossing will be permitted. And it
* refuses outright to apply a highway-corridor factor to a route that crosses
* open water, because there is no highway.
*
* Depends on: nothing. Pure arithmetic and classification over caller-declared
* crossings. The straight-line distance is supplied by the caller, from
* v9-geodesy.js distanceKm or geo-core.js haversine, exactly as before.
*
* Schema: ventus-grid-engine.route-obstacles.v1
*/
export const schema = 'ventus-grid-engine.route-obstacles.v1';
/* The obstacle classes a GB cable route actually meets, and whether the
crossing can be open-cut. `trenchless: true` means the asset cannot be
opened: the crossing is drilled or bored beneath it. `blocksCorridor: true`
means a highway-corridor factor is not applicable to a route crossing it at
all — there is no road that goes there. */
export const OBSTACLES = Object.freeze({
motorway: { label: 'Motorway', trenchless: true, blocksCorridor: false,
why: 'A live motorway cannot be open-cut. Crossing is trenchless, under a highways authority agreement, with pits set back beyond the boundary fence.' },
trunk_road: { label: 'Trunk road', trenchless: true, blocksCorridor: false,
why: 'Strategic road network. Trenchless in practice; a lane closure for open-cut is rarely permitted and never assumed at screening.' },
minor_road: { label: 'Minor road', trenchless: false, blocksCorridor: false,
why: 'Open-cut with traffic management is normal, subject to the street authority\'s permit.' },
railway: { label: 'Railway', trenchless: true, blocksCorridor: false,
why: 'A running railway cannot be open-cut. Network Rail asset protection sets the method, the cover and the setback, and its own approval timescale usually governs the programme.' },
navigable_river: { label: 'Navigable river', trenchless: true, blocksCorridor: false,
why: 'Trenchless beneath the bed. The navigation authority and the environmental regulator both have a say, and the drill must clear the deepest scour, not the current bed level.' },
canal: { label: 'Canal', trenchless: true, blocksCorridor: false,
why: 'Trenchless beneath the invert, under the navigation authority\'s agreement.' },
watercourse: { label: 'Minor watercourse', trenchless: false, blocksCorridor: false,
why: 'Open-cut is often possible in a dry season with consent, but the regulator may still require trenchless.' },
open_water: { label: 'Open water / sea', trenchless: true, blocksCorridor: true,
why: 'This is a marine cable, not a buried land route. A highway-corridor factor calibrated on road-following circuits does not describe it, and no land estimate is offered.' },
protected_habitat: { label: 'Protected habitat', trenchless: true, blocksCorridor: false,
why: 'Trenchless to avoid surface disturbance where consent requires it. Whether it is permitted at all is a consenting question, not an engineering one.' }
});
function positive(name, v) {
if (typeof v !== 'number' || !Number.isFinite(v)) {
throw new TypeError(`${name} must be a finite number, received ${v === null ? 'null' : typeof v}`);
}
if (v <= 0) throw new RangeError(`${name} must be greater than zero, received ${v}`);
return v;
}
/**
* Length of one trenchless crossing.
*
* L = width + 2 x setback (the straight-line span between pits)
*
* The setback dominates for a narrow obstacle, which is exactly why a drill is
* never the width of the thing it passes under. A real drill is longer again
* because it dips: the entry and exit angles and the required depth add a
* curve the caller may supply as `depthM`.
*/
export function crossingLengthM({ widthM, setbackM, depthM = 0 }) {
positive('widthM', widthM);
positive('setbackM', setbackM);
if (typeof depthM !== 'number' || !Number.isFinite(depthM) || depthM < 0) {
throw new TypeError(`depthM must be a finite number of zero or more, received ${depthM}`);
}
const span = widthM + 2 * setbackM;
/* Pythagorean allowance for the dip: the bore runs from surface down to
depth and back. Approximate, stated as approximate, and zero when no
depth is declared. */
const withDip = depthM > 0 ? Math.hypot(span / 2, depthM) * 2 : span;
return {
schema,
quantity: 'crossing_length_m',
value: withDip,
unit: 'm',
spanM: span,
from: { widthM, setbackM, depthM },
basis:
`${widthM} m of obstacle plus ${setbackM} m of setback on each side gives a ${span} m span ` +
`between pits` +
(depthM > 0
? `, and running to ${depthM} m depth and back adds a dip, giving ${withDip.toFixed(1)} m of bore. `
: `. `) +
`The setback dominates for a narrow obstacle: a drill is never the width of the thing it ` +
`passes under. Widths, setbacks and cover are the asset owner's requirements and differ ` +
`between owners, which is why they are inputs here and not constants.`
};
}
/**
* Classify and total a set of declared crossings.
*
* Returns the trenchless schedule, the open-cut schedule, the added length,
* and — decisively — whether any crossing invalidates a highway-corridor
* estimate for this route.
*/
export function crossingSchedule({ crossings }) {
if (!Array.isArray(crossings)) {
throw new TypeError('crossings must be an array, empty if the route crosses nothing');
}
const items = crossings.map((c, i) => {
const spec = OBSTACLES[c.type];
if (!spec) {
throw new RangeError(
`crossings[${i}].type "${c.type}" is not a known obstacle. Known: ${Object.keys(OBSTACLES).join(', ')}`);
}
const count = c.count === undefined ? 1 : c.count;
if (!Number.isInteger(count) || count <= 0) {
throw new RangeError(`crossings[${i}].count must be a whole number greater than zero, received ${c.count}`);
}
let lengthM = 0, lengthBasis = 'no length declared';
if (c.widthM !== undefined || c.setbackM !== undefined) {
const l = crossingLengthM({ widthM: c.widthM, setbackM: c.setbackM, depthM: c.depthM });
lengthM = l.value * count;
lengthBasis = l.basis;
}
return {
index: i, type: c.type, label: spec.label, count,
trenchless: spec.trenchless, blocksCorridor: spec.blocksCorridor,
method: spec.trenchless ? 'trenchless' : 'open-cut',
why: spec.why, lengthM, lengthBasis,
lengthDeclared: lengthM > 0
};
});
const blocking = items.filter(i => i.blocksCorridor);
const trenchless = items.filter(i => i.trenchless);
const undeclared = items.filter(i => !i.lengthDeclared);
return {
schema,
quantity: 'crossing_schedule',
items,
crossingCount: items.reduce((a, b) => a + b.count, 0),
trenchlessCount: trenchless.reduce((a, b) => a + b.count, 0),
openCutCount: items.filter(i => !i.trenchless).reduce((a, b) => a + b.count, 0),
addedLengthM: items.reduce((a, b) => a + b.lengthM, 0),
corridorApplicable: blocking.length === 0,
blockedBy: blocking.map(b => b.label),
undeclaredLengths: undeclared.map(u => u.label),
basis: blocking.length
? `This route crosses ${blocking.map(b => b.label).join(' and ')}. A highway-corridor factor ` +
`is calibrated on circuits that follow the road network, and there is no road here, so no ` +
`land corridor estimate is offered for this route.`
: `${items.reduce((a, b) => a + b.count, 0)} declared crossing(s): ` +
`${trenchless.reduce((a, b) => a + b.count, 0)} trenchless, ` +
`${items.filter(i => !i.trenchless).reduce((a, b) => a + b.count, 0)} open-cut.` +
(undeclared.length
? ` ${undeclared.length} crossing(s) have no width or setback declared and contribute ` +
`no length: ${undeclared.map(u => u.label).join(', ')}. They are counted, not costed.`
: ``)
};
}
/**
* A route estimate that knows what it crossed.
*
* Straight line in, corridor factor applied ONLY where it is applicable, plus
* the declared crossing allowances. Returns null where there is nothing honest
* to say — the same discipline corridor-estimate already uses.
*/
export function routeEstimate({ straightLineKm, crossings = [], corridorFactor }) {
positive('straightLineKm', straightLineKm);
positive('corridorFactor', corridorFactor);
if (corridorFactor < 1) {
throw new RangeError(
`corridorFactor must be at least 1, received ${corridorFactor}; a route cannot be shorter than the straight line between its ends.`);
}
const sched = crossingSchedule({ crossings });
if (!sched.corridorApplicable) {
return {
schema,
quantity: 'route_estimate',
value: null,
unit: 'km',
straightLineKm,
schedule: sched,
corridorApplicable: false,
basis:
`No estimate. ${sched.basis} The straight-line distance of ${straightLineKm} km stands ` +
`and is unchanged — it is a real measurement — but multiplying it by a road factor would ` +
`describe a route that does not exist. This is the check that a scalar-only corridor ` +
`function could not make, because it never saw the coordinates.`
};
}
const corridorKm = straightLineKm * corridorFactor;
const crossingKm = sched.addedLengthM / 1000;
return {
schema,
quantity: 'route_estimate',
value: corridorKm + crossingKm,
unit: 'km',
straightLineKm,
corridorKm,
crossingAllowanceKm: crossingKm,
corridorApplicable: true,
schedule: sched,
basis:
`${straightLineKm} km straight line, x${corridorFactor} for a highway corridor gives ` +
`${corridorKm.toFixed(2)} km, plus ${crossingKm.toFixed(3)} km of declared crossing ` +
`allowance across ${sched.crossingCount} crossing(s), of which ${sched.trenchlessCount} ` +
`cannot be open-cut. Indicative screening only: not a route, not a constructability ` +
`assessment, and not a consenting design.`
};
}
export const NOT_COMPUTED = Object.freeze({
theRouteItself:
'There is no pathfinder here. A real route needs obstacle geometry, land ownership, ground conditions, existing plant and consenting constraints — none of which are in this module. Crossings are declared by the user, not discovered.',
crossingCost:
'What a crossing costs depends on ground conditions, the owner\'s requirements, programme and risk allocation. A length is not a price.',
crossingConsent:
'Whether a crossing is permitted is the asset owner\'s and the regulator\'s answer. Network Rail asset protection alone often governs the programme, regardless of engineering feasibility.',
groundConditions:
'Whether a drill is achievable depends on the ground. Rock, running sand, contamination and existing services decide the method, and none of them are visible from a map.'
});V9 Geodesy
A JavaScript module in Ventus Grid Engine that works with distance km (`distanceKm`) and representative point (`representativePoint`) and calculates great-circle distances and angles (units: kV), using haversine.
geodesyventus-grid-engine / engine/v9-geodesy.js · lines 1–141 of 141 · Entry point · pattern representativePoint (shared by 22 files)
- What it does
- Defines distanceKm, representativePoint, voltagesKv, destinationPoint, initialBearingDeg. Side effects: changes the web page (DOM).
- Why it exists in the grid workflow
- Domain stage upstream_foresight (voltage levels 750kV (all 132kV or above)): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight. Domain terms in the code: substations, 750kV. README: "`v9-geodesy.distanceKm` and the V8 `haversine` are bit-identical on every reference leg, and the proof asserts that exactly rather than to a tolerance."
- Inputs & outputs
- Voltage levels named: 750kV.
- Downstream impact
- Used directly by 7 files: Grid Engine — Solar Farm Page (globalgrid2050, https://globalgrid2050.com/grid_engine/202609060318-solar-farm/); Build Graph (ventus-grid-engine, https://ventusltd.github.io/ventus-grid-engine/genome/); Browser Observer Proof (ventus-grid-engine); V9 Engine Proof (ventus-grid-engine); and 3 more. Reached from 4 other entry points, including Homepage V090 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v090.html); Homepage V091 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v091.html); Homepage V093 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v093.html).
- What it achieves
- It is built from the distance km helper (`distanceKm`), the representative point helper (`representativePoint`) and the voltages kV helper (`voltagesKv`). Extracted verbatim (formula and constant unchanged) from `gridatlas/atlas/modules/202609011950-geodesy.js`. Its code works with 750 kV.
- Why it matters
- Loaded by the Solar Farm page in GlobalGrid2050 at https://globalgrid2050.com/grid_engine/202609060318-solar-farm/ and 2 other pages. Also imported by 4 files, including Build Graph, Browser Observer Proof and V9 Engine Proof.
- Application
- ventus-grid-engine · engine · JavaScript module
- VEDIC
- MEASURE (GG2050-VEDIC-000001): GridAtlas / Geodesy · Mathematics / Spherical geometry. coordinate_pair, coordinate_pair → distance_km
- VEDIC
- REPRESENT (GG2050-VEDIC-000002): GridAtlas / Geodesy · Computer science / Geometry processing. geojson_geometry → coordinate_pair_or_null
- VEDIC
- VOLTAGE (GG2050-VEDIC-000003): GridAtlas / Geodesy · Computer science / Data normalisation. voltage_properties → kilovolt_list
- Uses
- none found
- Used by
- linked from Grid Engine — Solar Farm Page (link), named by URL in Build Graph (estate URL), imported by Browser Observer Proof (import), imported by V9 Engine Proof (import), linked from Grid Engine — Site Geometry Page (link), imported by Compute Observer (import), named by URL in Ventus Grid Engine — Genome Page (estate URL)
- Produces
- EARTH_RADIUS_KM, distanceKm, representativePoint, voltagesKv, destinationPoint, initialBearingDeg, schema
- Defines here
- distanceKm, representativePoint, voltagesKv, destinationPoint, initialBearingDeg
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- ventus-grid-engine@ad566356a44e006682e956483d569f31ddbb9630 engine/v9-geodesy.js:1-141 · blob 14023f06d4ef2ea806437863bd35dee954c46b11 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: production_core
/**
* Module: geodesy
*
* Extracted verbatim (formula and constant unchanged) from
* gridatlas/atlas/modules/202609011950-geodesy.js.
*
* One Earth radius for the whole estate, and the three operations every
* measurement here is built from. This existed three times tonight - in
* the sandbox, in the substation cartridge and in the data repository -
* which is exactly how two of them end up on different radii without
* anyone noticing.
*
* Radius 6378.137 km, matching Ventusltd/grid-distance-maths. Haversine.
* No projection, no turf, no second radius for geometry.
*
* Pure functions. No DOM, no network, no state.
*
* CHANGED: source wraps this in `(() => { ... NS.geodesy = Object.freeze({...}) })()`
* and registers itself on `window.__GRIDATLAS_MODULES__.geodesy`. That
* closure/global-namespace wiring is removed; every function below is
* otherwise byte-identical to the source, including the atan2 argument
* order that the source's own comment insists on for numerical parity
* with ventus-corev8engine.js haversine() (see distanceKm below).
*/
export const EARTH_RADIUS_KM = 6378.137;
const DEG = Math.PI / 180;
export function distanceKm(lon1, lat1, lon2, lat2) {
const dLat = (lat2 - lat1) * DEG;
const dLon = (lon2 - lon1) * DEG;
const a = Math.sin(dLat / 2) ** 2
+ Math.cos(lat1 * DEG) * Math.cos(lat2 * DEG) * Math.sin(dLon / 2) ** 2;
/* atan2, in this operand order, because that is the form every version
of this estate has shipped - ventus-corev8engine.js haversine() and
every cartridge carried from it.
-------------------------------------------------------------------
The extraction wrote 2 * R * asin(sqrt(a)) instead. Algebraically the
same; numerically one unit in the last place apart, which the
all-versions proof caught on West Burton Solar to Cottam:
7.050150827184836 shipped, 7.050150827184837 from the module. It is
1e-15 km and changes no figure any reader will ever see - and it is
still wrong, because the claim being made is PARITY. A module that is
nearly the incumbent is a module that has to be argued about every
time a digit differs. */
return EARTH_RADIUS_KM * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
}
/* A polygon reduces to the mean of its outer ring, not its first corner.
A substation drawn as a compound outline would otherwise be measured
from whichever vertex the mapper happened to start at.
Point, Polygon and MultiPolygon, and NOTHING ELSE. The first draft of
this module accepted any nested coordinate array and so returned a
mean for a LineString where the incumbent returns null; the parity
proof caught it against the live cartridge. Extraction is not the
moment to change behaviour, so the behaviour is pinned here and any
widening becomes its own version with its own reasoning.
One deliberate difference, on malformed input only: this returns null
where the incumbent would throw on a Point with no coordinates. No
real geometry reaches that path, and a proof asserts it. */
export function representativePoint(geometry) {
if (!geometry) return null;
const { type, coordinates } = geometry;
if (type === 'Point') {
return Array.isArray(coordinates) && coordinates.length >= 2
? [coordinates[0], coordinates[1]] : null;
}
const ring = type === 'Polygon' ? coordinates && coordinates[0]
: type === 'MultiPolygon' ? coordinates && coordinates[0] && coordinates[0][0]
: null;
if (!Array.isArray(ring) || !ring.length) return null;
let sumLon = 0;
let sumLat = 0;
for (const point of ring) {
sumLon += point[0];
sumLat += point[1];
}
return [sumLon / ring.length, sumLat / ring.length];
}
/* OpenStreetMap's `voltage` is VOLTS at every magnitude, and a feature
may carry several separated by a semicolon. Magnitude is not the unit:
750 is a DC traction supply at a railway depot, not 750 kV. An audit
of the served payload found 229 features (3.95%) carrying a token
below 1,000, every one of which had been misread. An explicit `kv`
property is already kilovolts and is trusted as such. */
export function voltagesKv(properties) {
if (!properties) return [];
const out = [];
const explicit = properties.kv ?? properties.KV;
if (explicit != null && String(explicit).trim() !== '') {
for (const token of String(explicit).match(/\d+(?:\.\d+)?/g) || []) {
const value = Number(token);
if (Number.isFinite(value) && value > 0) out.push(value);
}
}
const volts = properties.voltage ?? properties.VOLTAGE;
if (volts != null) {
for (const token of String(volts).match(/\d+(?:\.\d+)?/g) || []) {
const value = Number(token);
if (Number.isFinite(value) && value > 0) out.push(value / 1000);
}
}
return [...new Set(out)].sort((a, b) => b - a);
}
/* Projection and bearing, carried in from the sandbox verbatim.
----------------------------------------------------------------------
The deep scan found the body carrying a SECOND geodesy section - "the
geodesy the layout needs, all on R_ATLAS" - four hundred lines away
from the first. Two geodesies in one file, on a constant that must
never differ, is the configuration that produced the divergence the
all-versions proof caught. Both belong here, on the one radius, and
the body now delegates rather than defining.
The bodies below are the incumbent's, character for character apart
from the radius identifier, so parity is a property of the move rather
than something to argue about afterwards. */
export function destinationPoint(lon, lat, km, bearingDeg) {
const ad = km / EARTH_RADIUS_KM;
const brg = bearingDeg * DEG;
const p1 = lat * DEG;
const p2 = Math.asin(Math.sin(p1) * Math.cos(ad)
+ Math.cos(p1) * Math.sin(ad) * Math.cos(brg));
const l2 = lon * DEG + Math.atan2(
Math.sin(brg) * Math.sin(ad) * Math.cos(p1),
Math.cos(ad) - Math.sin(p1) * Math.sin(p2));
return [l2 / DEG, p2 / DEG];
}
export function initialBearingDeg(lon1, lat1, lon2, lat2) {
const p1 = lat1 * DEG; const p2 = lat2 * DEG;
const dl = (lon2 - lon1) * DEG;
const y = Math.sin(dl) * Math.cos(p2);
const x = Math.cos(p1) * Math.sin(p2) - Math.sin(p1) * Math.cos(p2) * Math.cos(dl);
return (Math.atan2(y, x) / DEG + 360) % 360;
}
export const schema = 'gridatlas.module.geodesy.v1';