silva 0.0.7 → 0.0.8
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.
- data/lib/silva/transform.rb +18 -19
- data/lib/silva/version.rb +1 -1
- metadata +2 -2
data/lib/silva/transform.rb
CHANGED
@@ -133,26 +133,24 @@ module Silva
|
|
133
133
|
# Portions of code from:
|
134
134
|
# http://www.harrywood.co.uk/blog/2010/06/29/ruby-code-for-converting-to-uk-ordnance-survey-coordinate-systems-from-wgs84/
|
135
135
|
|
136
|
-
def self.helmert_transform(
|
137
|
-
phi = to_rad(
|
138
|
-
lambda = to_rad(
|
139
|
-
|
136
|
+
def self.helmert_transform(source_system, target_system, ellipsoid_1, transform, ellipsoid_2)
|
137
|
+
phi = to_rad(source_system.lat)
|
138
|
+
lambda = to_rad(source_system.long)
|
139
|
+
h = source_system.alt
|
140
140
|
|
141
141
|
a1 = ellipsoid_1[:a]
|
142
142
|
b1 = ellipsoid_1[:b]
|
143
143
|
|
144
|
-
|
145
|
-
|
146
|
-
sin_lambda = Math.sin(lambda)
|
147
|
-
cos_lambda = Math.cos(lambda)
|
148
|
-
|
144
|
+
# convert co-ordinates to 3D Cartesian. See:
|
145
|
+
# http://www.ordnancesurvey.co.uk/oswebsite/gps/docs/A_Guide_to_Coordinate_Systems_in_Great_Britain.pdf
|
149
146
|
e_sq1 = eccentricity_squared(ellipsoid_1)
|
150
|
-
nu = a1 / Math.sqrt(1 - e_sq1 *
|
147
|
+
nu = a1 / Math.sqrt(1 - e_sq1 * Math.sin(phi)**2)
|
151
148
|
|
152
|
-
x1 = (nu +
|
153
|
-
y1 = (nu +
|
154
|
-
z1 = ((1 - e_sq1) * nu +
|
149
|
+
x1 = (nu + h) * Math.cos(phi) * Math.cos(lambda)
|
150
|
+
y1 = (nu + h) * Math.cos(phi) * Math.sin(lambda)
|
151
|
+
z1 = ((1 - e_sq1) * nu + h) * Math.sin(phi)
|
155
152
|
|
153
|
+
# apply Helmert transformation
|
156
154
|
tx = transform[:tx]
|
157
155
|
ty = transform[:ty]
|
158
156
|
tz = transform[:tz]
|
@@ -165,18 +163,19 @@ module Silva
|
|
165
163
|
y2 = ty + x1 * rz + y1 * s1 - z1 * rx
|
166
164
|
z2 = tz - x1 * ry + y1 * rx + z1 * s1
|
167
165
|
|
166
|
+
# convert 3D Cartesian co-ordinates back to lat, long, alt
|
168
167
|
a2 = ellipsoid_2[:a]
|
169
168
|
b2 = ellipsoid_2[:b]
|
170
169
|
precision = 4 / a2
|
171
170
|
|
172
171
|
e_sq2 = eccentricity_squared(ellipsoid_2)
|
173
|
-
p = Math.sqrt(x2
|
172
|
+
p = Math.sqrt(x2**2 + y2**2)
|
174
173
|
phi = Math.atan2(z2, p * (1 - e_sq2))
|
175
|
-
|
174
|
+
phi_prime = 2 * Math::PI
|
176
175
|
|
177
|
-
while ((phi -
|
176
|
+
while ((phi - phi_prime).abs > precision) do
|
178
177
|
nu = a2 / Math.sqrt(1 - e_sq2 * Math.sin(phi)**2)
|
179
|
-
|
178
|
+
phi_prime = phi
|
180
179
|
phi = Math.atan2(z2 + e_sq2 * nu * Math.sin(phi), p)
|
181
180
|
end
|
182
181
|
|
@@ -195,7 +194,7 @@ module Silva
|
|
195
194
|
# Calculate M (meridional arc) given latitude and relevant ellipsoid
|
196
195
|
def self.meridional_arc(phi, ellipsoid = AIRY1830)
|
197
196
|
a, b = ellipsoid[:a], ellipsoid[:b]
|
198
|
-
n =
|
197
|
+
n = n(ellipsoid)
|
199
198
|
|
200
199
|
ma = (1 + n + (5.0 / 4.0) * n**2 + (5.0 / 4.0) * n**3) * (phi - PHI0)
|
201
200
|
mb = (3 * n + 3 * n**2 + (21.0 / 8.0) * n**3) * Math.sin(phi - PHI0) * Math.cos(phi + PHI0)
|
@@ -208,7 +207,7 @@ module Silva
|
|
208
207
|
# Calculate nu, rho, eta2 (transverse and meridional radii) given latitude and relevant ellipsoid.
|
209
208
|
def self.transverse_and_meridional_radii(phi, ellipsoid = AIRY1830)
|
210
209
|
a, b = ellipsoid[:a], ellipsoid[:b]
|
211
|
-
e2 =
|
210
|
+
e2 = eccentricity_squared(ellipsoid)
|
212
211
|
|
213
212
|
nu = a * F0 / Math.sqrt(1 - e2 * Math.sin(phi)**2)
|
214
213
|
rho = a * F0 * (1 - e2) / ((1 - e2 * Math.sin(phi)**2)**1.5)
|
data/lib/silva/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: silva
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: test/unit
|