wbprojection 0.1.0

Whitebox Projections is a map projection library for Rust, inspired by PROJ
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
//! Map projection implementations.
//!
//! Each projection lives in its own submodule and implements the common
//! projection interface via the `ProjectionImpl` trait.

mod aitoff;
mod albers;
mod axis_oriented;
mod azimuthal_equidistant;
mod behrmann;
mod bonne;
mod cassini;
mod central_conic;
mod collignon;
mod craster;
mod cylindrical_equal_area;
mod eckert_i;
mod eckert_ii;
mod eckert_iii;
mod eckert_iv;
mod eckert_v;
mod eckert_vi;
mod equirectangular;
mod equal_earth;
mod euler;
mod fahey;
mod foucaut;
mod gall_peters;
mod gall_stereographic;
mod geographic;
mod geocentric;
mod geostationary;
mod gnomonic;
mod hammer;
mod hatano;
mod hobo_dyer;
mod hotine_oblique_mercator;
mod lagrange;
mod kavrayskiy_v;
mod kavrayskiy_vii;
mod krovak;
mod lambert_azimuthal_equal_area;
mod lambert_conformal_conic;
mod loximuthal;
mod mercator;
mod miller_cylindrical;
mod murdoch_i;
mod murdoch_ii;
mod murdoch_iii;
mod mbt_s;
mod mbt_fps;
mod mbtfpp;
mod mbtfpq;
mod mollweide;
mod natural_earth;
mod natural_earth_ii;
mod nell;
mod nell_hammer;
mod orthographic;
mod patterson;
mod perspective_conic;
mod polar_stereographic;
mod polyconic;
mod putnins_p2;
mod putnins_p3;
mod putnins_p3p;
mod putnins_p4p;
mod putnins_p5;
mod putnins_p5p;
mod putnins_p6;
mod putnins_p6p;
mod putnins_p1;
mod quartic_authalic;
mod robinson;
mod sinusoidal;
mod stereographic;
mod times;
mod tissot;
mod two_point_equidistant;
mod tobler_mercator;
mod transverse_cylindrical_equal_area;
mod transverse_mercator;
mod van_der_grinten;
mod vertical;
mod wagner_i;
mod wagner_ii;
mod wagner_iii;
mod wagner_iv;
mod wagner_v;
mod wagner_vi;
mod werenskiold_i;
mod winkel_i;
mod winkel_ii;
mod winkel_tripel;
mod vitkovsky_i;

use crate::datum::Datum;
use crate::ellipsoid::Ellipsoid;
use crate::error::Result;
use crate::transform::{CoordTransform, Point2D};

