geodetic 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -8
  3. data/README.md +66 -25
  4. data/docs/coordinate-systems/gars.md +0 -4
  5. data/docs/coordinate-systems/georef.md +0 -4
  6. data/docs/coordinate-systems/gh.md +0 -4
  7. data/docs/coordinate-systems/gh36.md +0 -4
  8. data/docs/coordinate-systems/h3.md +0 -4
  9. data/docs/coordinate-systems/ham.md +0 -4
  10. data/docs/coordinate-systems/index.md +2 -2
  11. data/docs/coordinate-systems/olc.md +0 -4
  12. data/docs/index.md +3 -0
  13. data/docs/reference/conversions.md +15 -15
  14. data/docs/reference/feature.md +116 -0
  15. data/docs/reference/map-rendering.md +32 -0
  16. data/docs/reference/serialization.md +4 -4
  17. data/examples/02_all_coordinate_systems.rb +0 -3
  18. data/examples/03_distance_calculations.rb +1 -0
  19. data/examples/04_bearing_calculations.rb +1 -0
  20. data/examples/05_map_rendering/.gitignore +2 -0
  21. data/examples/05_map_rendering/demo.rb +264 -0
  22. data/examples/05_map_rendering/icons/bridge.png +0 -0
  23. data/examples/05_map_rendering/icons/building.png +0 -0
  24. data/examples/05_map_rendering/icons/landmark.png +0 -0
  25. data/examples/05_map_rendering/icons/monument.png +0 -0
  26. data/examples/05_map_rendering/icons/park.png +0 -0
  27. data/examples/05_map_rendering/nyc_landmarks.png +0 -0
  28. data/examples/README.md +62 -0
  29. data/fiddle_pointer_buffer_pool.md +119 -0
  30. data/lib/geodetic/coordinate/bng.rb +14 -33
  31. data/lib/geodetic/coordinate/ecef.rb +5 -1
  32. data/lib/geodetic/coordinate/enu.rb +4 -0
  33. data/lib/geodetic/coordinate/gars.rb +2 -3
  34. data/lib/geodetic/coordinate/georef.rb +2 -3
  35. data/lib/geodetic/coordinate/gh.rb +2 -4
  36. data/lib/geodetic/coordinate/gh36.rb +4 -5
  37. data/lib/geodetic/coordinate/h3.rb +2 -3
  38. data/lib/geodetic/coordinate/ham.rb +2 -3
  39. data/lib/geodetic/coordinate/lla.rb +7 -1
  40. data/lib/geodetic/coordinate/mgrs.rb +1 -1
  41. data/lib/geodetic/coordinate/ned.rb +4 -0
  42. data/lib/geodetic/coordinate/olc.rb +0 -1
  43. data/lib/geodetic/coordinate/spatial_hash.rb +2 -2
  44. data/lib/geodetic/coordinate/ups.rb +1 -1
  45. data/lib/geodetic/coordinate/usng.rb +1 -1
  46. data/lib/geodetic/coordinate/utm.rb +1 -1
  47. data/lib/geodetic/coordinate/web_mercator.rb +1 -1
  48. data/lib/geodetic/coordinate.rb +30 -26
  49. data/lib/geodetic/feature.rb +44 -0
  50. data/lib/geodetic/geoid_height.rb +11 -6
  51. data/lib/geodetic/version.rb +1 -1
  52. data/lib/geodetic.rb +1 -0
  53. data/mkdocs.yml +2 -0
  54. metadata +14 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d81eb7c69d9aff7d512562f54e2413c91c8ff10b2361c9143a8afd0c1af0ca0
4
- data.tar.gz: e7fb09dd1f7d4d97f57ea48f9cacb0e6afbd30abedab1aa04cbf1153c2fe4373
3
+ metadata.gz: 13b2b50f8ff03c2093abf1a2454f3db38942f9c32918eb23aab30b6c45a4146b
4
+ data.tar.gz: 2b3d5a7f325e2766196d2997e9c1781f0425abe016edeeb2fe4f155fc6a43f13
5
5
  SHA512:
6
- metadata.gz: 90a2e1b8bbc1c6bdf59c7e326d4965f8ec85a16682bccba948fd1f104d7818a5fa34ee179fa00de0221cbfd0e9d9afbd5c667aac46c1a6c9c070b338618b461a
7
- data.tar.gz: 85b40d6e961ec4782a9748232eed4191df1dd8a5f22df77afe68c63d64b6b23df0e8ff5ec4ae927038d60919a7825e09c2429bbd4aa8d4447b1737ff81aa4dfd
6
+ metadata.gz: 1d0378c9df0e04f9bb3de688303abae35857c4fbc594a26094a983417baa55004ef7f7f4cef7c8db7511b8fc769d0a368420e7601cb04e12eaf887b324e51e61
7
+ data.tar.gz: c20dd6fa952579d8d035e1afd146d7337caa087efd71df4db17dcc3918b8cb4c561237f1cb5820167d9f84a64209da48a1dd38d0b46a5bccf0e3ce6959aa06d3
data/CHANGELOG.md CHANGED
@@ -11,21 +11,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
11
11
  ## [Unreleased]
12
12
 
13
13
 
14
- ## [0.2.0] - 2026-03-08
14
+ ## [0.3.1] - 2026-03-09
15
15
 
16
16
  ### Added
17
17
 
