geodetic 0.5.0 → 0.5.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +62 -3
- data/README.md +95 -48
- data/docs/coordinate-systems/index.md +18 -18
- data/docs/index.md +49 -27
- data/docs/reference/arithmetic.md +1 -1
- data/docs/reference/conversions.md +3 -3
- data/docs/reference/feature.md +1 -1
- data/docs/reference/geojson.md +388 -0
- data/examples/09_geojson_export.rb +255 -0
- data/examples/README.md +14 -0
- data/examples/geodetic_demo.geojson +305 -0
- data/lib/geodetic/areas/regular_polygon.rb +1 -21
- data/lib/geodetic/coordinate/bng.rb +26 -26
- data/lib/geodetic/coordinate/ecef.rb +12 -12
- data/lib/geodetic/coordinate/enu.rb +26 -26
- data/lib/geodetic/coordinate/lla.rb +16 -16
- data/lib/geodetic/coordinate/mgrs.rb +26 -26
- data/lib/geodetic/coordinate/ned.rb +26 -26
- data/lib/geodetic/coordinate/spatial_hash.rb +22 -22
- data/lib/geodetic/coordinate/state_plane.rb +42 -42
- data/lib/geodetic/coordinate/ups.rb +21 -21
- data/lib/geodetic/coordinate/usng.rb +25 -25
- data/lib/geodetic/coordinate/utm.rb +12 -12
- data/lib/geodetic/coordinate/web_mercator.rb +21 -21
- data/lib/geodetic/coordinate.rb +3 -2
- data/lib/geodetic/geojson.rb +303 -0
- data/lib/geodetic/path.rb +12 -15
- data/lib/geodetic/segment.rb +2 -18
- data/lib/geodetic/version.rb +1 -1
- data/lib/geodetic.rb +5 -4
- data/mkdocs.yml +10 -0
- metadata +5 -1
|
@@ -132,9 +132,9 @@ module Geodetic
|
|
|
132
132
|
LLA.new(lat: lat, lng: lng, alt: 0.0)
|
|
133
133
|
end
|
|
134
134
|
|
|
135
|
-
def self.from_lla(
|
|
136
|
-
lat =
|
|
137
|
-
lng =
|
|
135
|
+
def self.from_lla(lla, datum = WGS84)
|
|
136
|
+
lat = lla.lat
|
|
137
|
+
lng = lla.lng
|
|
138
138
|
|
|
139
139
|
# Determine hemisphere and zone
|
|
140
140
|
hemisphere = lat >= 0 ? 'N' : 'S'
|
|
@@ -183,8 +183,8 @@ module Geodetic
|
|
|
183
183
|
to_lla(datum).to_ecef(datum)
|
|
184
184
|
end
|
|
185
185
|
|
|
186
|
-
def self.from_ecef(
|
|
187
|
-
lla_coord =
|
|
186
|
+
def self.from_ecef(ecef, datum = WGS84)
|
|
187
|
+
lla_coord = ecef.to_lla(datum)
|
|
188
188
|
from_lla(lla_coord, datum)
|
|
189
189
|
end
|
|
190
190
|
|
|
@@ -192,8 +192,8 @@ module Geodetic
|
|
|
192
192
|
to_lla(datum).to_utm(datum)
|
|
193
193
|
end
|
|
194
194
|
|
|
195
|
-
def self.from_utm(
|
|
196
|
-
lla_coord =
|
|
195
|
+
def self.from_utm(utm, datum = WGS84)
|
|
196
|
+
lla_coord = utm.to_lla(datum)
|
|
197
197
|
from_lla(lla_coord, datum)
|
|
198
198
|
end
|
|
199
199
|
|
|
@@ -201,8 +201,8 @@ module Geodetic
|
|
|
201
201
|
to_lla(datum).to_enu(reference_lla)
|
|
202
202
|
end
|
|
203
203
|
|
|
204
|
-
def self.from_enu(
|
|
205
|
-
lla_coord =
|
|
204
|
+
def self.from_enu(enu, reference_lla, datum = WGS84)
|
|
205
|
+
lla_coord = enu.to_lla(reference_lla)
|
|
206
206
|
from_lla(lla_coord, datum)
|
|
207
207
|
end
|
|
208
208
|
|
|
@@ -210,8 +210,8 @@ module Geodetic
|
|
|
210
210
|
to_lla(datum).to_ned(reference_lla)
|
|
211
211
|
end
|
|
212
212
|
|
|
213
|
-
def self.from_ned(
|
|
214
|
-
lla_coord =
|
|
213
|
+
def self.from_ned(ned, reference_lla, datum = WGS84)
|
|
214
|
+
lla_coord = ned.to_lla(reference_lla)
|
|
215
215
|
from_lla(lla_coord, datum)
|
|
216
216
|
end
|
|
217
217
|
|
|
@@ -219,8 +219,8 @@ module Geodetic
|
|
|
219
219
|
MGRS.from_lla(to_lla(datum), datum, precision)
|
|
220
220
|
end
|
|
221
221
|
|
|
222
|
-
def self.from_mgrs(
|
|
223
|
-
lla_coord =
|
|
222
|
+
def self.from_mgrs(mgrs, datum = WGS84)
|
|
223
|
+
lla_coord = mgrs.to_lla(datum)
|
|
224
224
|
from_lla(lla_coord, datum)
|
|
225
225
|
end
|
|
226
226
|
|
|
@@ -228,8 +228,8 @@ module Geodetic
|
|
|
228
228
|
WebMercator.from_lla(to_lla(datum), datum)
|
|
229
229
|
end
|
|
230
230
|
|
|
231
|
-
def self.from_web_mercator(
|
|
232
|
-
lla_coord =
|
|
231
|
+
def self.from_web_mercator(web_mercator, datum = WGS84)
|
|
232
|
+
lla_coord = web_mercator.to_lla(datum)
|
|
233
233
|
from_lla(lla_coord, datum)
|
|
234
234
|
end
|
|
235
235
|
|
|
@@ -237,8 +237,8 @@ module Geodetic
|
|
|
237
237
|
USNG.from_lla(to_lla(datum), datum, precision)
|
|
238
238
|
end
|
|
239
239
|
|
|
240
|
-
def self.from_usng(
|
|
241
|
-
lla_coord =
|
|
240
|
+
def self.from_usng(usng, datum = WGS84)
|
|
241
|
+
lla_coord = usng.to_lla(datum)
|
|
242
242
|
from_lla(lla_coord, datum)
|
|
243
243
|
end
|
|
244
244
|
|
|
@@ -246,8 +246,8 @@ module Geodetic
|
|
|
246
246
|
BNG.from_lla(to_lla(datum), datum)
|
|
247
247
|
end
|
|
248
248
|
|
|
249
|
-
def self.from_bng(
|
|
250
|
-
lla_coord =
|
|
249
|
+
def self.from_bng(bng, datum = WGS84)
|
|
250
|
+
lla_coord = bng.to_lla(datum)
|
|
251
251
|
from_lla(lla_coord, datum)
|
|
252
252
|
end
|
|
253
253
|
|
|
@@ -255,8 +255,8 @@ module Geodetic
|
|
|
255
255
|
StatePlane.from_lla(to_lla(datum), zone_code, datum)
|
|
256
256
|
end
|
|
257
257
|
|
|
258
|
-
def self.from_state_plane(
|
|
259
|
-
lla_coord =
|
|
258
|
+
def self.from_state_plane(state_plane, datum = WGS84)
|
|
259
|
+
lla_coord = state_plane.to_lla(datum)
|
|
260
260
|
from_lla(lla_coord, datum)
|
|
261
261
|
end
|
|
262
262
|
|
|
@@ -49,13 +49,13 @@ module Geodetic
|
|
|
49
49
|
MGRS.new(mgrs_string: mgrs_string)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
-
def self.from_mgrs(
|
|
52
|
+
def self.from_mgrs(mgrs)
|
|
53
53
|
# Extract components from MGRS
|
|
54
|
-
grid_zone =
|
|
55
|
-
square_id =
|
|
56
|
-
easting =
|
|
57
|
-
northing =
|
|
58
|
-
precision =
|
|
54
|
+
grid_zone = mgrs.grid_zone_designator
|
|
55
|
+
square_id = mgrs.square_identifier
|
|
56
|
+
easting = mgrs.easting
|
|
57
|
+
northing = mgrs.northing
|
|
58
|
+
precision = mgrs.precision
|
|
59
59
|
|
|
60
60
|
new(grid_zone: grid_zone, square_id: square_id, easting: easting, northing: northing, precision: precision)
|
|
61
61
|
end
|
|
@@ -64,8 +64,8 @@ module Geodetic
|
|
|
64
64
|
to_mgrs.to_utm
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
def self.from_utm(
|
|
68
|
-
mgrs_coord = MGRS.from_utm(
|
|
67
|
+
def self.from_utm(utm, precision = 5)
|
|
68
|
+
mgrs_coord = MGRS.from_utm(utm, precision)
|
|
69
69
|
from_mgrs(mgrs_coord)
|
|
70
70
|
end
|
|
71
71
|
|
|
@@ -73,8 +73,8 @@ module Geodetic
|
|
|
73
73
|
to_mgrs.to_lla(datum)
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
-
def self.from_lla(
|
|
77
|
-
mgrs_coord = MGRS.from_lla(
|
|
76
|
+
def self.from_lla(lla, datum = WGS84, precision = 5)
|
|
77
|
+
mgrs_coord = MGRS.from_lla(lla, datum, precision)
|
|
78
78
|
from_mgrs(mgrs_coord)
|
|
79
79
|
end
|
|
80
80
|
|
|
@@ -82,8 +82,8 @@ module Geodetic
|
|
|
82
82
|
to_lla(datum).to_ecef(datum)
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
-
def self.from_ecef(
|
|
86
|
-
lla_coord =
|
|
85
|
+
def self.from_ecef(ecef, datum = WGS84, precision = 5)
|
|
86
|
+
lla_coord = ecef.to_lla(datum)
|
|
87
87
|
from_lla(lla_coord, datum, precision)
|
|
88
88
|
end
|
|
89
89
|
|
|
@@ -91,8 +91,8 @@ module Geodetic
|
|
|
91
91
|
to_lla(datum).to_enu(reference_lla)
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
-
def self.from_enu(
|
|
95
|
-
lla_coord =
|
|
94
|
+
def self.from_enu(enu, reference_lla, datum = WGS84, precision = 5)
|
|
95
|
+
lla_coord = enu.to_lla(reference_lla)
|
|
96
96
|
from_lla(lla_coord, datum, precision)
|
|
97
97
|
end
|
|
98
98
|
|
|
@@ -100,8 +100,8 @@ module Geodetic
|
|
|
100
100
|
to_lla(datum).to_ned(reference_lla)
|
|
101
101
|
end
|
|
102
102
|
|
|
103
|
-
def self.from_ned(
|
|
104
|
-
lla_coord =
|
|
103
|
+
def self.from_ned(ned, reference_lla, datum = WGS84, precision = 5)
|
|
104
|
+
lla_coord = ned.to_lla(reference_lla)
|
|
105
105
|
from_lla(lla_coord, datum, precision)
|
|
106
106
|
end
|
|
107
107
|
|
|
@@ -109,8 +109,8 @@ module Geodetic
|
|
|
109
109
|
UPS.from_lla(to_lla(datum), datum)
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
-
def self.from_ups(
|
|
113
|
-
lla_coord =
|
|
112
|
+
def self.from_ups(ups, datum = WGS84, precision = 5)
|
|
113
|
+
lla_coord = ups.to_lla(datum)
|
|
114
114
|
from_lla(lla_coord, datum, precision)
|
|
115
115
|
end
|
|
116
116
|
|
|
@@ -118,8 +118,8 @@ module Geodetic
|
|
|
118
118
|
WebMercator.from_lla(to_lla(datum), datum)
|
|
119
119
|
end
|
|
120
120
|
|
|
121
|
-
def self.from_web_mercator(
|
|
122
|
-
lla_coord =
|
|
121
|
+
def self.from_web_mercator(web_mercator, datum = WGS84, precision = 5)
|
|
122
|
+
lla_coord = web_mercator.to_lla(datum)
|
|
123
123
|
from_lla(lla_coord, datum, precision)
|
|
124
124
|
end
|
|
125
125
|
|
|
@@ -127,16 +127,16 @@ module Geodetic
|
|
|
127
127
|
BNG.from_lla(to_lla(datum), datum)
|
|
128
128
|
end
|
|
129
129
|
|
|
130
|
-
def self.from_bng(
|
|
131
|
-
from_lla(
|
|
130
|
+
def self.from_bng(bng, datum = WGS84, precision = 5)
|
|
131
|
+
from_lla(bng.to_lla(datum), datum, precision)
|
|
132
132
|
end
|
|
133
133
|
|
|
134
134
|
def to_state_plane(zone_code, datum = WGS84)
|
|
135
135
|
StatePlane.from_lla(to_lla(datum), zone_code, datum)
|
|
136
136
|
end
|
|
137
137
|
|
|
138
|
-
def self.from_state_plane(
|
|
139
|
-
from_lla(
|
|
138
|
+
def self.from_state_plane(state_plane, datum = WGS84, precision = 5)
|
|
139
|
+
from_lla(state_plane.to_lla(datum), datum, precision)
|
|
140
140
|
end
|
|
141
141
|
|
|
142
142
|
def ==(other)
|
|
@@ -196,7 +196,7 @@ module Geodetic
|
|
|
196
196
|
adjacent_usng = USNG.new(grid_zone: @grid_zone_designator, square_id: @square_identifier,
|
|
197
197
|
easting: new_east, northing: new_north, precision: @precision)
|
|
198
198
|
squares[direction] = adjacent_usng
|
|
199
|
-
rescue
|
|
199
|
+
rescue ArgumentError
|
|
200
200
|
# Skip invalid adjacent squares (e.g., crossing zone boundaries)
|
|
201
201
|
squares[direction] = nil
|
|
202
202
|
end
|
|
@@ -152,48 +152,48 @@ module Geodetic
|
|
|
152
152
|
MGRS.from_utm(self, precision)
|
|
153
153
|
end
|
|
154
154
|
|
|
155
|
-
def self.from_mgrs(
|
|
156
|
-
|
|
155
|
+
def self.from_mgrs(mgrs, datum = WGS84)
|
|
156
|
+
mgrs.to_utm
|
|
157
157
|
end
|
|
158
158
|
|
|
159
159
|
def to_usng(datum = WGS84, precision = 5)
|
|
160
160
|
USNG.from_utm(self, precision)
|
|
161
161
|
end
|
|
162
162
|
|
|
163
|
-
def self.from_usng(
|
|
164
|
-
|
|
163
|
+
def self.from_usng(usng, datum = WGS84)
|
|
164
|
+
usng.to_utm
|
|
165
165
|
end
|
|
166
166
|
|
|
167
167
|
def to_web_mercator(datum = WGS84)
|
|
168
168
|
WebMercator.from_lla(to_lla(datum), datum)
|
|
169
169
|
end
|
|
170
170
|
|
|
171
|
-
def self.from_web_mercator(
|
|
172
|
-
from_lla(
|
|
171
|
+
def self.from_web_mercator(web_mercator, datum = WGS84)
|
|
172
|
+
from_lla(web_mercator.to_lla(datum), datum)
|
|
173
173
|
end
|
|
174
174
|
|
|
175
175
|
def to_ups(datum = WGS84)
|
|
176
176
|
UPS.from_lla(to_lla(datum), datum)
|
|
177
177
|
end
|
|
178
178
|
|
|
179
|
-
def self.from_ups(
|
|
180
|
-
from_lla(
|
|
179
|
+
def self.from_ups(ups, datum = WGS84)
|
|
180
|
+
from_lla(ups.to_lla(datum), datum)
|
|
181
181
|
end
|
|
182
182
|
|
|
183
183
|
def to_state_plane(zone_code, datum = WGS84)
|
|
184
184
|
StatePlane.from_lla(to_lla(datum), zone_code, datum)
|
|
185
185
|
end
|
|
186
186
|
|
|
187
|
-
def self.from_state_plane(
|
|
188
|
-
from_lla(
|
|
187
|
+
def self.from_state_plane(state_plane, datum = WGS84)
|
|
188
|
+
from_lla(state_plane.to_lla(datum), datum)
|
|
189
189
|
end
|
|
190
190
|
|
|
191
191
|
def to_bng(datum = WGS84)
|
|
192
192
|
BNG.from_lla(to_lla(datum))
|
|
193
193
|
end
|
|
194
194
|
|
|
195
|
-
def self.from_bng(
|
|
196
|
-
from_lla(
|
|
195
|
+
def self.from_bng(bng, datum = WGS84)
|
|
196
|
+
from_lla(bng.to_lla, datum)
|
|
197
197
|
end
|
|
198
198
|
|
|
199
199
|
def to_s(precision = 2)
|
|
@@ -62,9 +62,9 @@ module Geodetic
|
|
|
62
62
|
LLA.new(lat: lat, lng: lng, alt: 0.0)
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
def self.from_lla(
|
|
66
|
-
lat =
|
|
67
|
-
lng =
|
|
65
|
+
def self.from_lla(lla, datum = WGS84)
|
|
66
|
+
lat = lla.lat
|
|
67
|
+
lng = lla.lng
|
|
68
68
|
|
|
69
69
|
# Clamp latitude to Web Mercator limits
|
|
70
70
|
lat = [[-MAX_LATITUDE, lat].max, MAX_LATITUDE].min
|
|
@@ -80,8 +80,8 @@ module Geodetic
|
|
|
80
80
|
to_lla(datum).to_ecef(datum)
|
|
81
81
|
end
|
|
82
82
|
|
|
83
|
-
def self.from_ecef(
|
|
84
|
-
lla_coord =
|
|
83
|
+
def self.from_ecef(ecef, datum = WGS84)
|
|
84
|
+
lla_coord = ecef.to_lla(datum)
|
|
85
85
|
from_lla(lla_coord, datum)
|
|
86
86
|
end
|
|
87
87
|
|
|
@@ -89,8 +89,8 @@ module Geodetic
|
|
|
89
89
|
to_lla(datum).to_utm(datum)
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
-
def self.from_utm(
|
|
93
|
-
lla_coord =
|
|
92
|
+
def self.from_utm(utm, datum = WGS84)
|
|
93
|
+
lla_coord = utm.to_lla(datum)
|
|
94
94
|
from_lla(lla_coord, datum)
|
|
95
95
|
end
|
|
96
96
|
|
|
@@ -98,8 +98,8 @@ module Geodetic
|
|
|
98
98
|
to_lla(datum).to_enu(reference_lla)
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
-
def self.from_enu(
|
|
102
|
-
lla_coord =
|
|
101
|
+
def self.from_enu(enu, reference_lla, datum = WGS84)
|
|
102
|
+
lla_coord = enu.to_lla(reference_lla)
|
|
103
103
|
from_lla(lla_coord, datum)
|
|
104
104
|
end
|
|
105
105
|
|
|
@@ -107,8 +107,8 @@ module Geodetic
|
|
|
107
107
|
to_lla(datum).to_ned(reference_lla)
|
|
108
108
|
end
|
|
109
109
|
|
|
110
|
-
def self.from_ned(
|
|
111
|
-
lla_coord =
|
|
110
|
+
def self.from_ned(ned, reference_lla, datum = WGS84)
|
|
111
|
+
lla_coord = ned.to_lla(reference_lla)
|
|
112
112
|
from_lla(lla_coord, datum)
|
|
113
113
|
end
|
|
114
114
|
|
|
@@ -116,8 +116,8 @@ module Geodetic
|
|
|
116
116
|
MGRS.from_lla(to_lla(datum), datum, precision)
|
|
117
117
|
end
|
|
118
118
|
|
|
119
|
-
def self.from_mgrs(
|
|
120
|
-
lla_coord =
|
|
119
|
+
def self.from_mgrs(mgrs, datum = WGS84)
|
|
120
|
+
lla_coord = mgrs.to_lla(datum)
|
|
121
121
|
from_lla(lla_coord, datum)
|
|
122
122
|
end
|
|
123
123
|
|
|
@@ -125,32 +125,32 @@ module Geodetic
|
|
|
125
125
|
USNG.from_lla(to_lla(datum), datum, precision)
|
|
126
126
|
end
|
|
127
127
|
|
|
128
|
-
def self.from_usng(
|
|
129
|
-
from_lla(
|
|
128
|
+
def self.from_usng(usng, datum = WGS84)
|
|
129
|
+
from_lla(usng.to_lla(datum), datum)
|
|
130
130
|
end
|
|
131
131
|
|
|
132
132
|
def to_ups(datum = WGS84)
|
|
133
133
|
UPS.from_lla(to_lla(datum), datum)
|
|
134
134
|
end
|
|
135
135
|
|
|
136
|
-
def self.from_ups(
|
|
137
|
-
from_lla(
|
|
136
|
+
def self.from_ups(ups, datum = WGS84)
|
|
137
|
+
from_lla(ups.to_lla(datum), datum)
|
|
138
138
|
end
|
|
139
139
|
|
|
140
140
|
def to_state_plane(zone_code, datum = WGS84)
|
|
141
141
|
StatePlane.from_lla(to_lla(datum), zone_code, datum)
|
|
142
142
|
end
|
|
143
143
|
|
|
144
|
-
def self.from_state_plane(
|
|
145
|
-
from_lla(
|
|
144
|
+
def self.from_state_plane(state_plane, datum = WGS84)
|
|
145
|
+
from_lla(state_plane.to_lla(datum), datum)
|
|
146
146
|
end
|
|
147
147
|
|
|
148
148
|
def to_bng(datum = WGS84)
|
|
149
149
|
BNG.from_lla(to_lla(datum))
|
|
150
150
|
end
|
|
151
151
|
|
|
152
|
-
def self.from_bng(
|
|
153
|
-
from_lla(
|
|
152
|
+
def self.from_bng(bng, datum = WGS84)
|
|
153
|
+
from_lla(bng.to_lla, datum)
|
|
154
154
|
end
|
|
155
155
|
|
|
156
156
|
# Tile coordinate methods for web mapping
|
data/lib/geodetic/coordinate.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Geodetic
|
|
|
11
11
|
attr_reader :registered_classes
|
|
12
12
|
|
|
13
13
|
def systems
|
|
14
|
-
@registered_classes.map(&:first).freeze
|
|
14
|
+
@systems_cache ||= @registered_classes.map(&:first).freeze
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def register_class(klass, hash_conversion_style: nil)
|
|
@@ -19,8 +19,9 @@ module Geodetic
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def finalize!
|
|
22
|
-
|
|
22
|
+
return if @finalized
|
|
23
23
|
@finalized = true
|
|
24
|
+
@systems_cache = nil
|
|
24
25
|
|
|
25
26
|
# Phase 1: Generate cross-hash conversion methods between spatial hash subclasses
|
|
26
27
|
SpatialHash.finalize_cross_hash_conversions!
|