/// Identifies which map projection algorithm to use.
#[derive(Debug, Clone, PartialEq)]
pub enum ProjectionKind {
    /// Geographic lon/lat degrees (identity pass-through).
    Geographic,
    /// Geocentric Earth-Centered Earth-Fixed (ECEF) Cartesian XYZ.
    Geocentric,
    /// Geostationary satellite view (near-sided perspective from geostationary orbit).
    Geostationary {
        /// Satellite altitude above the ellipsoid in meters.
        satellite_height: f64,
        /// Sweep axis selection (`true` for x-sweep, `false` for y-sweep).
        sweep_x: bool,
    },
    /// Vertical CRS (height-only axis).
    Vertical,
    /// Mercator cylindrical conformal projection.
    Mercator,
    /// Web Mercator (Google/EPSG:3857), sphere-based.
    WebMercator,
    /// Transverse Mercator (basis for UTM).
    TransverseMercator,
    /// Transverse Mercator with south-orientated axis convention.
    TransverseMercatorSouthOrientated,
    /// Universal Transverse Mercator (zone + hemisphere).
    Utm {
        /// UTM longitudinal zone in the range 1..=60.
        zone: u8,
        /// `true` for southern hemisphere; `false` for northern.
        south: bool,
    },
    /// Lambert Conformal Conic with one or two standard parallels.
    LambertConformalConic {
        /// First standard parallel in degrees.
        lat1: f64,
        /// Optional second standard parallel in degrees.
        lat2: Option<f64>,
    },
    /// Albers Equal-Area Conic.
    AlbersEqualAreaConic {
        /// First standard parallel in degrees.
        lat1: f64,
        /// Second standard parallel in degrees.
        lat2: f64,
    },
    /// Azimuthal Equidistant.
    AzimuthalEquidistant,
    /// Two-Point Equidistant.
    TwoPointEquidistant {
        /// Longitude of first control point in degrees.
        lon1: f64,
        /// Latitude of first control point in degrees.
        lat1: f64,
        /// Longitude of second control point in degrees.
        lon2: f64,
        /// Latitude of second control point in degrees.
        lat2: f64,
    },
    /// Lambert Azimuthal Equal-Area.
    LambertAzimuthalEqualArea,
    /// Krovak oblique conformal conic (EPSG method 9819).
    Krovak,
    /// Hotine Oblique Mercator (azimuth at projection center).
    ///
    /// `rectified_grid_angle` is used by Rectified Skew Orthomorphic methods.
    /// If omitted, it is treated as equal to `azimuth`.
    HotineObliqueMercator {
        /// Projection azimuth at center in degrees.
        azimuth: f64,
        /// Optional rectified grid angle in degrees.
        rectified_grid_angle: Option<f64>,
    },
    /// Central Conic projection.
    CentralConic {
        /// Standard parallel in degrees.
        lat1: f64,
    },
    /// Lagrange projection.
    Lagrange {
        /// Standard parallel in degrees.
        lat1: f64,
        /// Lagrange projection parameter `w`.
        w: f64,
    },
    /// Loximuthal projection.
    Loximuthal {
        /// Reference latitude in degrees.
        lat1: f64,
    },
    /// Euler conic projection.
    Euler {
        /// First standard parallel in degrees.
        lat1: f64,
        /// Second standard parallel in degrees.
        lat2: f64,
    },
    /// Tissot conic projection.
    Tissot {
        /// First standard parallel in degrees.
        lat1: f64,
        /// Second standard parallel in degrees.
        lat2: f64,
    },
    /// Murdoch I conic projection.
    MurdochI {
        /// First standard parallel in degrees.
        lat1: f64,
        /// Second standard parallel in degrees.
        lat2: f64,
    },
    /// Murdoch II conic projection.
    MurdochII {
        /// First standard parallel in degrees.
        lat1: f64,
        /// Second standard parallel in degrees.
        lat2: f64,
    },
    /// Murdoch III conic projection.
    MurdochIII {
        /// First standard parallel in degrees.
        lat1: f64,
        /// Second standard parallel in degrees.
        lat2: f64,
    },
    /// Perspective Conic projection.
    PerspectiveConic {
        /// First standard parallel in degrees.
        lat1: f64,
        /// Second standard parallel in degrees.
        lat2: f64,
    },
    /// Vitkovsky I conic projection.
    VitkovskyI {
        /// First standard parallel in degrees.
        lat1: f64,
        /// Second standard parallel in degrees.
        lat2: f64,
    },
    /// Tobler-Mercator projection.
    ToblerMercator,
    /// Winkel II projection.
    WinkelII,
    /// Kavrayskiy V projection.
    KavrayskiyV,
    /// Stereographic.
    Stereographic,
    /// Oblique Stereographic.
    ObliqueStereographic,
    /// Polar Stereographic (ellipsoidal).
    ///
    /// `north = true` for north-pole aspect, `false` for south-pole aspect.
    /// `lat_ts = Some(phi)` uses the given standard parallel (scale = 1 there, Variant B).
    /// `lat_ts = None` uses `ProjectionParams::scale` as kâ‚€ at the pole (Variant A).
    PolarStereographic {
        /// `true` for north-pole aspect, `false` for south-pole aspect.
        north: bool,
        /// Optional latitude of true scale in degrees.
        lat_ts: Option<f64>,
    },
    /// Orthographic.
    Orthographic,
    /// Sinusoidal pseudocylindrical.
    Sinusoidal,
    /// Mollweide pseudocylindrical.
    Mollweide,
    /// McBryde-Thomas Flat-Pole Sine (No. 2).
    MbtFps,
    /// McBryde-Thomas Flat-Polar Sine (No. 1).
    MbtS,
    /// McBryde-Thomas Flat-Polar Parabolic.
    Mbtfpp,
    /// McBryde-Thomas Flat-Polar Quartic.
    Mbtfpq,
    /// Nell projection.
    Nell,
    /// Equal Earth pseudocylindrical equal-area.
    EqualEarth,
    /// Lambert Cylindrical Equal-Area.
    CylindricalEqualArea {
        /// Latitude of true scale in degrees.
        lat_ts: f64,
    },
    /// Equirectangular (Plate Carrée).
    Equirectangular {
        /// Standard parallel in degrees.
        lat_ts: f64,
    },
    /// Robinson pseudocylindrical.
    Robinson,
    /// Gnomonic azimuthal projection.
    Gnomonic,
    /// Aitoff compromise projection.
    Aitoff,
    /// Van der Grinten I world projection.
    VanDerGrinten,
    /// Winkel Tripel world projection.
    WinkelTripel,
    /// Hammer equal-area world projection.
    Hammer,
    /// Hatano Asymmetrical Equal Area projection.
    Hatano,
    /// Eckert I pseudocylindrical world projection.
    EckertI,
    /// Eckert II pseudocylindrical world projection.
    EckertII,
    /// Eckert III pseudocylindrical world projection.
    EckertIII,
    /// Eckert IV equal-area world projection.
    EckertIV,
    /// Eckert V pseudocylindrical world projection.
    EckertV,
    /// Miller cylindrical projection.
    MillerCylindrical,
    /// Gall stereographic projection.
    GallStereographic,
    /// Gall-Peters equal-area cylindrical projection.
    GallPeters,
    /// Behrmann equal-area cylindrical projection.
    Behrmann,
    /// Hobo-Dyer equal-area cylindrical projection.
    HoboDyer,
    /// Wagner I projection.
    WagnerI,
    /// Wagner II projection.
    WagnerII,
    /// Wagner III projection.
    WagnerIII,
    /// Wagner IV projection.
    WagnerIV,
    /// Wagner V projection.
    WagnerV,
    /// Natural Earth projection.
    NaturalEarth,
    /// Natural Earth II projection.
    NaturalEarthII,
    /// Wagner VI projection.
    WagnerVI,
    /// Eckert VI projection.
    EckertVI,
    /// Transverse Cylindrical Equal Area.
    TransverseCylindricalEqualArea,
    /// American Polyconic projection.
    Polyconic,
    /// Cassini-Soldner projection.
    Cassini,
    /// Bonne projection.
    Bonne,
    /// Bonne with south-orientated axis convention.
    BonneSouthOrientated,
    /// Craster Parabolic (Putnins P4) projection.
    Craster,
    /// Putnins P4' projection.
    PutninsP4p,
    /// Fahey projection.
    Fahey,
    /// Times projection.
    Times,
    /// Patterson cylindrical projection.
    Patterson,
    /// Putnins P3 projection.
    PutninsP3,
    /// Putnins P3' projection.
    PutninsP3p,
    /// Putnins P5 projection.
    PutninsP5,
    /// Putnins P5' projection.
    PutninsP5p,
    /// Putnins P1 projection.
    PutninsP1,
    /// Putnins P2 projection.
    PutninsP2,
    /// Putnins P6 projection.
    PutninsP6,
    /// Putnins P6' projection.
    PutninsP6p,
    /// Quartic Authalic projection.
    QuarticAuthalic,
    /// Foucaut projection.
    Foucaut,
    /// Winkel I projection.
    WinkelI,
    /// Werenskiold I projection.
    WerenskioldI,
    /// Collignon equal-area projection.
    Collignon,
    /// Nell-Hammer projection.
    NellHammer,
    /// Kavrayskiy VII projection.
    KavrayskiyVII,
}

