geodesic_wgs84 1.32.2 → 1.32.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/ext/geodesic_wgs84/geodesic_wgs84.c +76 -8
- data/lib/geodesic_wgs84/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90a78279305f35055e74cf98c9d092cbbaa84d59
|
4
|
+
data.tar.gz: 3c09f9207ec20c580b3c2f9fd1a956797795493e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff785a2b23d03ed5daaf4035f8df9d2af0870b337e264823eed1ed7233b19bac22cc715401f25cfe6c3fd05083cfa05b053519f73a41cbcf355c6b2e5950b720
|
7
|
+
data.tar.gz: 57fde099670b5800730eeefd86a423065508a8a4a2321f08d097bee11f64f98df20c9cf73a222a0f43bc66f4eeaa701f9f1c99cd3b9f3aa2fcddb80fb082393a
|
data/README.md
CHANGED
@@ -33,12 +33,17 @@ Or install it yourself as:
|
|
33
33
|
|
34
34
|
## Sample Usage
|
35
35
|
|
36
|
+
The representation of a DMS (degree minute second) format is 'dd.mm.ss,f'
|
37
|
+
where f means tenth of seconds (fraction).
|
38
|
+
|
36
39
|
require 'geodesic_wgs84'
|
37
40
|
|
38
41
|
wgs84 = Wgs84.new
|
39
42
|
|
40
43
|
wgs84.lat_lon ...
|
41
44
|
|
45
|
+
wgs84.lat_lon_dms ...
|
46
|
+
|
42
47
|
wgs84.distance ...
|
43
48
|
|
44
49
|
wgs84.average ...
|
@@ -5,6 +5,9 @@
|
|
5
5
|
*/
|
6
6
|
|
7
7
|
#include <ruby.h>
|
8
|
+
#include <string.h>
|
9
|
+
#include <stdio.h>
|
10
|
+
#include <math.h>
|
8
11
|
#include "geodesic.h"
|
9
12
|
|
10
13
|
|
@@ -41,9 +44,11 @@ wgs84_get_value(VALUE arg)
|
|
41
44
|
memcpy(buf, RSTRING_PTR(arg), RSTRING_LEN(arg));
|
42
45
|
|
43
46
|
if (sscanf(buf, "%d.%d.%d,%d", &dd, &mm, &ss, &ff) == 4) {
|
44
|
-
|
45
|
-
dbl
|
46
|
-
|
47
|
+
dbl = (double) dd;
|
48
|
+
dbl += (double) mm / 60.0;
|
49
|
+
dbl += (double) ss / 3600.0;
|
50
|
+
dbl += (double) ff / 36000.0;
|
51
|
+
return dbl;
|
47
52
|
}
|
48
53
|
|
49
54
|
if (sscanf(buf, "%d.%d", &dd, &ff) == 2) {
|
@@ -91,6 +96,68 @@ wgs84_lat_lon(int argc, VALUE *argv, VALUE klass)
|
|
91
96
|
}
|
92
97
|
|
93
98
|
|
99
|
+
static void
|
100
|
+
wgs84_make_dms(double val, char *buf)
|
101
|
+
{
|
102
|
+
int tmp;
|
103
|
+
char *ptr;
|
104
|
+
|
105
|
+
/* get degrees */
|
106
|
+
tmp = (int) val;
|
107
|
+
sprintf(buf, "%02d", tmp);
|
108
|
+
val -= (double) tmp;
|
109
|
+
ptr = buf + strlen(buf);
|
110
|
+
|
111
|
+
/* get minutes */
|
112
|
+
val *= 60.0;
|
113
|
+
tmp = (int) val;
|
114
|
+
sprintf(ptr, ".%02d", tmp);
|
115
|
+
val -= (double) tmp;
|
116
|
+
ptr = buf + strlen(buf);
|
117
|
+
|
118
|
+
/* get seconds */
|
119
|
+
val *= 60.0;
|
120
|
+
tmp = (int) val;
|
121
|
+
sprintf(ptr, ".%02d", tmp);
|
122
|
+
val -= (double) tmp;
|
123
|
+
ptr = buf + strlen(buf);
|
124
|
+
|
125
|
+
/* get tenth of seconds */
|
126
|
+
val *= 10.0;
|
127
|
+
sprintf(ptr, ",%.0f", val);
|
128
|
+
}
|
129
|
+
|
130
|
+
|
131
|
+
static VALUE
|
132
|
+
wgs84_lat_lon_dms(int argc, VALUE *argv, VALUE klass)
|
133
|
+
{
|
134
|
+
double lat, lon;
|
135
|
+
char lat_buf[64], lon_buf[64];
|
136
|
+
VALUE tmp;
|
137
|
+
|
138
|
+
if (argc == 2) {
|
139
|
+
lat = wgs84_get_value(argv[0]);
|
140
|
+
lon = wgs84_get_value(argv[1]);
|
141
|
+
return rb_ary_new3(2L, rb_str_new2(lat_buf), rb_str_new2(lon_buf));
|
142
|
+
}
|
143
|
+
|
144
|
+
if (argc == 1 && TYPE(*argv) == T_ARRAY && RARRAY_LEN(*argv) == 2) {
|
145
|
+
lat = wgs84_get_value(rb_ary_entry(*argv, 0));
|
146
|
+
lon = wgs84_get_value(rb_ary_entry(*argv, 1));
|
147
|
+
return rb_ary_new3(2L, rb_str_new2(lat_buf), rb_str_new2(lon_buf));
|
148
|
+
}
|
149
|
+
|
150
|
+
if (argc == 1 && !NIL_P(tmp = rb_check_array_type(*argv))) {
|
151
|
+
lat = wgs84_get_value(rb_ary_entry(tmp, 0));
|
152
|
+
lon = wgs84_get_value(rb_ary_entry(tmp, 1));
|
153
|
+
return rb_ary_new3(2L, rb_str_new2(lat_buf), rb_str_new2(lon_buf));
|
154
|
+
}
|
155
|
+
|
156
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
157
|
+
return Qnil;
|
158
|
+
}
|
159
|
+
|
160
|
+
|
94
161
|
static VALUE
|
95
162
|
wgs84_distance(int argc, VALUE *argv, VALUE klass)
|
96
163
|
{
|
@@ -219,10 +286,11 @@ void
|
|
219
286
|
Init_geodesic_wgs84(void)
|
220
287
|
{
|
221
288
|
cWGS84 = rb_define_class("Wgs84", rb_cObject);
|
222
|
-
rb_define_method(cWGS84, "initialize",
|
223
|
-
rb_define_method(cWGS84, "lat_lon",
|
224
|
-
rb_define_method(cWGS84, "
|
225
|
-
rb_define_method(cWGS84, "
|
226
|
-
rb_define_method(cWGS84, "
|
289
|
+
rb_define_method(cWGS84, "initialize", wgs84_init, 0);
|
290
|
+
rb_define_method(cWGS84, "lat_lon", wgs84_lat_lon, -1);
|
291
|
+
rb_define_method(cWGS84, "lat_lon_dms", wgs84_lat_lon, -1);
|
292
|
+
rb_define_method(cWGS84, "distance", wgs84_distance, -1);
|
293
|
+
rb_define_method(cWGS84, "average", wgs84_average, 2);
|
294
|
+
rb_define_method(cWGS84, "center", wgs84_center, 2);
|
227
295
|
}
|
228
296
|
|