Struct EqualEarth

Prepared Equal Earth projection with explicit central meridian and offsets.

struct EqualEarth(T)
  
if (isGeodesyScalar!T);

Properties

NameTypeDescription
isValid[get] boolWhether the prepared projection has a valid supported ellipsoid.

Methods

NameDescription
forward (source) Project a geographic coordinate; throws on failure.
fromParameters (ellipsoid, centralMeridian, falseEasting, falseNorthing) Prepare a projection or throw for unsupported parameters.
reverse (source) Invert a projected point or throw on failure.
tryForward (source, result) Project a geographic coordinate without throwing.
tryFromParameters (ellipsoid, centralMeridian, falseEasting, falseNorthing, result) Try to prepare the supported sphere/oblate Equal Earth projection.
tryReverse (source, result) Invert a point in the represented Equal Earth footprint.

Example

Example

construct a prepared Equal Earth projection.

import geodesy.ellipsoid : wgs84;
auto projection = EqualEarth!double.fromParameters(
    wgs84!double(), Longitude!double.fromDegrees(0), 0.0, 0.0);
assert(projection.isValid);

Example

Verify public double and float projection round trips.

import geodesy.ellipsoid : wgs84;
foreach (unused; 0 .. 1)
{
    const projection = EqualEarth!double.fromParameters(
        wgs84!double(), Longitude!double.fromDegrees(0), 0.0, 0.0);
    const vienna = GeographicCoordinate!double.fromComponents(
        Latitude!double.fromDegrees(48.20849),
        Longitude!double.fromDegrees(16.37208));
    GeographicCoordinate!double roundTrip;
    assert(projection.tryReverse(projection.forward(vienna), roundTrip));
    assert(fabs(roundTrip.latitude.degrees - 48.20849) < 1e-8);
    assert(fabs(roundTrip.longitude.degrees - 16.37208) < 1e-8);
    EqualEarth!double invalid;
    assert(!invalid.isValid);
}

Example

Differential fixtures independently generated with PROJ 9.5.1 (+proj=eqearth +lon_0=0, WGS84 and spherical a=b=6371000). Distances are in metres. These values must not be derived from this module.

import geodesy.ellipsoid : wgs84;

const sphere = Ellipsoid!double.fromFlattening(6_371_000.0, 0.0);
const ellipsoids = [sphere, wgs84!double()];
const lon = [16.37208, 117.196763611, -179.999, 175.0];
const lat = [48.20849, 34.0575469444, 85.0, -55.0];
const sphericalX = [1_312_345.48091405, 10_295_861.09219202,
                    -10_326_640.10435293, 13_246_250.77046278];
const sphericalY = [5_816_365.43582457, 4_256_722.06905651,
                    8_345_677.93982351, -6_484_657.08620553];
const ellipsoidalX = [1_313_648.69768603, 10_302_257.07829061,
                      -10_327_625.55645225, 13_260_771.75350931];
const ellipsoidalY = [5_803_253.62355814, 4_242_849.75761119,
                      8_345_267.17633819, -6_473_350.64232608];

foreach (model; 0 .. 2)
{
    const projection = EqualEarth!double.fromParameters(
        ellipsoids[model], Longitude!double.fromDegrees(0), 0.0, 0.0);
    foreach (i; 0 .. lon.length)
    {
        const source = GeographicCoordinate!double.fromComponents(
            Latitude!double.fromDegrees(lat[i]),
            Longitude!double.fromDegrees(lon[i]));
        const projected = projection.forward(source);
        const expectedX = model == 0 ? sphericalX[i] : ellipsoidalX[i];
        const expectedY = model == 0 ? sphericalY[i] : ellipsoidalY[i];
        assert(fabs(projected.easting - expectedX) < 0.025);
        assert(fabs(projected.northing - expectedY) < 0.025);

        GeographicCoordinate!double recovered;
        assert(projection.tryReverse(projected, recovered));
        assert(fabs(recovered.latitude.degrees - lat[i]) < 1e-7);
        assert(fabs(recovered.longitude.degrees - lon[i]) < 1e-7);
    }
}