/// Parameters for constructing a projection.
#[derive(Debug, Clone)]
pub struct ProjectionParams {
    /// Which projection algorithm to use.
    pub kind: ProjectionKind,
    /// Central longitude (degrees). Default: 0.
    pub lon0: f64,
    /// Central latitude (degrees). Default: 0.
    pub lat0: f64,
    /// False easting (meters). Default: 0.
    pub false_easting: f64,
    /// False northing (meters). Default: 0.
    pub false_northing: f64,
    /// Scale factor at natural origin. Default: 1.
    pub scale: f64,
    /// Reference ellipsoid.
    pub ellipsoid: Ellipsoid,
    /// Datum (includes ellipsoid; overrides `ellipsoid` if set explicitly).
    pub datum: Datum,
}

impl Default for ProjectionParams {
    fn default() -> Self {
        ProjectionParams {
            kind: ProjectionKind::Equirectangular { lat_ts: 0.0 },
            lon0: 0.0,
            lat0: 0.0,
            false_easting: 0.0,
            false_northing: 0.0,
            scale: 1.0,
            ellipsoid: Ellipsoid::WGS84,
            datum: Datum::WGS84,
        }
    }
}

impl ProjectionParams {
    /// Create params for a specific projection kind with WGS84 ellipsoid.
    pub fn new(kind: ProjectionKind) -> Self {
        ProjectionParams {
            kind,
            ..Default::default()
        }
    }

    /// Create UTM projection params for the given zone and hemisphere.
    pub fn utm(zone: u8, south: bool) -> Self {
        let lon0 = (zone as f64 - 1.0) * 6.0 - 180.0 + 3.0;
        ProjectionParams {
            kind: ProjectionKind::Utm { zone, south },
            lon0,
            lat0: 0.0,
            false_easting: 500_000.0,
            false_northing: if south { 10_000_000.0 } else { 0.0 },
            scale: 0.9996,
            ellipsoid: Ellipsoid::WGS84,
            datum: Datum::WGS84,
        }
    }

