Skip to main content

Module geomath

Module geomath 

Source
Expand description

2i: PostGIS-geography math, ported from e1 (already calibrated equal to PostGIS to float precision there). Distances = Vincenty’s inverse formula on the WGS84 ellipsoid, in METRES; areas = spherical excess on the authalic sphere, in SQUARE METRES; point-in-polygon = planar even-odd crossing in coordinate space (the named subset deviation: correct away from poles/antimeridian; geography-PostGIS itself offers ST_Covers for the sphere-true predicate). Functions take (lat, lon) – PostGIS textual order; GeoJSON stores [lon, lat] and converters own the flip. Rings use the internal [[lat, lon], …] layout.

Functions§

geodesic_distance_m
Geodesic distance between two points in METRES on the WGS84 ellipsoid (Vincenty inverse). Matches PostGIS ST_Distance(a::geography, b::geography).
geodesic_path_length_m
Geodesic length of a [lat, lon] vertex path in METRES (sum of Vincenty edges). For a closed ring this is the perimeter. Matches PostGIS ST_Perimeter/ST_Length.
geodesic_ring_area_m2
Geodesic area of a polygon ring ([lat, lon]) in SQUARE METRES, via the spherical excess on the WGS84 authalic sphere. Matches PostGIS ST_Area(::geography) to ~1e-5 relative for city-scale polygons. Sign is dropped (absolute area); the ring need not be explicitly closed.
haversine_km
Great-circle (sphere) distance in KILOMETRES – the cheap pre-filter: diverges from Vincenty/WGS84 by < 0.56%, so any comparison further than that band from a threshold can be decided here without the iterative formula.
point_in_polygon
Test whether a point is inside a polygon ring using the ray-casting algorithm.