Example

Qualify finite-domain rejection and the equatorial seam for double.

import geodesy.ellipsoid : wgs84;

const projection = EqualEarth!double.fromParameters(
    wgs84!double(), Longitude!double.fromDegrees(0),
    1200.0, -4500.0);

GeographicCoordinate!double ignored;
assert(!projection.tryReverse(
    ProjectedCoordinate!double.fromComponents(100_000_000.0, -4500.0),
    ignored));
assert(!projection.tryReverse(
    ProjectedCoordinate!double.fromComponents(1200.0, 100_000_000.0),
    ignored));

foreach (degrees; [-179.999, -100.0, 0.0, 100.0, 179.999])
{
    const source = GeographicCoordinate!double.fromComponents(
        Latitude!double.fromDegrees(0.0),
        Longitude!double.fromDegrees(degrees));
    const projected = projection.forward(source);
    GeographicCoordinate!double reverse;
    assert(projection.tryReverse(projected, reverse));
    assert(fabs(reverse.latitude.degrees) < 1e-10);
    assert(fabs(reverse.longitude.degrees - degrees) < 1e-8);
}

const north = GeographicCoordinate!double.fromComponents(
    Latitude!double.fromDegrees(90.0),
    Longitude!double.fromDegrees(0.0));
const south = GeographicCoordinate!double.fromComponents(
    Latitude!double.fromDegrees(-90.0),
    Longitude!double.fromDegrees(0.0));
assert(isFinite(projection.forward(north).northing));
assert(isFinite(projection.forward(south).northing));

Example

Instantiate checked and throwing Equal Earth operations for each scalar.

import geodesy.ellipsoid : wgs84;
import std.meta : AliasSeq;

static foreach (T; AliasSeq!(float, double, real))
{{
    EqualEarth!T projection;
    assert(EqualEarth!T.tryFromParameters(
        wgs84!T(), Longitude!T.fromDegrees(cast(T) 0),
        cast(T) 0, cast(T) 0, projection));
    const point = GeographicCoordinate!T.fromComponents(
        Latitude!T.fromDegrees(cast(T) 30),
        Longitude!T.fromDegrees(cast(T) 45));
    const mapped = projection.forward(point);
    GeographicCoordinate!T back;
    assert(projection.tryReverse(mapped, back));
    const T tolerance = is(T == float) ? cast(T) 0.001 : cast(T) 1e-7;
    assert(fabs(back.latitude.degrees - cast(T) 30) < tolerance);
    assert(fabs(back.longitude.degrees - cast(T) 45) < tolerance);
}}

Example

Regression grid for the bounded authalic inverse, including polar approaches.

import geodesy.ellipsoid : wgs84;
import std.math : fabs;

const projection = EqualEarth!double.fromParameters(
    wgs84!double(), Longitude!double.fromDegrees(0), 0.0, 0.0);
const double[] latitudes = [
    -89.999999, -89.99, -85.0, -60.0, -30.0, -1.0,
    -0.000001, 0.0, 0.000001, 1.0, 30.0, 60.0, 85.0,
    89.99, 89.999999
];
const double[] longitudes = [-179.999, -100.0, 0.0, 100.0, 179.999];
foreach (lat; latitudes)
{
    foreach (lon; longitudes)
    {
        const original = GeographicCoordinate!double.fromComponents(
            Latitude!double.fromDegrees(lat),
            Longitude!double.fromDegrees(lon));
        ProjectedCoordinate!double projected;
        assert(projection.tryForward(original, projected));
        GeographicCoordinate!double recovered;
        assert(projection.tryReverse(projected, recovered));
        assert(fabs(recovered.latitude.degrees - lat) < 2e-6);
        assert(fabs(recovered.longitude.degrees - lon) < 2e-6);
    }
}