    /// Create Web Mercator (EPSG:3857) params.
    pub fn web_mercator() -> Self {
        ProjectionParams {
            kind: ProjectionKind::WebMercator,
            lon0: 0.0,
            lat0: 0.0,
            false_easting: 0.0,
            false_northing: 0.0,
            scale: 1.0,
            ellipsoid: Ellipsoid::SPHERE,
            datum: Datum::WGS84,
        }
    }

    /// Set central longitude.
    pub fn with_lon0(mut self, lon0: f64) -> Self {
        self.lon0 = lon0;
        self
    }

    /// Set central latitude.
    pub fn with_lat0(mut self, lat0: f64) -> Self {
        self.lat0 = lat0;
        self
    }

    /// Set false easting.
    pub fn with_false_easting(mut self, fe: f64) -> Self {
        self.false_easting = fe;
        self
    }

    /// Set false northing.
    pub fn with_false_northing(mut self, fn_: f64) -> Self {
        self.false_northing = fn_;
        self
    }

    /// Set scale factor.
    pub fn with_scale(mut self, k: f64) -> Self {
        self.scale = k;
        self
    }

    /// Set the ellipsoid.
    pub fn with_ellipsoid(mut self, ellipsoid: Ellipsoid) -> Self {
        self.ellipsoid = ellipsoid.clone();
        self.datum = Datum {
            name: "Custom",
            ellipsoid,
            transform: crate::datum::DatumTransform::None,
        };
        self
    }
}

/// Internal trait implemented by each projection algorithm.
trait ProjectionImpl: Send + Sync {
    /// Forward projection: (lon_deg, lat_deg) → (x_m, y_m).
    fn forward(&self, lon_deg: f64, lat_deg: f64) -> Result<(f64, f64)>;

    /// Inverse projection: (x_m, y_m) → (lon_deg, lat_deg).
    fn inverse(&self, x: f64, y: f64) -> Result<(f64, f64)>;
}

/// A configured map projection ready for forward and inverse transformations.
pub struct Projection {
    params: ProjectionParams,
    inner: Box<dyn ProjectionImpl>,
}

impl std::fmt::Debug for Projection {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("Projection")
            .field("params", &self.params)
            .finish()
    }
}