18
- - **3 new coordinate systems** bringing the total from 15 to 18:
19
- - `Geodetic::Coordinate::GEOREF`World Geographic Reference System (aviation/military geocode with variable precision from 15-degree tiles to 0.001-minute resolution)
20
- - `Geodetic::Coordinate::GARS` Global Area Reference System (NGA standard with 30-minute cells, 15-minute quadrants, and 5-minute keypads)
21
- - `Geodetic::Coordinate::H3` — Uber's H3 Hexagonal Hierarchical Index (16 resolution levels, hexagonal cells via `libh3` C library through `fiddle`)
22
- - Full cross-system conversions for GEOREF, GARS, and H3 — all 18 coordinate systems convert to/from every other system (324 conversion paths)
23
- - Spatial hash features for GEOREF, GARS, and H3: `neighbors`, `to_area`, `precision_in_meters`, `to_slug`, configurable precision
18
+ - **`Geodetic::Feature` class** wraps any coordinate or area geometry with a `label` and `metadata` hash; delegates `distance_to` and `bearing_to` to the underlying geometry, using the centroid for area geometries
19
+ - **Map rendering example** (`examples/05_map_rendering/`)renders NYC landmarks on a raster map using [libgd-gis](https://rubygems.org/gems/libgd-gis), demonstrating Feature objects, polygon overlays, bearing arrows, icon compositing, and light/dark theme support
20
+ - `examples/README.md` describing all five example scripts
21
+ - Documentation: `docs/reference/feature.md` (Feature reference) and `docs/reference/map-rendering.md` (libgd-gis integration guide)
22
+
23
+ ### Changed
24
+
25
+ - Updated README, `docs/index.md`, and mkdocs nav to include Feature class and map rendering example
26
+
27
+ ## [0.3.0] - 2026-03-08
28
+
29
+ ### Added
30
+
31
+ - **H3 Hexagonal Hierarchical Index** (`Geodetic::Coordinate::H3`) — Uber's spatial indexing system, bringing total to 18 coordinate systems (324 conversion paths)
32
+ - H3 uses Ruby's `fiddle` to call the H3 v4 C API directly — no gem dependency beyond `fiddle`
24
33
  - H3-specific features: `grid_disk(k)`, `parent(res)`, `children(res)`, `pentagon?`, `cell_area`, `h3_index`, `resolution` (0-15)
25
34
  - H3 `to_area` returns `Areas::Polygon` (6 vertices for hexagons, 5 for pentagons) instead of `Areas::Rectangle`
26
35
  - H3 `neighbors` returns Array of 6 cells instead of directional Hash with 8 cardinal keys
27
36
  - Graceful degradation: H3 raises clear error with installation instructions if `libh3` is not found; all other coordinate systems work normally
28
- - Documentation pages: `docs/coordinate-systems/georef.md`, `docs/coordinate-systems/gars.md`, and `docs/coordinate-systems/h3.md`
37
+ - `H3.available?` class method to check for libh3 at runtime
38
+ - Documentation page: `docs/coordinate-systems/h3.md`
39
+
40
+ ### Changed
41
+
42
+ - Updated all documentation to reflect 18 coordinate systems (README, docs, gemspec, CLAUDE.md)
43
+
44
+ ## [0.2.0] - 2026-03-08
45
+
46
+ ### Added
47
+
48
+ - **2 new coordinate systems** bringing the total from 15 to 17:
49
+ - `Geodetic::Coordinate::GEOREF` — World Geographic Reference System (aviation/military geocode with variable precision from 15-degree tiles to 0.001-minute resolution)
50
+ - `Geodetic::Coordinate::GARS` — Global Area Reference System (NGA standard with 30-minute cells, 15-minute quadrants, and 5-minute keypads)
51
+ - Full cross-system conversions for GEOREF and GARS — all 17 coordinate systems convert to/from every other system (289 conversion paths)
52
+ - Spatial hash features for GEOREF and GARS: `neighbors`, `to_area`, `precision_in_meters`, `to_slug`, configurable precision
53
+ - Documentation pages: `docs/coordinate-systems/georef.md` and `docs/coordinate-systems/gars.md`
29
54
 
30
55
  ### Changed
31
56
 
data/README.md CHANGED
@@ -19,6 +19,7 @@
19
19
  - <strong>Bearing Calculations</strong> - Forward azimuth, back azimuth, compass directions, elevation angles<br>
20
20
  - <strong>Geoid Height Support</strong> - EGM96, EGM2008, GEOID18, GEOID12B models<br>
21
21
  - <strong>Geographic Areas</strong> - Circle, Polygon, and Rectangle with point-in-area tests<br>
22
+ - <strong>Features</strong> - Named geometry wrapper with metadata and delegated distance/bearing<br>
22
23
  - <strong>Validated Setters</strong> - Type coercion and range validation on all coordinate attributes<br>
23
24
  - <strong>Serialization</strong> - to_s(precision), to_a, from_string, from_array, DMS format<br>
24
25
  - <strong>Multiple Datums</strong> - WGS84, Clarke 1866, GRS 1980, Airy 1830, and more<br>
@@ -77,14 +78,29 @@ ned = Coordinates::NED.new(n: 200.0, e: 100.0, d: -50.0)
77
78
 
78
79
  ### GCS Shorthand
79
80
 
80
- `GCS` is a top-level alias for `Geodetic::Coordinate`, providing a concise way to create and work with coordinates:
81
+ For convenience, you can define a short alias in your application:
81
82
 
82
83
  ```ruby
83
84
  require "geodetic"
84
85
 
85
- # Use GCS as a shorthand for Geodetic::Coordinate
86
- seattle = GCS::LLA.new(lat: 47.6205, lng: -122.3493, alt: 184.0)
87
- ecef = GCS::ECEF.new(x: -2304643.57, y: -3638650.07, z: 4688674.43)
86
+ GCS = Geodetic::Coordinate
87
+
88
+ seattle = Geodetic::Coordinate::LLA.new(lat: 47.6205, lng: -122.3493, alt: 184.0)
89
+ ecef = Geodetic::Coordinate::ECEF.new(x: -2304643.57, y: -3638650.07, z: 4688674.43)
90
+ ```
91
+
92
+ ### Discovering Coordinate Systems
93
+
94
+ List all available coordinate systems at runtime:
95
+
96
+ ```ruby
97
+ Geodetic::Coordinate.systems
98
+ # => [Geodetic::Coordinate::LLA, Geodetic::Coordinate::ECEF, Geodetic::Coordinate::UTM, ...]
99
+
100
+ # Get short names
101
+ Geodetic::Coordinate.systems.map { |c| c.name.split('::').last }
102
+ # => ["LLA", "ECEF", "UTM", "ENU", "NED", "MGRS", "USNG", "WebMercator",
103
+ # "UPS", "StatePlane", "BNG", "GH36", "GH", "HAM", "OLC", "GEOREF", "GARS", "H3"]
88
104
  ```
89
105
 
90
106
  ### Coordinate Conversions
@@ -185,9 +201,9 @@ Universal distance methods work across all coordinate types and return `Distance
185
201
  **Instance method `distance_to`** — Vincenty great-circle distance:
186
202
 
187
203
  ```ruby
188
- seattle = GCS::LLA.new(lat: 47.6205, lng: -122.3493, alt: 0.0)
189
- portland = GCS::LLA.new(lat: 45.5152, lng: -122.6784, alt: 0.0)
190
- sf = GCS::LLA.new(lat: 37.7749, lng: -122.4194, alt: 0.0)
204
+ seattle = Geodetic::Coordinate::LLA.new(lat: 47.6205, lng: -122.3493, alt: 0.0)
205
+ portland = Geodetic::Coordinate::LLA.new(lat: 45.5152, lng: -122.6784, alt: 0.0)
206
+ sf = Geodetic::Coordinate::LLA.new(lat: 37.7749, lng: -122.4194, alt: 0.0)
191
207
 
192
208
  d = seattle.distance_to(portland) # => Distance (meters)
193
209
  d.meters # => 235393.17
@@ -201,23 +217,23 @@ seattle.distance_to([portland, sf]) # => [Distance, Distance] (radial)
201
217
  **Class method `distance_between`** — consecutive chain distances:
202
218
 
203
219
  ```ruby
204
- GCS.distance_between(seattle, portland) # => Distance
205
- GCS.distance_between(seattle, portland, sf) # => [Distance, Distance] (chain)
206
- GCS.distance_between([seattle, portland, sf]) # => [Distance, Distance] (chain)
220
+ Geodetic::Coordinate.distance_between(seattle, portland) # => Distance
221
+ Geodetic::Coordinate.distance_between(seattle, portland, sf) # => [Distance, Distance] (chain)
222
+ Geodetic::Coordinate.distance_between([seattle, portland, sf]) # => [Distance, Distance] (chain)
207
223
  ```
208
224
 
209
225
  **Straight-line (ECEF Euclidean) versions:**
210
226
 
211
227
  ```ruby
212
228
  seattle.straight_line_distance_to(portland) # => Distance
213
- GCS.straight_line_distance_between(seattle, portland) # => Distance
229
+ Geodetic::Coordinate.straight_line_distance_between(seattle, portland) # => Distance
214
230
  ```
215
231
 
216
232
  **Cross-system distances** — works between any coordinate types:
217
233
 
218
234
  ```ruby
219
235
  utm = seattle.to_utm
220
- mgrs = GCS::MGRS.from_lla(portland)
236
+ mgrs = Geodetic::Coordinate::MGRS.from_lla(portland)
221
237
  utm.distance_to(mgrs) # => Distance
222
238
  ```
223
239
 
@@ -230,8 +246,8 @@ Universal bearing methods work across all coordinate types and return `Bearing`
230
246
  **Instance method `bearing_to`** — great-circle forward azimuth:
231
247
 
232
248
  ```ruby
233
- seattle = GCS::LLA.new(lat: 47.6205, lng: -122.3493, alt: 0.0)
234
- portland = GCS::LLA.new(lat: 45.5152, lng: -122.6784, alt: 0.0)
249
+ seattle = Geodetic::Coordinate::LLA.new(lat: 47.6205, lng: -122.3493, alt: 0.0)
250
+ portland = Geodetic::Coordinate::LLA.new(lat: 45.5152, lng: -122.6784, alt: 0.0)
235
251
 
236
252
  b = seattle.bearing_to(portland) # => Bearing
237
253
  b.degrees # => 188.2
@@ -245,8 +261,8 @@ b.to_s # => "188.2036°"
245
261
  **Instance method `elevation_to`** — vertical look angle:
246
262
 
247
263
  ```ruby
248
- a = GCS::LLA.new(lat: 47.62, lng: -122.35, alt: 0.0)
249
- b = GCS::LLA.new(lat: 47.62, lng: -122.35, alt: 5000.0)
264
+ a = Geodetic::Coordinate::LLA.new(lat: 47.62, lng: -122.35, alt: 0.0)
265
+ b = Geodetic::Coordinate::LLA.new(lat: 47.62, lng: -122.35, alt: 5000.0)
250
266
 
251
267
  a.elevation_to(b) # => 89.9... (degrees, nearly straight up)
252
268
  ```
@@ -254,15 +270,15 @@ a.elevation_to(b) # => 89.9... (degrees, nearly straight up)
254
270
  **Class method `bearing_between`** — consecutive chain bearings:
255
271
 
256
272
  ```ruby
257
- GCS.bearing_between(seattle, portland) # => Bearing
258
- GCS.bearing_between(seattle, portland, sf) # => [Bearing, Bearing] (chain)
273
+ Geodetic::Coordinate.bearing_between(seattle, portland) # => Bearing
274
+ Geodetic::Coordinate.bearing_between(seattle, portland, sf) # => [Bearing, Bearing] (chain)
259
275
  ```
260
276
 
261
277
  **Cross-system bearings** — works between any coordinate types:
262
278
 
263
279
  ```ruby
264
280
  utm = seattle.to_utm
265
- mgrs = GCS::MGRS.from_lla(portland)
281
+ mgrs = Geodetic::Coordinate::MGRS.from_lla(portland)
266
282
  utm.bearing_to(mgrs) # => Bearing
267
283
  ```
268
284
 
@@ -405,9 +421,6 @@ gh36 = lla.to_gh36(precision: 8)
405
421
  # Decode back to LLA
406
422
  lla = gh36.to_lla
407
423
 
408
- # URL slug (the hash itself is URL-safe)
409
- gh36.to_slug # => "bdrdC26BqH"
410
-
411
424
  # Neighbor cells
412
425
  gh36.neighbors # => { N: GH36, S: GH36, E: GH36, W: GH36, NE: ..., NW: ..., SE: ..., SW: ... }
413
426
 
@@ -435,9 +448,6 @@ gh = lla.to_gh(precision: 8)
435
448
  # Decode back to LLA
436
449
  lla = gh.to_lla
437
450
 
438
- # URL slug (the hash itself is URL-safe)
439
- gh.to_slug # => "dr5ru7"
440
-
441
451
  # Neighbor cells
442
452
  gh.neighbors # => { N: GH, S: GH, E: GH, W: GH, NE: ..., NW: ..., SE: ..., SW: ... }
443
453
 
@@ -531,6 +541,36 @@ rect.sw # => computed SW corner
531
541
  rect.includes?(point) # => true/false
532
542
  ```
533
543
 
544
+ ### Features
545
+
546
+ `Feature` wraps a geometry (any coordinate or area) with a label and a metadata hash. It delegates `distance_to` and `bearing_to` to its geometry, using the centroid for area geometries.
547
+
548
+ ```ruby
549
+ liberty = Feature.new(
550
+ label: "Statue of Liberty",
551
+ geometry: Coordinates::LLA.new(lat: 40.6892, lng: -74.0445, alt: 0),
552
+ metadata: { category: "monument", year: 1886 }
553
+ )
554
+
555
+ empire = Feature.new(
556
+ label: "Empire State Building",
557
+ geometry: Coordinates::LLA.new(lat: 40.7484, lng: -73.9857, alt: 0),
558
+ metadata: { category: "building", floors: 102 }
559
+ )
560
+
561
+ liberty.distance_to(empire).to_km # => "8.24 km"
562
+ liberty.bearing_to(empire).degrees # => 36.99
563
+
564
+ # Area geometries use the centroid for distance/bearing
565
+ park = Feature.new(
566
+ label: "Central Park",
567
+ geometry: Areas::Polygon.new(boundary: [...])
568
+ )
569
+ park.distance_to(liberty).to_km # => "12.47 km"
570
+ ```
571
+
572
+ All three attributes (`label`, `geometry`, `metadata`) are mutable.
573
+
534
574
  ### Web Mercator Tile Coordinates
535
575
 
536
576
  ```ruby
@@ -559,6 +599,7 @@ The [`examples/`](examples/) directory contains runnable demo scripts showing pr
559
599
  | [`02_all_coordinate_systems.rb`](examples/02_all_coordinate_systems.rb) | All 18 coordinate systems, cross-system chains, and areas |
560
600
  | [`03_distance_calculations.rb`](examples/03_distance_calculations.rb) | Distance class features, unit conversions, and arithmetic |
561
601
  | [`04_bearing_calculations.rb`](examples/04_bearing_calculations.rb) | Bearing class, compass directions, elevation angles, and chain bearings |
602
+ | [`05_map_rendering/`](examples/05_map_rendering/) | Render landmarks on a raster map with Feature objects, polygon areas, bearing arrows, and icons using [libgd-gis](https://rubygems.org/gems/libgd-gis) |
562
603
 
563
604
  Run any example with:
564
605
 
@@ -141,10 +141,6 @@ coord.to_s(6) # => "006AG3"
141
141
  coord.to_s(5) # => "006AG"
142
142
  ```
143
143
 
144
- ### `to_slug`
145
-
146
- Alias for `to_s`. GARS codes are already URL-safe.
147
-
148
144
  ### `to_a`
149
145
 
150
146
  Returns `[lat, lng]` of the cell midpoint.
@@ -122,10 +122,6 @@ coord.to_s(4) # => "GJPJ"
122
122
  coord.to_s(2) # => "GJ"
123
123
  ```
124
124
 
125
- ### `to_slug`
126
-
127
- Alias for `to_s`. GEOREF codes are already URL-safe.
128
-
129
125
  ### `to_a`
130
126
 
131
127
  Returns `[lat, lng]` of the cell midpoint.
@@ -110,10 +110,6 @@ coord.to_s # => "dr5ru7c5g200"
110
110
  coord.to_s(6) # => "dr5ru7"
111
111
  ```
112
112
 
113
- ### `to_slug`
114
-
115
- Alias for `to_s`. The geohash is already URL-safe.
116
-
117
113
  ### `to_a`
118
114
 
119
115
  Returns `[lat, lng]` of the cell midpoint.
@@ -105,10 +105,6 @@ coord.to_s # => "bdrdC26BqH"
105
105
  coord.to_s(5) # => "bdrdC"
106
106
  ```
107
107
 
108
- ### `to_slug`
109
-
110
- Alias for `to_s`. The geohash is already URL-safe.
111
-
112
108
  ### `to_a`
113
109
 
114
110
  Returns `[lat, lng]` of the cell midpoint.
@@ -174,10 +174,6 @@ coord.to_s(:integer) # => 608693941536498687
174
174
  coord.h3_index # => 608693941536498687
175
175
  ```
176
176
 
177
- ### `to_slug`
178
-
179
- Alias for `to_s`. H3 hex strings are already URL-safe.
180
-
181
177
  ### `to_a`
182
178
 
183
179
  Returns `[lat, lng]` of the cell centroid.
@@ -118,10 +118,6 @@ coord.to_s(6) # => "FN31pr"
118
118
  coord.to_s(4) # => "FN31"
119
119
  ```
120
120
 
121
- ### `to_slug`
122
-
123
- Alias for `to_s`. The locator is already URL-safe.
124
-
125
121
  ### `to_a`
126
122
 
127
123
  Returns `[lat, lng]` of the cell midpoint.
@@ -84,9 +84,9 @@ Every coordinate system can convert to every other coordinate system. The table
84
84
 
85
85
  ## Universal Distance and Bearing Calculations
86
86
 
87
- All coordinate systems support universal distance calculations via `distance_to` (Vincenty great-circle) and `straight_line_distance_to` (ECEF Euclidean). These methods work across different coordinate types -- for example, computing the distance from a UTM coordinate to an MGRS coordinate. Class-level methods `GCS.distance_between` and `GCS.straight_line_distance_between` compute consecutive chain distances across a sequence of coordinates.
87
+ All coordinate systems support universal distance calculations via `distance_to` (Vincenty great-circle) and `straight_line_distance_to` (ECEF Euclidean). These methods work across different coordinate types -- for example, computing the distance from a UTM coordinate to an MGRS coordinate. Class-level methods `Geodetic::Coordinate.distance_between` and `Geodetic::Coordinate.straight_line_distance_between` compute consecutive chain distances across a sequence of coordinates.
88
88
 
89
- All coordinate systems also support universal bearing calculations via `bearing_to` (great-circle forward azimuth) and `elevation_to` (vertical look angle). These return `Bearing` and `Float` objects respectively. The class-level method `GCS.bearing_between` computes consecutive chain bearings.
89
+ All coordinate systems also support universal bearing calculations via `bearing_to` (great-circle forward azimuth) and `elevation_to` (vertical look angle). These return `Bearing` and `Float` objects respectively. The class-level method `Geodetic::Coordinate.bearing_between` computes consecutive chain bearings.
90
90
 
91
91
  See the [Conversions Reference](../reference/conversions.md#distance-calculations) for details on distances and [Bearing Calculations](../reference/conversions.md#bearing-calculations) for bearings.
92
92
 
@@ -123,10 +123,6 @@ coord.to_s(8) # => "849VCWC8+"
123
123
  coord.to_s(4) # => "84900000+"
124
124
  ```
125
125
 
126
- ### `to_slug`
127
-
128
- Alias for `to_s`. Plus codes are already URL-safe.
129
-
130
126
  ### `to_a`
131
127
 
132
128
  Returns `[lat, lng]` of the cell midpoint.
data/docs/index.md CHANGED
@@ -15,6 +15,7 @@
15
15
  <li><strong>Bearing Calculations</strong> - Forward azimuth, back azimuth, compass directions, elevation angles<br>
16
16
  <li><strong>Geoid Height Support</strong> - EGM96, EGM2008, GEOID18, GEOID12B models<br>
17
17
  <li><strong>Geographic Areas</strong> - Circle, Polygon, and Rectangle with point-in-area tests<br>
18
+ <li><strong>Features</strong> - Named geometry wrapper with metadata and delegated distance/bearing<br>
18
19
  <li><strong>Validated Setters</strong> - Type coercion and range validation on all coordinate attributes<br>
19
20
  <li><strong>Serialization</strong> - to_s(precision), to_a, from_string, from_array, DMS format<br>
20
21
  <li><strong>Multiple Datums</strong> - WGS84, Clarke 1866, GRS 1980, Airy 1830, and more<br>
@@ -56,12 +57,14 @@ Geodetic supports full bidirectional conversion between all 18 coordinate system
56
57
  - **16 geodetic datums** -- WGS84, GRS 1980, Clarke 1866, Airy 1830, Bessel 1841, and more. All conversion methods accept an optional datum parameter, defaulting to WGS84.
57
58
  - **Geoid height calculations** -- Convert between ellipsoidal and orthometric heights using models such as EGM96, EGM2008, GEOID18, and GEOID12B.
58
59
  - **Geographic areas** -- `Geodetic::Areas::Circle`, `Geodetic::Areas::Polygon`, and `Geodetic::Areas::Rectangle` for point-in-area testing.
60
+ - **Features** -- `Geodetic::Feature` wraps any coordinate or area with a label and metadata hash, delegating `distance_to` and `bearing_to` to the underlying geometry.
59
61
 
60
62
  ## Design Principles
61
63
 
62
64
  - All constructors use **keyword arguments** for clarity.
63
65
  - Every coordinate system supports **serialization** via `to_s` and `to_a`, and **deserialization** via `from_string` and `from_array`.
64
66
  - Conversions are available as instance methods (`to_ecef`, `to_utm`, etc.) and class-level factory methods (`from_ecef`, `from_utm`, etc.).
67
+ - All registered coordinate systems are discoverable at runtime via `Geodetic::Coordinate.systems`.
65
68
 
66
69
  ## Quick Example
67
70
 
@@ -240,31 +240,31 @@ Universal distance methods are available on all coordinate types and work across
240
240
  ### Great-Circle Distance (Vincenty)
241
241
 
242
242
  - **`distance_to(other, *others)`** — Instance method. Computes the Vincenty great-circle distance from the receiver to one or more target coordinates. Returns a `Distance` for a single target, or an Array of `Distance` objects for multiple targets (radial distances from the receiver).
243
- - **`GCS.distance_between(*coords)`** — Class method on `Geodetic::Coordinate` (aliased as `GCS`). Computes consecutive chain distances between an ordered sequence of coordinates. Returns a `Distance` for two coordinates, or an Array of `Distance` objects for three or more.
243
+ - **`Geodetic::Coordinate.distance_between(*coords)`** — Class method on `Geodetic::Coordinate`. Computes consecutive chain distances between an ordered sequence of coordinates. Returns a `Distance` for two coordinates, or an Array of `Distance` objects for three or more.
244
244
 
245
245
  > **`Distance` objects** wrap a distance value and provide unit-aware access. Call `.meters` to get the raw Float value in meters, or `.to_f` to get the value in the current display unit.
246
246
 
247
247
  ```ruby
248
- seattle = GCS::LLA.new(lat: 47.6205, lng: -122.3493, alt: 0.0)
249
- portland = GCS::LLA.new(lat: 45.5152, lng: -122.6784, alt: 0.0)
250
- sf = GCS::LLA.new(lat: 37.7749, lng: -122.4194, alt: 0.0)
248
+ seattle = Geodetic::Coordinate::LLA.new(lat: 47.6205, lng: -122.3493, alt: 0.0)
249
+ portland = Geodetic::Coordinate::LLA.new(lat: 45.5152, lng: -122.6784, alt: 0.0)
250
+ sf = Geodetic::Coordinate::LLA.new(lat: 37.7749, lng: -122.4194, alt: 0.0)
251
251
 
252
252
  # Radial distances from receiver
253
253
  seattle.distance_to(portland) # => Distance (235393.17 m)
254
254
  seattle.distance_to(portland, sf) # => [Distance, Distance] (Array)
255
255
 
256
256
  # Consecutive chain distances
257
- GCS.distance_between(seattle, portland, sf) # => [Distance, Distance] (Array)
257
+ Geodetic::Coordinate.distance_between(seattle, portland, sf) # => [Distance, Distance] (Array)
258
258
  ```
259
259
 
260
260
  ### Straight-Line Distance (ECEF Euclidean)
261
261
 
262
262
  - **`straight_line_distance_to(other, *others)`** — Instance method. Computes the Euclidean distance in ECEF (3D Cartesian) space. Returns a `Distance` for a single target, or an Array of `Distance` objects for multiple targets.
263
- - **`GCS.straight_line_distance_between(*coords)`** — Class method. Computes consecutive chain Euclidean distances.
263
+ - **`Geodetic::Coordinate.straight_line_distance_between(*coords)`** — Class method. Computes consecutive chain Euclidean distances.
264
264
 
265
265
  ```ruby
266
266
  seattle.straight_line_distance_to(portland) # => Distance
267
- GCS.straight_line_distance_between(seattle, portland) # => Distance
267
+ Geodetic::Coordinate.straight_line_distance_between(seattle, portland) # => Distance
268
268
  ```
269
269
 
270
270
  ### Cross-System Distances
@@ -273,7 +273,7 @@ Both `distance_to` and `straight_line_distance_to` accept any coordinate type. C
273
273
 
274
274
  ```ruby
275
275
  utm = seattle.to_utm
276
- mgrs = GCS::MGRS.from_lla(portland)
276
+ mgrs = Geodetic::Coordinate::MGRS.from_lla(portland)
277
277
  utm.distance_to(mgrs) # => Distance (235393.17 m)
278
278
  ```
279
279
 
@@ -282,7 +282,7 @@ utm.distance_to(mgrs) # => Distance (235393.17 m)
282
282
  ENU and NED are relative coordinate systems and do not support `distance_to` or `straight_line_distance_to` directly. Convert to an absolute system first:
283
283
 
284
284
  ```ruby
285
- ref = GCS::LLA.new(lat: 47.62, lng: -122.35, alt: 0.0)
285
+ ref = Geodetic::Coordinate::LLA.new(lat: 47.62, lng: -122.35, alt: 0.0)
286
286
  lla = enu.to_lla(ref)
287
287
  lla.distance_to(other_lla)
288
288
  ```
@@ -299,12 +299,12 @@ Universal bearing methods are available on all coordinate types and work across
299
299
 
300
300
  - **`bearing_to(other)`** — Instance method. Computes the great-circle forward azimuth from the receiver to the target coordinate. Returns a `Bearing` object.
301
301
  - **`elevation_to(other)`** — Instance method. Computes the vertical look angle (elevation) from the receiver to the target. Returns a Float in degrees (-90 to +90).
302
- - **`GCS.bearing_between(*coords)`** — Class method on `Geodetic::Coordinate` (aliased as `GCS`). Computes consecutive chain bearings between an ordered sequence of coordinates. Returns a `Bearing` for two coordinates, or an Array of `Bearing` objects for three or more.
302
+ - **`Geodetic::Coordinate.bearing_between(*coords)`** — Class method on `Geodetic::Coordinate`. Computes consecutive chain bearings between an ordered sequence of coordinates. Returns a `Bearing` for two coordinates, or an Array of `Bearing` objects for three or more.
303
303
 
304
304
  ```ruby
305
- seattle = GCS::LLA.new(lat: 47.6205, lng: -122.3493, alt: 0.0)
306
- portland = GCS::LLA.new(lat: 45.5152, lng: -122.6784, alt: 0.0)
307
- sf = GCS::LLA.new(lat: 37.7749, lng: -122.4194, alt: 0.0)
305
+ seattle = Geodetic::Coordinate::LLA.new(lat: 47.6205, lng: -122.3493, alt: 0.0)
306
+ portland = Geodetic::Coordinate::LLA.new(lat: 45.5152, lng: -122.6784, alt: 0.0)
307
+ sf = Geodetic::Coordinate::LLA.new(lat: 37.7749, lng: -122.4194, alt: 0.0)
308
308
 
309
309
  # Forward azimuth
310
310
  b = seattle.bearing_to(portland) # => Bearing
@@ -316,7 +316,7 @@ b.reverse # => Bearing (back azimuth)
316
316
  seattle.elevation_to(portland) # => Float (degrees)
317
317
 
318
318
  # Consecutive chain bearings
319
- GCS.bearing_between(seattle, portland, sf) # => [Bearing, Bearing]
319
+ Geodetic::Coordinate.bearing_between(seattle, portland, sf) # => [Bearing, Bearing]
320
320
  ```
321
321
 
322
322
  ### Cross-System Bearings
@@ -325,7 +325,7 @@ GCS.bearing_between(seattle, portland, sf) # => [Bearing, Bearing]
325
325
 
326
326
  ```ruby
327
327
  utm = seattle.to_utm
328
- mgrs = GCS::MGRS.from_lla(portland)
328
+ mgrs = Geodetic::Coordinate::MGRS.from_lla(portland)
329
329
  utm.bearing_to(mgrs) # => Bearing
330
330
  ```
331
331
 
@@ -0,0 +1,116 @@
1
+ # Feature Reference
2
+
3
+ `Geodetic::Feature` wraps a geometry with a human-readable label and an arbitrary metadata hash. It provides a single object that ties spatial data to application-level information like names, categories, and display properties.
4
+
5
+ ---
6
+
7
+ ## Constructor
8
+
9
+ ```ruby
10
+ Feature.new(
11
+ label: "Statue of Liberty",
12
+ geometry: Geodetic::Coordinate::LLA.new(lat: 40.6892, lng: -74.0445, alt: 0),
13
+ metadata: { category: "monument", year: 1886 }
14
+ )
15
+ ```
16
+
17
+ The `geometry` parameter accepts any coordinate class or any area class (`Circle`, `Polygon`, `Rectangle`). The `metadata` hash is optional and defaults to `{}`.
18
+
19
+ ---
20
+
21
+ ## Attributes
22
+
23
+ | Attribute | Type | Mutable | Description |
24
+ |------------|--------|---------|-------------|
25
+ | `label` | String | Yes | A display name for the feature |
26
+ | `geometry` | Object | Yes | A coordinate or area object |
27
+ | `metadata` | Hash | Yes | Arbitrary key-value pairs |
28
+
29
+ All three attributes have both reader and writer methods.
30
+
31
+ ---
32
+
33
+ ## Geometry Types
34
+
35
+ A Feature's geometry can be any of:
36
+
37
+ - **Coordinate** — any of the 18 coordinate classes (`LLA`, `ECEF`, `UTM`, etc.)
38
+ - **Area** — `Areas::Circle`, `Areas::Polygon`, or `Areas::Rectangle`
39
+
40
+ When the geometry is an area, `distance_to` and `bearing_to` use the area's `centroid` as the reference point.
41
+
42
+ ---
43
+
44
+ ## Methods
45
+
46
+ ### `distance_to(other)`
47
+
48
+ Returns a `Geodetic::Distance` between this feature and another feature, coordinate, or area. When either side is an area geometry, its centroid is used.
49
+
50
+ The `other` parameter can be a `Feature`, a coordinate, or an area.
51
+
52
+ ```ruby
53
+ liberty = Feature.new(label: "Liberty", geometry: LLA.new(lat: 40.6892, lng: -74.0445, alt: 0))
54
+ empire = Feature.new(label: "Empire", geometry: LLA.new(lat: 40.7484, lng: -73.9857, alt: 0))
55
+
56
+ liberty.distance_to(empire).to_km # => "8.24 km"
57
+
58
+ # Also works with a raw coordinate
59
+ liberty.distance_to(LLA.new(lat: 40.7484, lng: -73.9857, alt: 0))
60
+ ```
61
+
62
+ ### `bearing_to(other)`
63
+
64
+ Returns a `Geodetic::Bearing` from this feature to another feature, coordinate, or area. Uses the same centroid resolution as `distance_to`.
65
+
66
+ ```ruby
67
+ liberty.bearing_to(empire).degrees # => 36.99
68
+ liberty.bearing_to(empire).to_compass # => "NE"
69
+ ```
70
+
71
+ ### `to_s`
72
+
73
+ Returns `"label (geometry.to_s)"`.
74
+
75
+ ```ruby
76
+ liberty.to_s # => "Liberty (40.689200, -74.044500, 0.00)"
77
+ ```
78
+
79
+ ### `inspect`
80
+
81
+ Returns a detailed string with label, geometry, and metadata.
82
+
83
+ ```ruby
84
+ liberty.inspect
85
+ # => "#<Geodetic::Feature name=\"Liberty\" geometry=#<Geodetic::Coordinate::LLA ...> metadata={}>"
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Area Geometry Example
91
+
92
+ ```ruby
93
+ park_boundary = Areas::Polygon.new(boundary: [
94
+ LLA.new(lat: 40.7679, lng: -73.9818, alt: 0),
95
+ LLA.new(lat: 40.7649, lng: -73.9727, alt: 0),
96
+ LLA.new(lat: 40.8003, lng: -73.9494, alt: 0),
97
+ LLA.new(lat: 40.8008, lng: -73.9585, alt: 0),
98
+ ])
99
+
100
+ park = Feature.new(label: "Central Park", geometry: park_boundary)
101
+
102
+ # distance_to uses the polygon's centroid
103
+ park.distance_to(liberty) # => Distance
104
+ park.bearing_to(liberty) # => Bearing
105
+ ```
106
+
107
+ ---
108
+
109
+ ## Centroid Resolution
110
+
111
+ When computing distances and bearings, Feature resolves the underlying point as follows:
112
+
113
+ - If the geometry responds to `centroid` (all area classes do), the centroid is used.
114
+ - Otherwise, the geometry itself is used directly (all coordinate classes).
115
+
116
+ This applies to both the source feature and the target. When the target is a Feature, its geometry is resolved the same way. When the target is a raw coordinate or area, the same logic applies.
@@ -0,0 +1,32 @@
1
+ # Map Rendering with libgd-gis
2
+
3
+ Geodetic coordinates and areas can be rendered on raster maps using the [libgd-gis](https://rubygems.org/gems/libgd-gis) gem, which provides tile-based basemap rendering on top of [ruby-libgd](https://rubygems.org/gems/ruby-libgd).
4
+
5
+ ## Overview
6
+
7
+ The `libgd-gis` gem downloads map tiles and stitches them into a single raster image for a given bounding box and zoom level. Geodetic's coordinate objects provide the geographic data, and `GD::GIS::Geometry.project` converts longitude/latitude pairs into pixel positions on the rendered map. From there, ruby-libgd primitives (lines, circles, polygons, text, image compositing) can draw overlays on top of the basemap.
8
+
9
+ This combination supports:
10
+
11
+ - **Point markers** for any Geodetic coordinate
12
+ - **Polygon overlays** from `Geodetic::Areas::Polygon` boundaries
13
+ - **Bearing arrows** computed with `Feature#bearing_to` and drawn as lines with arrowheads
14
+ - **Distance labels** using `Feature#distance_to` for annotation
15
+ - **Icon compositing** with scaled PNG images positioned at projected coordinates
16
+ - **Light and dark basemaps** via `:carto_light` and `:carto_dark`
17
+
18
+ ## Feature Class
19
+
20
+ `Geodetic::Feature` wraps a geometry (any coordinate or area) with a label and a metadata hash. It delegates `distance_to` and `bearing_to` to its geometry, using the centroid for area geometries. This makes it straightforward to attach display properties like icon paths and categories alongside the spatial data.
21
+
22
+ ## Prerequisites
23
+
24
+ ```bash
25
+ gem install libgd-gis
26
+ brew install gd # macOS
27
+ # apt install libgd-dev # Linux
28
+ ```
29
+
30
+ ## Example
31
+
32
+ See [`examples/05_map_rendering/demo.rb`](https://github.com/madbomber/geodetic/tree/main/examples/05_map_rendering) for a complete working demo that renders NYC landmarks with icons, a Central Park polygon boundary, and bearing arrows between landmarks. The demo supports light/dark themes, icon scaling, and CLI flags for toggling features.
@@ -254,7 +254,7 @@ restored = Geodetic::Coordinate::LLA.from_dms(dms_string)
254
254
  | StatePlane | `easting, northing, zone_code` | 2 | `[easting, northing, zone_code]` | -- |
255
255
  | MGRS | `grid_zone+square+coords` | n/a | `[grid_zone, square_id, easting, northing, precision]` | String-based |
256
256
  | USNG | `grid_zone square coords` | n/a | `[grid_zone, square_id, easting, northing, precision]` | `to_full_format`, `to_abbreviated_format` |
257
- | GH36 | geohash string | n/a | `[lat, lng]` | `to_slug`, `to_area`, `neighbors` |
258
- | GH | geohash string | n/a | `[lat, lng]` | `to_slug`, `to_area`, `neighbors` |
259
- | HAM | locator string | n/a | `[lat, lng]` | `to_slug`, `to_area`, `neighbors` |
260
- | OLC | plus code string | n/a | `[lat, lng]` | `to_slug`, `to_area`, `neighbors` |
257
+ | GH36 | geohash string | n/a | `[lat, lng]` | `to_area`, `neighbors` |
258
+ | GH | geohash string | n/a | `[lat, lng]` | `to_area`, `neighbors` |
259
+ | HAM | locator string | n/a | `[lat, lng]` | `to_area`, `neighbors` |
260
+ | OLC | plus code string | n/a | `[lat, lng]` | `to_area`, `neighbors` |
@@ -161,9 +161,6 @@ def demo_coordinate_systems
161
161
  puts " Precision: #{gh36_coord.precision} chars"
162
162
  puts " Precision in meters: lat=#{gh36_coord.precision_in_meters[:lat].round(3)}m, lng=#{gh36_coord.precision_in_meters[:lng].round(3)}m"
163
163
 
164
- # URL slug
165
- puts " URL slug: #{gh36_coord.to_slug}"
166
-
167
164
  # Reduced precision
168
165
  gh36_short = GH36.new(lla_coord, precision: 5)
169
166
  puts " 5-char precision: #{gh36_short.to_s}"
@@ -6,6 +6,7 @@
6
6
 
7
7
  require_relative "../lib/geodetic"
8
8
 
9
+ GCS = Geodetic::Coordinate
9
10
  Distance = Geodetic::Distance
10
11
 
11
12
  # ── Notable locations ────────────────────────────────────────────