English | 简体中文
Pure-Go coordinate projections for weather and satellite grids: no cgo, no third-party dependencies, only the standard library.
simple-proj implements the subset of PROJ that GRIB and satellite products
actually use — lon/lat, Mercator, Lambert conformal conic, polar stereographic,
geostationary view, UTM, rotated-pole grids — plus WKT input and CRS-to-CRS
transforms. Numerical behaviour is checked against pyproj 3.8.0 / PROJ 9.8.1
on every commit.
Status: v0.2.0 · Go 1.27+ · 11 projections · statement coverage 98.3%
- No cgo. A pure-Go build cross-compiles and statically links anywhere; no PROJ shared library, no C toolchain, no runtime data directory.
- Runs everywhere Go does. No cgo means trivial cross-compilation; the library and its full test suite also build and run as js/wasm (verified under Node).
- Built for grids. Packed batch APIs, per-point domain errors, and GRIB
shape_of_the_earth→ ellipsoid conversion are first-class. - Verified, not approximated. Every projection is compared point-by-point
with pyproj on two independent point sets: a 33×33 golden grid and a 22-case
edge/random sweep. The fixtures are committed, so
go testneeds no Python.
go get github.com/knoweather/simple-projimport proj "github.com/knoweather/simple-proj"crs, err := proj.Parse("+proj=merc +a=6378137 +b=6378137 +units=km")
if err != nil {
// bad definition
}
p, err := crs.NewProjection() // build the instance once, then reuse it
if err != nil {
// unsupported projection or parameter
}
x, y, err := p.Forward(10, 0) // degrees -> kilometres
lon, lat, err := p.Inverse(x, y)Batch conversion uses packed [lon0,lat0,lon1,lat1,...] slices:
xy, err := proj.ForwardBatch(p, lonLat) // out-of-domain points become NaN
if errors.Is(err, proj.ErrDomain) {
// the batch completed; (NaN,NaN) marks the points outside the domain
}CRS-to-CRS conversion, including +towgs84 Helmert transforms:
from, _ := proj.Parse("EPSG:4326")
to, _ := proj.Parse("EPSG:3857")
tr, _ := proj.NewTransformer(from, to)
x, y, err := tr.Transform(0, 0)Runnable versions of these snippets live in example_test.go
and run as part of go test.
The wasm/ subpackage runs the same projection code in browsers and Node.js,
with parsed CRS handles kept on the Go side:
pwsh wasm/build.ps1 # or ./wasm/build.shconst p = simpleProj.parse("+proj=geos +h=35785863 +lon_0=140.7 +ellps=WGS84");
const { x, y } = simpleProj.forward(p.id, 140.7, 30.5);
const { xy, domain } = simpleProj.forwardBatch(p.id, new Float64Array([0, 0, 140.7, 30.5]));simpleProj exposes parse, forward, inverse, forwardBatch,
inverseBatch, transform, transformBatch, info and free. See
wasm/README.md for the full API, batch semantics and the
browser demo.
+proj= |
Description | Sphere / ellipsoid | Notes |
|---|---|---|---|
latlong / longlat |
longitude/latitude identity | — | output in degrees |
eqc |
Equidistant Cylindrical (Plate Carrée) | ✓ | +lat_ts; k_0 ignored |
geos |
Geostationary Satellite View | ✓ | +h required; +sweep=x/y |
stere |
Stereographic (polar/oblique/equatorial) | ✓ | +lat_ts folds into scale |
laea |
Lambert Azimuthal Equal-Area | ✓ | k_0 ignored |
lcc |
Lambert Conformal Conic | ✓ | one or two standard parallels |
merc |
Mercator | ✓ | +lat_ts; sphere or ellipsoid |
tmerc |
Transverse Mercator (Poder/Engsager 6th order) | ✓ | ` |
aeqd |
Azimuthal Equidistant | ✓ | ellipsoidal oblique uses Karney geodesics |
utm |
Universal Transverse Mercator | ✓ | +zone=1..60, +south |
ob_tran |
Rotated pole / oblique transverse | ✓ | GRIB2 templates 3.1/3.3 |
Also supported:
+units=/+to_meter=(m, km, ft, us-ft, mi, …), applied at the API layer;- WKT2 and WKT1 subset parsing (
Parseauto-detects WKT); - EPSG shortcuts: 4326, 4269, 3857, 900913, and WGS84 UTM 32601–32660 / 32701–32760;
+towgs843- and 7-parameter Helmert transforms throughNewTransformer;- GRIB
shape_of_the_earth0–11 plus dual-axis shapes 3/7 (GRIBEllipsoid,GRIBEllipsoidAxes); Info()metadata (Name,Domain,HasInverse,Accuracy, …) and reason-carryingDomainError(errors.Asgivesfar-pole,antipode,ce-limit, …) whileerrors.Is(err, ErrDomain)stays the primary check.
The reference data was generated with pyproj 3.8.0 / PROJ 9.8.1 and is committed under xcheck/:
- golden grids: 33×33 points for each projection, forward and inverse;
- 22-case extension sweep with structured edges and fixed-seed random points, including domain boundaries and unit scaling;
- WKT parity: 14 CRS × 2 dialects, parsed and compared against pyproj output;
- geodesics: 86 inverse + 71 direct cases, including near-antipodal and 8 m lines;
- rotated pole: 7 configurations, both directions.
Acceptance gates enforced by the test suite:
| Axis | Gate |
|---|---|
| forward | ≤ 1e-6 m absolute, with a relative floor for coordinates above ~1e6 m |
| inverse | ≤ 1e-9 deg absolute, with a relative floor for extreme displacements |
| round trip | ≤ 1e-9 deg, except at documented ill-conditioned edges |
| longitude | compared on the circle (−180° and +180° are the same meridian) |
The package has 98.3% statement coverage; the remaining paths are defensive branches (nil receivers, impossible constructor states) covered by dedicated tests where reachable.
CRS, Projection and Transformer are immutable after construction and can
be shared by any number of goroutines. Batch calls allocate only their output
slice; no per-point allocations, no locks, no global caches.
TestThreadSafety hammers every projection from 8 goroutines and compares the
results bit-for-bit with a serial run; the race detector runs on every push in
CI (go test -race ./...).
One rule: treat the CRS you get from Parse as read-only. Its exported
Params / UnknownParams / Towgs84 fields are shared with the projections
and metadata helpers, so mutating them concurrently is a data race.
1e6 points per batch, packed input, output allocation included. All rows are 1 alloc/op (the 16 MB output slice). Measured on Windows 11, AMD Ryzen 7 7840HS, Go 1.27.3, 2026-10-23; numbers vary with machine and load.
| Projection | ForwardBatch | InverseBatch |
|---|---|---|
latlong |
18 ms | 18 ms |
eqc |
48 ms | 43 ms |
geos |
108 ms | 91 ms |
ob_tran |
84 ms | 80 ms |
aeqd (ellipsoidal oblique) |
898 ms | 356 ms |
aeqd is the outlier by design: its ellipsoidal oblique/equatorial forward path
solves a geodesic per point, matching PROJ's algorithm. For equal-area,
conformal and Mercator workloads the per-point cost stays in the tens of
nanoseconds.
Reproduce with:
go test -run '^$' -bench . -benchmemThe core surface is small:
- types:
CRS,Projection,Transformer,Ellipsoid,DomainError; - constructors:
Parse,ParseWKT,CRS.NewProjection,NewTransformer; - conversion:
Forward,Inverse,Transform, and the batch variants; - errors:
ErrDomainpluserrors.Asfor*DomainError; - introspection:
CRS.String/EPSG/IsGeographic/Units/Equals,Info; - GRIB:
GRIBEllipsoid,GRIBEllipsoidAxes.
Until v1.0, minor releases may still adjust edge-case behaviour; exported names and signatures are kept stable unless a release note says otherwise.
Typical GRIB2 grid_template_number mapping:
| Template | +proj= |
|---|---|
| 3.0 / 3.1 regular and rotated lat/lon | latlong, or ob_tran for rotated grids |
| 3.10 Mercator | merc |
| 3.20 / 3.30 Lambert conformal | lcc |
| 3.40 / 3.41 geostationary | geos |
Rotated grids: GRIB gives the south pole (LaSP, LoSP); use
+o_lat_p = -LaSP and +lon_0 = LoSP (for example, ECMWF's north pole at
39.25°N, 162°W becomes +o_lat_p=39.25 +lon_0=18).
Deliberately out of scope:
- grid-shift datums (
+nadgridsNTv2/HARN), dynamic/ITRF datums; +proj=pipelinesyntax — useNewTransformerbetween two CRSs;- a full EPSG database (only the shortcuts listed above);
- WKT output, PROJJSON, and ESRI dialect details;
- 3D/4D coordinates, vertical datums, geoid grids;
- authority axis-order swapping: coordinates are always
lon,lat/x,y; - framework-level parallelism (the batch loops are already tight and allocation-free).
Parsing is strict: parameters whose semantics are not implemented (+pm,
+axis, +nadgrids, non-WGS84 +datum, the +R_A family, +geoc, +over,
…) fail at Parse instead of being silently ignored.
- simple-grib — pure-Go GRIB1/GRIB2 reader/writer, the source of grid definitions this library consumes;
- simple-sat — the satellite data stack that uses
simple-projfor resampling.
The Go gopher was designed by Renee French and is
licensed under CC BY 3.0. The logo in
docs/logo.svg is a derivative work based on that design.
MIT — see LICENSE.