impl Projection {
    /// Build a [`Projection`] from the given parameters.
    pub fn new(params: ProjectionParams) -> Result<Self> {
        let inner: Box<dyn ProjectionImpl> = match &params.kind {
            ProjectionKind::Geographic => Box::new(
                geographic::GeographicProj::new(&params)?,
            ),
            ProjectionKind::Geocentric => Box::new(
                geocentric::GeocentricProj::new(&params)?,
            ),
            ProjectionKind::Geostationary {
                satellite_height,
                sweep_x,
            } => Box::new(
                geostationary::GeostationaryProj::new(&params, *satellite_height, *sweep_x)?,
            ),
            ProjectionKind::Vertical => Box::new(
                vertical::VerticalProj::new(&params)?,
            ),
            ProjectionKind::Mercator => Box::new(
                mercator::MercatorProj::new(&params)?,
            ),
            ProjectionKind::WebMercator => Box::new(
                mercator::WebMercatorProj::new(&params)?,
            ),
            ProjectionKind::TransverseMercator => Box::new(
                transverse_mercator::TransverseMercatorProj::new(&params)?,
            ),
            ProjectionKind::TransverseMercatorSouthOrientated => Box::new(
                axis_oriented::AxisOrientedProj::new(
                    Box::new(transverse_mercator::TransverseMercatorProj::new(&params)?),
                    params.false_easting,
                    params.false_northing,
                    true,
                    true,
                ),
            ),
            ProjectionKind::Utm { zone, south } => {
                let _ = (zone, south); // Already baked into params
                Box::new(transverse_mercator::TransverseMercatorProj::new(&params)?)
            }
            ProjectionKind::LambertConformalConic { lat1, lat2 } => Box::new(
                lambert_conformal_conic::LccProj::new(&params, *lat1, *lat2)?,
            ),
            ProjectionKind::AlbersEqualAreaConic { lat1, lat2 } => Box::new(
                albers::AlbersProj::new(&params, *lat1, *lat2)?,
            ),
            ProjectionKind::AzimuthalEquidistant => Box::new(
                azimuthal_equidistant::AzimuthalEquidistantProj::new(&params)?,
            ),
            ProjectionKind::TwoPointEquidistant { lon1, lat1, lon2, lat2 } => Box::new(
                two_point_equidistant::TwoPointEquidistantProj::new(&params, *lon1, *lat1, *lon2, *lat2)?,
            ),
            ProjectionKind::LambertAzimuthalEqualArea => Box::new(
                lambert_azimuthal_equal_area::LambertAzimuthalEqualAreaProj::new(&params)?,
            ),
            ProjectionKind::Krovak => Box::new(
                krovak::KrovakProj::new(&params)?,
            ),
            ProjectionKind::HotineObliqueMercator {
                azimuth,
                rectified_grid_angle,
            } => Box::new(
                hotine_oblique_mercator::HotineObliqueMercatorProj::new(
                    &params,
                    *azimuth,
                    rectified_grid_angle.unwrap_or(*azimuth),
                )?,
            ),
            ProjectionKind::CentralConic { lat1 } => Box::new(
                central_conic::CentralConicProj::new(&params, *lat1)?,
            ),
            ProjectionKind::Lagrange { lat1, w } => Box::new(
                lagrange::LagrangeProj::new(&params, *lat1, *w)?,
            ),
            ProjectionKind::Loximuthal { lat1 } => Box::new(
                loximuthal::LoximuthalProj::new(&params, *lat1)?,
            ),
            ProjectionKind::Euler { lat1, lat2 } => Box::new(
                euler::EulerProj::new(&params, *lat1, *lat2)?,
            ),
            ProjectionKind::Tissot { lat1, lat2 } => Box::new(
                tissot::TissotProj::new(&params, *lat1, *lat2)?,
            ),
            ProjectionKind::MurdochI { lat1, lat2 } => Box::new(
                murdoch_i::MurdochIProj::new(&params, *lat1, *lat2)?,
            ),
            ProjectionKind::MurdochII { lat1, lat2 } => Box::new(
                murdoch_ii::MurdochIIProj::new(&params, *lat1, *lat2)?,
            ),
            ProjectionKind::MurdochIII { lat1, lat2 } => Box::new(
                murdoch_iii::MurdochIIIProj::new(&params, *lat1, *lat2)?,
            ),
            ProjectionKind::PerspectiveConic { lat1, lat2 } => Box::new(
                perspective_conic::PerspectiveConicProj::new(&params, *lat1, *lat2)?,
            ),
            ProjectionKind::VitkovskyI { lat1, lat2 } => Box::new(
                vitkovsky_i::VitkovskyIProj::new(&params, *lat1, *lat2)?,
            ),
            ProjectionKind::ToblerMercator => Box::new(
                tobler_mercator::ToblerMercatorProj::new(&params)?,
            ),
            ProjectionKind::WinkelII => Box::new(
                winkel_ii::WinkelIIProj::new(&params)?,
            ),
            ProjectionKind::KavrayskiyV => Box::new(
                kavrayskiy_v::KavrayskiyVProj::new(&params)?,
            ),
            ProjectionKind::Stereographic => Box::new(
                stereographic::StereographicProj::new(&params)?,
            ),
            ProjectionKind::PolarStereographic { north, lat_ts } => Box::new(
                polar_stereographic::PolarStereographicProj::new(&params, *north, *lat_ts)?,
            ),
            ProjectionKind::ObliqueStereographic => Box::new(
                stereographic::StereographicProj::new(&params)?,
            ),
            ProjectionKind::Orthographic => Box::new(
                orthographic::OrthographicProj::new(&params)?,
            ),
            ProjectionKind::Sinusoidal => Box::new(
                sinusoidal::SinusoidalProj::new(&params)?,
            ),
            ProjectionKind::Mollweide => Box::new(
                mollweide::MollweideProj::new(&params)?,
            ),
            ProjectionKind::MbtFps => Box::new(
                mbt_fps::MbtFpsProj::new(&params)?,
            ),
            ProjectionKind::MbtS => Box::new(
                mbt_s::MbtSProj::new(&params)?,
            ),
            ProjectionKind::Mbtfpp => Box::new(
                mbtfpp::MbtfppProj::new(&params)?,
            ),
            ProjectionKind::Mbtfpq => Box::new(
                mbtfpq::MbtfpqProj::new(&params)?,
            ),
            ProjectionKind::Nell => Box::new(
                nell::NellProj::new(&params)?,
            ),
            ProjectionKind::EqualEarth => Box::new(
                equal_earth::EqualEarthProj::new(&params)?,
            ),
            ProjectionKind::MillerCylindrical => Box::new(
                miller_cylindrical::MillerCylindricalProj::new(&params)?,
            ),
            ProjectionKind::GallStereographic => Box::new(
                gall_stereographic::GallStereographicProj::new(&params)?,
            ),
            ProjectionKind::GallPeters => Box::new(
                gall_peters::GallPetersProj::new(&params)?,
            ),
            ProjectionKind::Behrmann => Box::new(
                behrmann::BehrmannProj::new(&params)?,
            ),
            ProjectionKind::HoboDyer => Box::new(
                hobo_dyer::HoboDyerProj::new(&params)?,
            ),
            ProjectionKind::WagnerI => Box::new(
                wagner_i::WagnerIProj::new(&params)?,
            ),
            ProjectionKind::WagnerII => Box::new(
                wagner_ii::WagnerIiProj::new(&params)?,
            ),
            ProjectionKind::WagnerIII => Box::new(
                wagner_iii::WagnerIiiProj::new(&params)?,
            ),
            ProjectionKind::WagnerIV => Box::new(
                wagner_iv::WagnerIvProj::new(&params)?,
            ),
            ProjectionKind::WagnerV => Box::new(
                wagner_v::WagnerVProj::new(&params)?,
            ),
            ProjectionKind::NaturalEarth => Box::new(
                natural_earth::NaturalEarthProj::new(&params)?,
            ),
            ProjectionKind::NaturalEarthII => Box::new(
                natural_earth_ii::NaturalEarthIIProj::new(&params)?,
            ),
            ProjectionKind::WagnerVI => Box::new(
                wagner_vi::WagnerViProj::new(&params)?,
            ),
            ProjectionKind::EckertVI => Box::new(
                eckert_vi::EckertViProj::new(&params)?,
            ),
            ProjectionKind::TransverseCylindricalEqualArea => Box::new(
                transverse_cylindrical_equal_area::TransverseCylindricalEqualAreaProj::new(&params)?,
            ),
            ProjectionKind::Polyconic => Box::new(
                polyconic::PolyconicProj::new(&params)?,
            ),
            ProjectionKind::Cassini => Box::new(
                cassini::CassiniProj::new(&params)?,
            ),
            ProjectionKind::Bonne => Box::new(
                bonne::BonneProj::new(&params)?,
            ),
            ProjectionKind::BonneSouthOrientated => Box::new(
                axis_oriented::AxisOrientedProj::new(
                    Box::new(bonne::BonneProj::new(&params)?),
                    params.false_easting,
                    params.false_northing,
                    true,
                    true,
                ),
            ),
            ProjectionKind::Craster => Box::new(
                craster::CrasterProj::new(&params)?,
            ),
            ProjectionKind::PutninsP4p => Box::new(
                putnins_p4p::PutninsP4pProj::new(&params)?,
            ),
            ProjectionKind::Fahey => Box::new(
                fahey::FaheyProj::new(&params)?,
            ),
            ProjectionKind::Times => Box::new(
                times::TimesProj::new(&params)?,
            ),
            ProjectionKind::Patterson => Box::new(
                patterson::PattersonProj::new(&params)?,
            ),
            ProjectionKind::PutninsP3 => Box::new(
                putnins_p3::PutninsP3Proj::new(&params)?,
            ),
            ProjectionKind::PutninsP3p => Box::new(
                putnins_p3p::PutninsP3pProj::new(&params)?,
            ),
            ProjectionKind::PutninsP5 => Box::new(
                putnins_p5::PutninsP5Proj::new(&params)?,
            ),
            ProjectionKind::PutninsP5p => Box::new(
                putnins_p5p::PutninsP5pProj::new(&params)?,
            ),
            ProjectionKind::PutninsP1 => Box::new(
                putnins_p1::PutninsP1Proj::new(&params)?,
            ),
            ProjectionKind::PutninsP2 => Box::new(
                putnins_p2::PutninsP2Proj::new(&params)?,
            ),
            ProjectionKind::PutninsP6 => Box::new(
                putnins_p6::PutninsP6Proj::new(&params)?,
            ),
            ProjectionKind::PutninsP6p => Box::new(
                putnins_p6p::PutninsP6pProj::new(&params)?,
            ),
            ProjectionKind::QuarticAuthalic => Box::new(
                quartic_authalic::QuarticAuthalicProj::new(&params)?,
            ),
            ProjectionKind::Foucaut => Box::new(
                foucaut::FoucautProj::new(&params)?,
            ),
            ProjectionKind::WinkelI => Box::new(
                winkel_i::WinkelIProj::new(&params)?,
            ),
            ProjectionKind::WerenskioldI => Box::new(
                werenskiold_i::WerenskioldIProj::new(&params)?,
            ),
            ProjectionKind::CylindricalEqualArea { lat_ts } => Box::new(
                cylindrical_equal_area::CylindricalEqualAreaProj::new(&params, *lat_ts)?,
            ),
            ProjectionKind::Equirectangular { lat_ts } => Box::new(
                equirectangular::EquirectangularProj::new(&params, *lat_ts)?,
            ),
            ProjectionKind::Robinson => Box::new(
                robinson::RobinsonProj::new(&params)?,
            ),
            ProjectionKind::Gnomonic => Box::new(
                gnomonic::GnomonicProj::new(&params)?,
            ),
            ProjectionKind::Aitoff => Box::new(
                aitoff::AitoffProj::new(&params)?,
            ),
            ProjectionKind::VanDerGrinten => Box::new(
                van_der_grinten::VanDerGrintenProj::new(&params)?,
            ),
            ProjectionKind::WinkelTripel => Box::new(
                winkel_tripel::WinkelTripelProj::new(&params)?,
            ),
            ProjectionKind::Hammer => Box::new(
                hammer::HammerProj::new(&params)?,
            ),
            ProjectionKind::Hatano => Box::new(
                hatano::HatanoProj::new(&params)?,
            ),
            ProjectionKind::EckertI => Box::new(
                eckert_i::EckertIProj::new(&params)?,
            ),
            ProjectionKind::EckertII => Box::new(
                eckert_ii::EckertIiProj::new(&params)?,
            ),
            ProjectionKind::EckertIII => Box::new(
                eckert_iii::EckertIiiProj::new(&params)?,
            ),
            ProjectionKind::EckertIV => Box::new(
                eckert_iv::EckertIvProj::new(&params)?,
            ),
            ProjectionKind::EckertV => Box::new(
                eckert_v::EckertVProj::new(&params)?,
            ),
            ProjectionKind::Collignon => Box::new(
                collignon::CollignonProj::new(&params)?,
            ),
            ProjectionKind::NellHammer => Box::new(
                nell_hammer::NellHammerProj::new(&params)?,
            ),
            ProjectionKind::KavrayskiyVII => Box::new(
                kavrayskiy_vii::KavrayskiyViiProj::new(&params)?,
            ),
        };

        Ok(Projection { params, inner })
    }

    /// Forward projection: geographic (lon, lat) degrees → projected (x, y) meters.
    pub fn forward(&self, lon_deg: f64, lat_deg: f64) -> Result<(f64, f64)> {
        self.inner.forward(lon_deg, lat_deg)
    }

    /// Inverse projection: projected (x, y) meters → geographic (lon, lat) degrees.
    pub fn inverse(&self, x: f64, y: f64) -> Result<(f64, f64)> {
        self.inner.inverse(x, y)
    }

    /// Return a reference to the projection parameters.
    pub fn params(&self) -> &ProjectionParams {
        &self.params
    }

    /// Return the name of the projection.
    pub fn name(&self) -> &str {
        match &self.params.kind {
            ProjectionKind::Geographic => "Geographic",
            ProjectionKind::Geocentric => "Geocentric",
            ProjectionKind::Geostationary { .. } => "Geostationary Satellite View",
            ProjectionKind::Vertical => "Vertical",
            ProjectionKind::Mercator => "Mercator",
            ProjectionKind::WebMercator => "Web Mercator",
            ProjectionKind::TransverseMercator => "Transverse Mercator",
            ProjectionKind::TransverseMercatorSouthOrientated => "Transverse Mercator South Orientated",
            ProjectionKind::Utm { zone, south } => {
                let _ = (zone, south);
                "UTM"
            }
            ProjectionKind::LambertConformalConic { .. } => "Lambert Conformal Conic",
            ProjectionKind::AlbersEqualAreaConic { .. } => "Albers Equal-Area Conic",
            ProjectionKind::AzimuthalEquidistant => "Azimuthal Equidistant",
            ProjectionKind::TwoPointEquidistant { .. } => "Two-Point Equidistant",
            ProjectionKind::LambertAzimuthalEqualArea => "Lambert Azimuthal Equal-Area",
            ProjectionKind::Krovak => "Krovak",
            ProjectionKind::HotineObliqueMercator { .. } => "Hotine Oblique Mercator",
            ProjectionKind::CentralConic { .. } => "Central Conic",
            ProjectionKind::Lagrange { .. } => "Lagrange",
            ProjectionKind::Loximuthal { .. } => "Loximuthal",
            ProjectionKind::Euler { .. } => "Euler",
            ProjectionKind::Tissot { .. } => "Tissot",
            ProjectionKind::MurdochI { .. } => "Murdoch I",
            ProjectionKind::MurdochII { .. } => "Murdoch II",
            ProjectionKind::MurdochIII { .. } => "Murdoch III",
            ProjectionKind::PerspectiveConic { .. } => "Perspective Conic",
            ProjectionKind::VitkovskyI { .. } => "Vitkovsky I",
            ProjectionKind::ToblerMercator => "Tobler-Mercator",
            ProjectionKind::WinkelII => "Winkel II",
            ProjectionKind::KavrayskiyV => "Kavrayskiy V",
            ProjectionKind::Stereographic => "Stereographic",
            ProjectionKind::PolarStereographic { north, .. } => {
                if *north { "Polar Stereographic (North)" } else { "Polar Stereographic (South)" }
            }
            ProjectionKind::ObliqueStereographic => "Oblique Stereographic",
            ProjectionKind::Orthographic => "Orthographic",
            ProjectionKind::Sinusoidal => "Sinusoidal",
            ProjectionKind::Mollweide => "Mollweide",
            ProjectionKind::MbtFps => "McBryde-Thomas Flat-Pole Sine (No. 2)",
            ProjectionKind::MbtS => "McBryde-Thomas Flat-Polar Sine (No. 1)",
            ProjectionKind::Mbtfpp => "McBryde-Thomas Flat-Polar Parabolic",
            ProjectionKind::Mbtfpq => "McBryde-Thomas Flat-Polar Quartic",
            ProjectionKind::Nell => "Nell",
            ProjectionKind::EqualEarth => "Equal Earth",
            ProjectionKind::CylindricalEqualArea { .. } => "Cylindrical Equal Area",
            ProjectionKind::Equirectangular { .. } => "Equirectangular",
            ProjectionKind::Robinson => "Robinson",
            ProjectionKind::Gnomonic => "Gnomonic",
            ProjectionKind::Aitoff => "Aitoff",
            ProjectionKind::VanDerGrinten => "Van der Grinten",
            ProjectionKind::WinkelTripel => "Winkel Tripel",
            ProjectionKind::Hammer => "Hammer",
            ProjectionKind::Hatano => "Hatano",
            ProjectionKind::EckertI => "Eckert I",
            ProjectionKind::EckertII => "Eckert II",
            ProjectionKind::EckertIII => "Eckert III",
            ProjectionKind::EckertIV => "Eckert IV",
            ProjectionKind::EckertV => "Eckert V",
            ProjectionKind::MillerCylindrical => "Miller Cylindrical",
            ProjectionKind::GallStereographic => "Gall Stereographic",
            ProjectionKind::GallPeters => "Gall-Peters",
            ProjectionKind::Behrmann => "Behrmann",
            ProjectionKind::HoboDyer => "Hobo-Dyer",
            ProjectionKind::WagnerI => "Wagner I",
            ProjectionKind::WagnerII => "Wagner II",
            ProjectionKind::WagnerIII => "Wagner III",
            ProjectionKind::WagnerIV => "Wagner IV",
            ProjectionKind::WagnerV => "Wagner V",
            ProjectionKind::NaturalEarth => "Natural Earth",
            ProjectionKind::NaturalEarthII => "Natural Earth II",
            ProjectionKind::WagnerVI => "Wagner VI",
            ProjectionKind::EckertVI => "Eckert VI",
            ProjectionKind::TransverseCylindricalEqualArea => "Transverse Cylindrical Equal Area",
            ProjectionKind::Polyconic => "Polyconic",
            ProjectionKind::Cassini => "Cassini-Soldner",
            ProjectionKind::Bonne => "Bonne",
            ProjectionKind::BonneSouthOrientated => "Bonne South Orientated",
            ProjectionKind::Craster => "Craster",
            ProjectionKind::PutninsP4p => "Putnins P4'",
            ProjectionKind::Fahey => "Fahey",
            ProjectionKind::Times => "Times",
            ProjectionKind::Patterson => "Patterson",
            ProjectionKind::PutninsP3 => "Putnins P3",
            ProjectionKind::PutninsP3p => "Putnins P3'",
            ProjectionKind::PutninsP5 => "Putnins P5",
            ProjectionKind::PutninsP5p => "Putnins P5'",
            ProjectionKind::PutninsP1 => "Putnins P1",
            ProjectionKind::PutninsP2 => "Putnins P2",
            ProjectionKind::PutninsP6 => "Putnins P6",
            ProjectionKind::PutninsP6p => "Putnins P6'",
            ProjectionKind::QuarticAuthalic => "Quartic Authalic",
            ProjectionKind::Foucaut => "Foucaut",
            ProjectionKind::WinkelI => "Winkel I",
            ProjectionKind::WerenskioldI => "Werenskiold I",
            ProjectionKind::Collignon => "Collignon",
            ProjectionKind::NellHammer => "Nell-Hammer",
            ProjectionKind::KavrayskiyVII => "Kavrayskiy VII",
        }
    }
}

impl CoordTransform for Projection {
    fn transform_fwd(&self, point: Point2D) -> Result<Point2D> {
        let (x, y) = self.forward(point.x, point.y)?;
        Ok(Point2D::new(x, y))
    }

    fn transform_inv(&self, point: Point2D) -> Result<Point2D> {
        let (lon, lat) = self.inverse(point.x, point.y)?;
        Ok(Point2D::new(lon, lat))
    }
}