geo-coordinates-parser 1.7.0 → 1.7.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.
- package/dist/cjs/converter.js +11 -9
- package/dist/cjs/tests/temp.cjs +6 -0
- package/dist/cjs/tests/temp.d.cts +1 -0
- package/dist/cjs/tests/test.js +2 -0
- package/dist/cjs/tests/testFormatConverter.js +7 -7
- package/dist/cjs/tests/testFormats.json +394 -0
- package/dist/cjs/tests/testformats.js +1 -1
- package/dist/cjs/toCoordinateFormat.d.ts +2 -1
- package/dist/cjs/toCoordinateFormat.js +35 -27
- package/dist/mjs/converter.js +11 -9
- package/dist/mjs/tests/temp.cjs +5 -0
- package/dist/mjs/tests/temp.d.cts +1 -0
- package/dist/mjs/tests/test.js +2 -0
- package/dist/mjs/tests/testFormatConverter.js +7 -7
- package/dist/mjs/tests/testFormats.json +394 -0
- package/dist/mjs/tests/testformats.js +1 -1
- package/dist/mjs/toCoordinateFormat.d.ts +2 -1
- package/dist/mjs/toCoordinateFormat.js +35 -27
- package/package.json +1 -1
package/dist/cjs/converter.js
CHANGED
@@ -139,6 +139,7 @@ function converter(coordsString, decimalPlaces) {
|
|
139
139
|
if (parseInt(match[10]) < 0) {
|
140
140
|
ddLng = -1 * ddLng;
|
141
141
|
}
|
142
|
+
//the compass directions
|
142
143
|
if (match[1]) {
|
143
144
|
latdir = match[1];
|
144
145
|
lngdir = match[9];
|
@@ -176,6 +177,7 @@ function converter(coordsString, decimalPlaces) {
|
|
176
177
|
if (parseInt(match[10]) < 0) {
|
177
178
|
ddLng = -1 * ddLng;
|
178
179
|
}
|
180
|
+
//the compass directions
|
179
181
|
if (match[1]) {
|
180
182
|
latdir = match[1];
|
181
183
|
lngdir = match[9];
|
@@ -200,8 +202,8 @@ function converter(coordsString, decimalPlaces) {
|
|
200
202
|
throw new Error("invalid latitude value");
|
201
203
|
}
|
202
204
|
//if we have one direction we must have the other
|
203
|
-
if ((latdir
|
204
|
-
throw new Error("invalid coordinates
|
205
|
+
if ((latdir && !lngdir) || (!latdir && lngdir)) {
|
206
|
+
throw new Error("invalid coordinates value");
|
205
207
|
}
|
206
208
|
//the directions can't be the same
|
207
209
|
if (latdir && latdir == lngdir) {
|
@@ -279,20 +281,19 @@ function converter(coordsString, decimalPlaces) {
|
|
279
281
|
}
|
280
282
|
}
|
281
283
|
//no integer coords allowed
|
282
|
-
//validation -- no integer coords
|
283
284
|
if (/^\d+$/.test(verbatimLat) || /^\d+$/.test(verbatimLng)) {
|
284
285
|
throw new Error('degree only coordinate/s provided');
|
285
286
|
}
|
286
|
-
//
|
287
|
+
// last bit of tidying up...
|
287
288
|
if (isNaN(ddLat) && ddLat.includes(',')) {
|
288
289
|
ddLat = ddLat.replace(',', '.');
|
289
290
|
}
|
290
|
-
//all done!!
|
291
|
-
//just truncate the decimals appropriately
|
292
|
-
ddLat = Number(Number(ddLat).toFixed(decimalPlaces));
|
293
291
|
if (isNaN(ddLng) && ddLng.includes(',')) {
|
294
292
|
ddLng = ddLng.replace(',', '.');
|
295
293
|
}
|
294
|
+
//all done!!
|
295
|
+
//just truncate the decimals appropriately
|
296
|
+
ddLat = Number(Number(ddLat).toFixed(decimalPlaces));
|
296
297
|
ddLng = Number(Number(ddLng).toFixed(decimalPlaces));
|
297
298
|
return Object.freeze({
|
298
299
|
verbatimCoordinates,
|
@@ -317,11 +318,11 @@ function checkMatch(match) {
|
|
317
318
|
const filteredMatch = [...match];
|
318
319
|
//we need to shift the array because it contains the whole coordinates string in the first item
|
319
320
|
filteredMatch.shift();
|
320
|
-
//check the array length is an even number
|
321
|
+
//check the array length is an even number
|
321
322
|
if (filteredMatch.length % 2 > 0) {
|
322
323
|
return false;
|
323
324
|
}
|
324
|
-
//regex for testing corresponding values match
|
325
|
+
// regex for testing corresponding values match
|
325
326
|
const numerictest = /^[-+]?\d+([\.,]\d+)?$/; //for testing numeric values
|
326
327
|
const stringtest = /[eastsouthnorthwest]+/i; //for testing string values (north, south, etc)
|
327
328
|
const halflen = filteredMatch.length / 2;
|
@@ -372,6 +373,7 @@ function coordsCloseEnough(coordsToTest) {
|
|
372
373
|
throw new Error("coords being tested must be separated by a comma");
|
373
374
|
}
|
374
375
|
}
|
376
|
+
// An enum for coordinates formats
|
375
377
|
const to = Object.freeze({
|
376
378
|
DMS: 'DMS',
|
377
379
|
DM: 'DM',
|
@@ -0,0 +1,6 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
// just for counting the number of test objects in the json file
|
4
|
+
// remember if you run makeTestFormatsJSON from the debugger it puts the new json file in the root directory so you have to move it here
|
5
|
+
const data = require('./testFormats.json');
|
6
|
+
let i = 0;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/dist/cjs/tests/test.js
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
"use strict";
|
2
|
+
// when adding new formats, make sure to add them to testformats.js, and not to testFormats.json
|
3
|
+
// use makeTestFormatsJSON.js to make testFormats.json
|
2
4
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
5
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
6
|
};
|
@@ -8,13 +8,13 @@ let test = {
|
|
8
8
|
decimalCoordinates: '-24.3456, 28.92435',
|
9
9
|
toCoordinateFormat: toCoordinateFormat_js_1.default
|
10
10
|
};
|
11
|
-
console.log(test.toCoordinateFormat('DMS'));
|
11
|
+
console.log(test.decimalCoordinates, '==', test.toCoordinateFormat('DMS'));
|
12
12
|
test.decimalCoordinates = '-25.76887,28.26939';
|
13
|
-
console.log(test.toCoordinateFormat('DMS'));
|
14
|
-
console.log(test.toCoordinateFormat('DM'));
|
15
|
-
console.log(test.toCoordinateFormat('DD'));
|
13
|
+
console.log(test.decimalCoordinates, '==', test.toCoordinateFormat('DMS'));
|
14
|
+
console.log(test.decimalCoordinates, '==', test.toCoordinateFormat('DM'));
|
15
|
+
console.log(test.decimalCoordinates, '==', test.toCoordinateFormat('DD'));
|
16
16
|
test.decimalCoordinates = '-25.815928, 28.070318';
|
17
|
-
console.log(test.toCoordinateFormat('DM'));
|
17
|
+
console.log(test.decimalCoordinates, '==', test.toCoordinateFormat('DM'));
|
18
18
|
test.decimalCoordinates = '-25.000, 28.000';
|
19
|
-
console.log(test.toCoordinateFormat('DMS'));
|
20
|
-
console.log(test.toCoordinateFormat('DM'));
|
19
|
+
console.log(test.decimalCoordinates, '==', test.toCoordinateFormat('DMS'));
|
20
|
+
console.log(test.decimalCoordinates, '==', test.toCoordinateFormat('DM'));
|
@@ -0,0 +1,394 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"verbatimCoordinates": "40.123, -74.123",
|
4
|
+
"verbatimLatitude": "40.123",
|
5
|
+
"verbatimLongitude": "-74.123",
|
6
|
+
"decimalLatitude": 40.123,
|
7
|
+
"decimalLongitude": -74.123
|
8
|
+
},
|
9
|
+
{
|
10
|
+
"verbatimCoordinates": "40.123° N 74.123° W",
|
11
|
+
"verbatimLatitude": "40.123° N",
|
12
|
+
"verbatimLongitude": "74.123° W",
|
13
|
+
"decimalLatitude": 40.123,
|
14
|
+
"decimalLongitude": -74.123
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"verbatimCoordinates": "40.123° N 74.123° W",
|
18
|
+
"verbatimLatitude": "40.123° N",
|
19
|
+
"verbatimLongitude": "74.123° W",
|
20
|
+
"decimalLatitude": 40.123,
|
21
|
+
"decimalLongitude": -74.123
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"verbatimCoordinates": "40° 7´ 22.8\" N 74° 7´ 22.8\" W",
|
25
|
+
"verbatimLatitude": "40° 7´ 22.8\" N",
|
26
|
+
"verbatimLongitude": "74° 7´ 22.8\" W",
|
27
|
+
"decimalLatitude": 40.123,
|
28
|
+
"decimalLongitude": -74.123
|
29
|
+
},
|
30
|
+
{
|
31
|
+
"verbatimCoordinates": "40° 7.38’ , -74° 7.38’",
|
32
|
+
"verbatimLatitude": "40° 7.38’",
|
33
|
+
"verbatimLongitude": "-74° 7.38’",
|
34
|
+
"decimalLatitude": 40.123,
|
35
|
+
"decimalLongitude": -74.123
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"verbatimCoordinates": "N40°7’22.8’’, W74°7’22.8’’",
|
39
|
+
"verbatimLatitude": "N40°7’22.8’’",
|
40
|
+
"verbatimLongitude": "W74°7’22.8’’",
|
41
|
+
"decimalLatitude": 40.123,
|
42
|
+
"decimalLongitude": -74.123
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"verbatimCoordinates": "40°7’22.8\"N, 74°7’22.8\"W",
|
46
|
+
"verbatimLatitude": "40°7’22.8\"N",
|
47
|
+
"verbatimLongitude": "74°7’22.8\"W",
|
48
|
+
"decimalLatitude": 40.123,
|
49
|
+
"decimalLongitude": -74.123
|
50
|
+
},
|
51
|
+
{
|
52
|
+
"verbatimCoordinates": "40°7'22.8\"N, 74°7'22.8\"W",
|
53
|
+
"verbatimLatitude": "40°7'22.8\"N",
|
54
|
+
"verbatimLongitude": "74°7'22.8\"W",
|
55
|
+
"decimalLatitude": 40.123,
|
56
|
+
"decimalLongitude": -74.123
|
57
|
+
},
|
58
|
+
{
|
59
|
+
"verbatimCoordinates": "40 7 22.8, -74 7 22.8",
|
60
|
+
"verbatimLatitude": "40 7 22.8",
|
61
|
+
"verbatimLongitude": "-74 7 22.8",
|
62
|
+
"decimalLatitude": 40.123,
|
63
|
+
"decimalLongitude": -74.123
|
64
|
+
},
|
65
|
+
{
|
66
|
+
"verbatimCoordinates": "40.123 -74.123",
|
67
|
+
"verbatimLatitude": "40.123",
|
68
|
+
"verbatimLongitude": "-74.123",
|
69
|
+
"decimalLatitude": 40.123,
|
70
|
+
"decimalLongitude": -74.123
|
71
|
+
},
|
72
|
+
{
|
73
|
+
"verbatimCoordinates": "40.123°,-74.123°",
|
74
|
+
"verbatimLatitude": "40.123°",
|
75
|
+
"verbatimLongitude": "-74.123°",
|
76
|
+
"decimalLatitude": 40.123,
|
77
|
+
"decimalLongitude": -74.123
|
78
|
+
},
|
79
|
+
{
|
80
|
+
"verbatimCoordinates": "40.123N74.123W",
|
81
|
+
"verbatimLatitude": "40.123N",
|
82
|
+
"verbatimLongitude": "74.123W",
|
83
|
+
"decimalLatitude": 40.123,
|
84
|
+
"decimalLongitude": -74.123
|
85
|
+
},
|
86
|
+
{
|
87
|
+
"verbatimCoordinates": "4007.38N7407.38W",
|
88
|
+
"verbatimLatitude": "4007.38N",
|
89
|
+
"verbatimLongitude": "7407.38W",
|
90
|
+
"decimalLatitude": 40.123,
|
91
|
+
"decimalLongitude": -74.123
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"verbatimCoordinates": "40°7’22.8\"N, 74°7’22.8\"W",
|
95
|
+
"verbatimLatitude": "40°7’22.8\"N",
|
96
|
+
"verbatimLongitude": "74°7’22.8\"W",
|
97
|
+
"decimalLatitude": 40.123,
|
98
|
+
"decimalLongitude": -74.123
|
99
|
+
},
|
100
|
+
{
|
101
|
+
"verbatimCoordinates": "400722.8N740722.8W",
|
102
|
+
"verbatimLatitude": "400722.8N",
|
103
|
+
"verbatimLongitude": "740722.8W",
|
104
|
+
"decimalLatitude": 40.123,
|
105
|
+
"decimalLongitude": -74.123
|
106
|
+
},
|
107
|
+
{
|
108
|
+
"verbatimCoordinates": "N 40 7.38 W 74 7.38",
|
109
|
+
"verbatimLatitude": "N 40 7.38",
|
110
|
+
"verbatimLongitude": "W 74 7.38",
|
111
|
+
"decimalLatitude": 40.123,
|
112
|
+
"decimalLongitude": -74.123
|
113
|
+
},
|
114
|
+
{
|
115
|
+
"verbatimCoordinates": "40:7:22.8N 74:7:22.8W",
|
116
|
+
"verbatimLatitude": "40:7:22.8N",
|
117
|
+
"verbatimLongitude": "74:7:22.8W",
|
118
|
+
"decimalLatitude": 40.123,
|
119
|
+
"decimalLongitude": -74.123
|
120
|
+
},
|
121
|
+
{
|
122
|
+
"verbatimCoordinates": "40:7:23N,74:7:23W",
|
123
|
+
"verbatimLatitude": "40:7:23N",
|
124
|
+
"verbatimLongitude": "74:7:23W",
|
125
|
+
"decimalLatitude": 40.1230555555,
|
126
|
+
"decimalLongitude": -74.1230555555
|
127
|
+
},
|
128
|
+
{
|
129
|
+
"verbatimCoordinates": "40°7’23\"N 74°7’23\"W",
|
130
|
+
"verbatimLatitude": "40°7’23\"N",
|
131
|
+
"verbatimLongitude": "74°7’23\"W",
|
132
|
+
"decimalLatitude": 40.1230555555,
|
133
|
+
"decimalLongitude": -74.12305555555555
|
134
|
+
},
|
135
|
+
{
|
136
|
+
"verbatimCoordinates": "40°7’23\"S 74°7’23\"E",
|
137
|
+
"verbatimLatitude": "40°7’23\"S",
|
138
|
+
"verbatimLongitude": "74°7’23\"E",
|
139
|
+
"decimalLatitude": -40.1230555555,
|
140
|
+
"decimalLongitude": 74.12305555555555
|
141
|
+
},
|
142
|
+
{
|
143
|
+
"verbatimCoordinates": "40°7’23\" -74°7’23\"",
|
144
|
+
"verbatimLatitude": "40°7’23\"",
|
145
|
+
"verbatimLongitude": "-74°7’23\"",
|
146
|
+
"decimalLatitude": 40.1230555555,
|
147
|
+
"decimalLongitude": -74.123055555
|
148
|
+
},
|
149
|
+
{
|
150
|
+
"verbatimCoordinates": "40d 7’ 23\" N 74d 7’ 23\" W",
|
151
|
+
"verbatimLatitude": "40d 7’ 23\" N",
|
152
|
+
"verbatimLongitude": "74d 7’ 23\" W",
|
153
|
+
"decimalLatitude": 40.1230555555,
|
154
|
+
"decimalLongitude": -74.123055555
|
155
|
+
},
|
156
|
+
{
|
157
|
+
"verbatimCoordinates": "40.123N 74.123W",
|
158
|
+
"verbatimLatitude": "40.123N",
|
159
|
+
"verbatimLongitude": "74.123W",
|
160
|
+
"decimalLatitude": 40.123,
|
161
|
+
"decimalLongitude": -74.123
|
162
|
+
},
|
163
|
+
{
|
164
|
+
"verbatimCoordinates": "40° 7.38, -74° 7.38",
|
165
|
+
"verbatimLatitude": "40° 7.38",
|
166
|
+
"verbatimLongitude": "-74° 7.38",
|
167
|
+
"decimalLatitude": 40.123,
|
168
|
+
"decimalLongitude": -74.123
|
169
|
+
},
|
170
|
+
{
|
171
|
+
"verbatimCoordinates": "40° 7.38, -74° 7.38",
|
172
|
+
"verbatimLatitude": "40° 7.38",
|
173
|
+
"verbatimLongitude": "-74° 7.38",
|
174
|
+
"decimalLatitude": 40.123,
|
175
|
+
"decimalLongitude": -74.123
|
176
|
+
},
|
177
|
+
{
|
178
|
+
"verbatimCoordinates": "40 7 22.8; -74 7 22.8",
|
179
|
+
"verbatimLatitude": "40 7 22.8",
|
180
|
+
"verbatimLongitude": "-74 7 22.8",
|
181
|
+
"decimalLatitude": 40.123,
|
182
|
+
"decimalLongitude": -74.123
|
183
|
+
},
|
184
|
+
{
|
185
|
+
"verbatimCoordinates": "50°4'17.698\"south, 14°24'2.826\"east",
|
186
|
+
"verbatimLatitude": "50°4'17.698\"south",
|
187
|
+
"verbatimLongitude": "14°24'2.826\"east",
|
188
|
+
"decimalLatitude": -50.07158277777778,
|
189
|
+
"decimalLongitude": 14.400785
|
190
|
+
},
|
191
|
+
{
|
192
|
+
"verbatimCoordinates": "50d4m17.698S 14d24m2.826E",
|
193
|
+
"verbatimLatitude": "50d4m17.698S",
|
194
|
+
"verbatimLongitude": "14d24m2.826E",
|
195
|
+
"decimalLatitude": -50.07158277777778,
|
196
|
+
"decimalLongitude": 14.400785
|
197
|
+
},
|
198
|
+
{
|
199
|
+
"verbatimCoordinates": "40:26:46N,79:56:55W",
|
200
|
+
"verbatimLatitude": "40:26:46N",
|
201
|
+
"verbatimLongitude": "79:56:55W",
|
202
|
+
"decimalLatitude": 40.44611111111111,
|
203
|
+
"decimalLongitude": -79.9486111111111
|
204
|
+
},
|
205
|
+
{
|
206
|
+
"verbatimCoordinates": "40:26:46.302N 79:56:55.903W",
|
207
|
+
"verbatimLatitude": "40:26:46.302N",
|
208
|
+
"verbatimLongitude": "79:56:55.903W",
|
209
|
+
"decimalLatitude": 40.446195,
|
210
|
+
"decimalLongitude": -79.94886194444445
|
211
|
+
},
|
212
|
+
{
|
213
|
+
"verbatimCoordinates": "40°26′47″N 79°58′36″W",
|
214
|
+
"verbatimLatitude": "40°26′47″N",
|
215
|
+
"verbatimLongitude": "79°58′36″W",
|
216
|
+
"decimalLatitude": 40.44638888888889,
|
217
|
+
"decimalLongitude": -79.97666666666667
|
218
|
+
},
|
219
|
+
{
|
220
|
+
"verbatimCoordinates": "40d 26′ 47″ N 79d 58′ 36″ W",
|
221
|
+
"verbatimLatitude": "40d 26′ 47″ N",
|
222
|
+
"verbatimLongitude": "79d 58′ 36″ W",
|
223
|
+
"decimalLatitude": 40.44638888888889,
|
224
|
+
"decimalLongitude": -79.97666666666667
|
225
|
+
},
|
226
|
+
{
|
227
|
+
"verbatimCoordinates": "40.446195N 79.948862W",
|
228
|
+
"verbatimLatitude": "40.446195N",
|
229
|
+
"verbatimLongitude": "79.948862W",
|
230
|
+
"decimalLatitude": 40.446195,
|
231
|
+
"decimalLongitude": -79.948862
|
232
|
+
},
|
233
|
+
{
|
234
|
+
"verbatimCoordinates": "40,446195° 79,948862°",
|
235
|
+
"verbatimLatitude": "40,446195°",
|
236
|
+
"verbatimLongitude": "79,948862°",
|
237
|
+
"decimalLatitude": 40.446195,
|
238
|
+
"decimalLongitude": 79.948862
|
239
|
+
},
|
240
|
+
{
|
241
|
+
"verbatimCoordinates": "40° 26.7717, -79° 56.93172",
|
242
|
+
"verbatimLatitude": "40° 26.7717",
|
243
|
+
"verbatimLongitude": "-79° 56.93172",
|
244
|
+
"decimalLatitude": 40.446195,
|
245
|
+
"decimalLongitude": -79.948862
|
246
|
+
},
|
247
|
+
{
|
248
|
+
"verbatimCoordinates": "40.446195, -79.948862",
|
249
|
+
"verbatimLatitude": "40.446195",
|
250
|
+
"verbatimLongitude": "-79.948862",
|
251
|
+
"decimalLatitude": 40.446195,
|
252
|
+
"decimalLongitude": -79.948862
|
253
|
+
},
|
254
|
+
{
|
255
|
+
"verbatimCoordinates": "40.123256; -74.123256",
|
256
|
+
"verbatimLatitude": "40.123256",
|
257
|
+
"verbatimLongitude": "-74.123256",
|
258
|
+
"decimalLatitude": 40.123256,
|
259
|
+
"decimalLongitude": -74.123256
|
260
|
+
},
|
261
|
+
{
|
262
|
+
"verbatimCoordinates": "18°24S 22°45E",
|
263
|
+
"verbatimLatitude": "18°24S",
|
264
|
+
"verbatimLongitude": "22°45E",
|
265
|
+
"decimalLatitude": -18.4,
|
266
|
+
"decimalLongitude": 22.75
|
267
|
+
},
|
268
|
+
{
|
269
|
+
"verbatimCoordinates": "10.432342S 10.6345345E",
|
270
|
+
"verbatimLatitude": "10.432342S",
|
271
|
+
"verbatimLongitude": "10.6345345E",
|
272
|
+
"decimalLatitude": -10.432342,
|
273
|
+
"decimalLongitude": 10.6345345
|
274
|
+
},
|
275
|
+
{
|
276
|
+
"verbatimCoordinates": "10.00S 10.00E",
|
277
|
+
"verbatimLatitude": "10.00S",
|
278
|
+
"verbatimLongitude": "10.00E",
|
279
|
+
"decimalLatitude": -10,
|
280
|
+
"decimalLongitude": 10
|
281
|
+
},
|
282
|
+
{
|
283
|
+
"verbatimCoordinates": "00.00S 01.00E",
|
284
|
+
"verbatimLatitude": "00.00S",
|
285
|
+
"verbatimLongitude": "01.00E",
|
286
|
+
"decimalLatitude": 0,
|
287
|
+
"decimalLongitude": 1
|
288
|
+
},
|
289
|
+
{
|
290
|
+
"verbatimCoordinates": "18.24S 22.45E",
|
291
|
+
"verbatimLatitude": "18.24S",
|
292
|
+
"verbatimLongitude": "22.45E",
|
293
|
+
"decimalLatitude": -18.4,
|
294
|
+
"decimalLongitude": 22.75
|
295
|
+
},
|
296
|
+
{
|
297
|
+
"verbatimCoordinates": "27deg 15min 45.2sec S 18deg 32min 53.7sec E",
|
298
|
+
"verbatimLatitude": "27deg 15min 45.2sec S",
|
299
|
+
"verbatimLongitude": "18deg 32min 53.7sec E",
|
300
|
+
"decimalLatitude": -27.262555555555554,
|
301
|
+
"decimalLongitude": 18.54825
|
302
|
+
},
|
303
|
+
{
|
304
|
+
"verbatimCoordinates": "-23.3245° S / 28.2344° E",
|
305
|
+
"verbatimLatitude": "-23.3245° S",
|
306
|
+
"verbatimLongitude": "28.2344° E",
|
307
|
+
"decimalLatitude": -23.3245,
|
308
|
+
"decimalLongitude": 28.2344
|
309
|
+
},
|
310
|
+
{
|
311
|
+
"verbatimCoordinates": "40° 26.7717 -79° 56.93172",
|
312
|
+
"verbatimLatitude": "40° 26.7717",
|
313
|
+
"verbatimLongitude": "-79° 56.93172",
|
314
|
+
"decimalLatitude": 40.446195,
|
315
|
+
"decimalLongitude": -79.948862
|
316
|
+
},
|
317
|
+
{
|
318
|
+
"verbatimCoordinates": "27.15.45S 18.32.53E",
|
319
|
+
"verbatimLatitude": "27.15.45S",
|
320
|
+
"verbatimLongitude": "18.32.53E",
|
321
|
+
"decimalLatitude": -27.2625,
|
322
|
+
"decimalLongitude": 18.548055
|
323
|
+
},
|
324
|
+
{
|
325
|
+
"verbatimCoordinates": "-27.15.45 18.32.53",
|
326
|
+
"verbatimLatitude": "-27.15.45",
|
327
|
+
"verbatimLongitude": "18.32.53",
|
328
|
+
"decimalLatitude": -27.2625,
|
329
|
+
"decimalLongitude": 18.548055
|
330
|
+
},
|
331
|
+
{
|
332
|
+
"verbatimCoordinates": "27.15.45.2S 18.32.53.4E",
|
333
|
+
"verbatimLatitude": "27.15.45.2S",
|
334
|
+
"verbatimLongitude": "18.32.53.4E",
|
335
|
+
"decimalLatitude": -27.262556,
|
336
|
+
"decimalLongitude": 18.548167
|
337
|
+
},
|
338
|
+
{
|
339
|
+
"verbatimCoordinates": "27.15.45,2S 18.32.53,4E",
|
340
|
+
"verbatimLatitude": "27.15.45,2S",
|
341
|
+
"verbatimLongitude": "18.32.53,4E",
|
342
|
+
"decimalLatitude": -27.262556,
|
343
|
+
"decimalLongitude": 18.548167
|
344
|
+
},
|
345
|
+
{
|
346
|
+
"verbatimCoordinates": "S23.43563 ° E22.45634 °",
|
347
|
+
"verbatimLatitude": "S23.43563 °",
|
348
|
+
"verbatimLongitude": "E22.45634 °",
|
349
|
+
"decimalLatitude": -23.43563,
|
350
|
+
"decimalLongitude": 22.45634
|
351
|
+
},
|
352
|
+
{
|
353
|
+
"verbatimCoordinates": "27,71372° S 23,07771° E",
|
354
|
+
"verbatimLatitude": "27,71372° S",
|
355
|
+
"verbatimLongitude": "23,07771° E",
|
356
|
+
"decimalLatitude": -27.71372,
|
357
|
+
"decimalLongitude": 23.07771
|
358
|
+
},
|
359
|
+
{
|
360
|
+
"verbatimCoordinates": "27.45.34 S 23.23.23 E",
|
361
|
+
"verbatimLatitude": "27.45.34 S",
|
362
|
+
"verbatimLongitude": "23.23.23 E",
|
363
|
+
"decimalLatitude": -27.759444,
|
364
|
+
"decimalLongitude": 23.38972222
|
365
|
+
},
|
366
|
+
{
|
367
|
+
"verbatimCoordinates": "S 27.45.34 E 23.23.23",
|
368
|
+
"verbatimLatitude": "S 27.45.34",
|
369
|
+
"verbatimLongitude": "E 23.23.23",
|
370
|
+
"decimalLatitude": -27.759444,
|
371
|
+
"decimalLongitude": 23.38972222
|
372
|
+
},
|
373
|
+
{
|
374
|
+
"verbatimCoordinates": "53 16.3863,4 52.8171",
|
375
|
+
"verbatimLatitude": "53 16.3863",
|
376
|
+
"verbatimLongitude": "4 52.8171",
|
377
|
+
"decimalLatitude": 53.273105,
|
378
|
+
"decimalLongitude": 4.88029
|
379
|
+
},
|
380
|
+
{
|
381
|
+
"verbatimCoordinates": "50 8.2914,-5 2.4447",
|
382
|
+
"verbatimLatitude": "50 8.2914",
|
383
|
+
"verbatimLongitude": "-5 2.4447",
|
384
|
+
"decimalLatitude": 50.13819,
|
385
|
+
"decimalLongitude": -5.040745
|
386
|
+
},
|
387
|
+
{
|
388
|
+
"verbatimCoordinates": "N 48° 30,6410', E 18° 57,4583'",
|
389
|
+
"verbatimLatitude": "N 48° 30,6410'",
|
390
|
+
"verbatimLongitude": "E 18° 57,4583'",
|
391
|
+
"decimalLatitude": 48.51068,
|
392
|
+
"decimalLongitude": 18.95764
|
393
|
+
}
|
394
|
+
]
|
@@ -236,8 +236,8 @@ const coordsRegexFormats = [
|
|
236
236
|
decimalLongitude: 22.75
|
237
237
|
}
|
238
238
|
];
|
239
|
+
// additional formats we've encountered
|
239
240
|
const otherFormats = [
|
240
|
-
// additional formats we've encountered
|
241
241
|
{
|
242
242
|
verbatimCoordinates: '10.432342S 10.6345345E',
|
243
243
|
verbatimLatitude: '10.432342S',
|
@@ -1,6 +1,7 @@
|
|
1
1
|
export default toCoordinateFormat;
|
2
2
|
/**
|
3
|
-
* Converts decimalCoordinates to
|
3
|
+
* Converts decimalCoordinates to commonly used string formats
|
4
|
+
* Note that this will add degree and direction symbols to decimal coordinates
|
4
5
|
* @param {string} format Either DMS or DM
|
5
6
|
* @returns {string}
|
6
7
|
*/
|
@@ -2,7 +2,8 @@
|
|
2
2
|
//borrowed from https://www.codegrepper.com/code-examples/javascript/javascript+converting+latitude+longitude+to+gps+coordinates
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
4
4
|
/**
|
5
|
-
* Converts decimalCoordinates to
|
5
|
+
* Converts decimalCoordinates to commonly used string formats
|
6
|
+
* Note that this will add degree and direction symbols to decimal coordinates
|
6
7
|
* @param {string} format Either DMS or DM
|
7
8
|
* @returns {string}
|
8
9
|
*/
|
@@ -10,40 +11,47 @@ function toCoordinateFormat(format) {
|
|
10
11
|
if (!['DMS', 'DM', 'DD'].includes(format))
|
11
12
|
throw new Error('invalid format specified');
|
12
13
|
if (this.decimalCoordinates && this.decimalCoordinates.trim()) {
|
14
|
+
const parts = this.decimalCoordinates.split(',').map(x => Number(x.trim()));
|
15
|
+
const decimalLatitude = Number(parts[0]);
|
16
|
+
const decimalLongitude = Number(parts[1]);
|
17
|
+
const absoluteLatitude = Math.abs(decimalLatitude);
|
18
|
+
const absoluteLongitude = Math.abs(decimalLongitude);
|
19
|
+
const latDir = decimalLatitude > 0 ? "N" : "S";
|
20
|
+
const longDir = decimalLongitude > 0 ? "E" : "W";
|
21
|
+
let result;
|
13
22
|
if (format == 'DD') {
|
14
|
-
|
23
|
+
result = `${absoluteLatitude}° ${latDir}, ${absoluteLongitude}° ${longDir}`;
|
15
24
|
}
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
25
|
+
//else we need some more things
|
26
|
+
const degreesLatitude = Math.floor(absoluteLatitude);
|
27
|
+
const degreesLongitude = Math.floor(absoluteLongitude);
|
28
|
+
const minutesLatitudeNotTruncated = (absoluteLatitude - degreesLatitude) * 60;
|
29
|
+
const minutesLongitudeNotTruncated = (absoluteLongitude - degreesLongitude) * 60;
|
30
|
+
if (format == 'DM') {
|
31
|
+
const dmMinsLatitude = round(minutesLatitudeNotTruncated, 3).toFixed(3).padStart(6, '0');
|
32
|
+
const dmMinsLongitude = round(minutesLongitudeNotTruncated, 3).toFixed(3).padStart(6, '0');
|
33
|
+
result = `${degreesLatitude}° ${dmMinsLatitude}' ${latDir}, ${degreesLongitude}° ${dmMinsLongitude}' ${longDir}`;
|
34
|
+
}
|
35
|
+
if (format == "DMS") {
|
36
|
+
const latMinutes = Math.floor(minutesLatitudeNotTruncated);
|
37
|
+
const longMinutes = Math.floor(minutesLongitudeNotTruncated);
|
38
|
+
let latSeconds = ((minutesLatitudeNotTruncated - latMinutes) * 60).toFixed(1).padStart(4, '0');
|
39
|
+
let longSeconds = ((minutesLongitudeNotTruncated - longMinutes) * 60).toFixed(1).padStart(4, '0');
|
40
|
+
const latMinutesString = latMinutes.toString().padStart(2, '0');
|
41
|
+
const longMinutesString = longMinutes.toString().padStart(2, '0');
|
42
|
+
// if they both end in .0 we drop the .0
|
43
|
+
if (latSeconds.endsWith('.0"') && longSeconds.endsWith('.0"')) {
|
44
|
+
latSeconds = latSeconds.replace(/\.0"$/, '"');
|
45
|
+
longSeconds = longSeconds.replace(/\.0"$/, '"');
|
46
|
+
}
|
47
|
+
result = `${degreesLatitude}° ${latMinutesString}' ${latSeconds}" ${latDir}, ${degreesLongitude}° ${longMinutesString}' ${longSeconds}" ${longDir}`;
|
23
48
|
}
|
24
|
-
|
25
|
-
const longDirection = parts[1] >= 0 ? " E" : " W";
|
26
|
-
return `${convertedLat + latDirection}, ${convertedLong + longDirection}`;
|
49
|
+
return result;
|
27
50
|
}
|
28
51
|
else {
|
29
52
|
throw new Error('no decimal coordinates to convert');
|
30
53
|
}
|
31
54
|
}
|
32
|
-
//assumes everything is valid...
|
33
|
-
function convert(coord, format) {
|
34
|
-
const absolute = Math.abs(coord);
|
35
|
-
const degrees = Math.floor(absolute);
|
36
|
-
const minutesNotTruncated = (absolute - degrees) * 60;
|
37
|
-
if (format == 'DM') {
|
38
|
-
let dmMins = round(minutesNotTruncated, 3).toFixed(3).padStart(6, '0');
|
39
|
-
return `${degrees}° ${dmMins}'`;
|
40
|
-
}
|
41
|
-
//else
|
42
|
-
let minutes = Math.floor(minutesNotTruncated);
|
43
|
-
let seconds = ((minutesNotTruncated - minutes) * 60).toFixed(1).padStart(4, '0');
|
44
|
-
minutes = minutes.toString().padStart(2, '0');
|
45
|
-
return `${degrees}° ${minutes}' ${seconds}"`;
|
46
|
-
}
|
47
55
|
function round(num, places) {
|
48
56
|
const d = Math.pow(10, places);
|
49
57
|
return Math.round((num + Number.EPSILON) * d) / d;
|
package/dist/mjs/converter.js
CHANGED
@@ -134,6 +134,7 @@ function converter(coordsString, decimalPlaces) {
|
|
134
134
|
if (parseInt(match[10]) < 0) {
|
135
135
|
ddLng = -1 * ddLng;
|
136
136
|
}
|
137
|
+
//the compass directions
|
137
138
|
if (match[1]) {
|
138
139
|
latdir = match[1];
|
139
140
|
lngdir = match[9];
|
@@ -171,6 +172,7 @@ function converter(coordsString, decimalPlaces) {
|
|
171
172
|
if (parseInt(match[10]) < 0) {
|
172
173
|
ddLng = -1 * ddLng;
|
173
174
|
}
|
175
|
+
//the compass directions
|
174
176
|
if (match[1]) {
|
175
177
|
latdir = match[1];
|
176
178
|
lngdir = match[9];
|
@@ -195,8 +197,8 @@ function converter(coordsString, decimalPlaces) {
|
|
195
197
|
throw new Error("invalid latitude value");
|
196
198
|
}
|
197
199
|
//if we have one direction we must have the other
|
198
|
-
if ((latdir
|
199
|
-
throw new Error("invalid coordinates
|
200
|
+
if ((latdir && !lngdir) || (!latdir && lngdir)) {
|
201
|
+
throw new Error("invalid coordinates value");
|
200
202
|
}
|
201
203
|
//the directions can't be the same
|
202
204
|
if (latdir && latdir == lngdir) {
|
@@ -274,20 +276,19 @@ function converter(coordsString, decimalPlaces) {
|
|
274
276
|
}
|
275
277
|
}
|
276
278
|
//no integer coords allowed
|
277
|
-
//validation -- no integer coords
|
278
279
|
if (/^\d+$/.test(verbatimLat) || /^\d+$/.test(verbatimLng)) {
|
279
280
|
throw new Error('degree only coordinate/s provided');
|
280
281
|
}
|
281
|
-
//
|
282
|
+
// last bit of tidying up...
|
282
283
|
if (isNaN(ddLat) && ddLat.includes(',')) {
|
283
284
|
ddLat = ddLat.replace(',', '.');
|
284
285
|
}
|
285
|
-
//all done!!
|
286
|
-
//just truncate the decimals appropriately
|
287
|
-
ddLat = Number(Number(ddLat).toFixed(decimalPlaces));
|
288
286
|
if (isNaN(ddLng) && ddLng.includes(',')) {
|
289
287
|
ddLng = ddLng.replace(',', '.');
|
290
288
|
}
|
289
|
+
//all done!!
|
290
|
+
//just truncate the decimals appropriately
|
291
|
+
ddLat = Number(Number(ddLat).toFixed(decimalPlaces));
|
291
292
|
ddLng = Number(Number(ddLng).toFixed(decimalPlaces));
|
292
293
|
return Object.freeze({
|
293
294
|
verbatimCoordinates,
|
@@ -312,11 +313,11 @@ function checkMatch(match) {
|
|
312
313
|
const filteredMatch = [...match];
|
313
314
|
//we need to shift the array because it contains the whole coordinates string in the first item
|
314
315
|
filteredMatch.shift();
|
315
|
-
//check the array length is an even number
|
316
|
+
//check the array length is an even number
|
316
317
|
if (filteredMatch.length % 2 > 0) {
|
317
318
|
return false;
|
318
319
|
}
|
319
|
-
//regex for testing corresponding values match
|
320
|
+
// regex for testing corresponding values match
|
320
321
|
const numerictest = /^[-+]?\d+([\.,]\d+)?$/; //for testing numeric values
|
321
322
|
const stringtest = /[eastsouthnorthwest]+/i; //for testing string values (north, south, etc)
|
322
323
|
const halflen = filteredMatch.length / 2;
|
@@ -367,6 +368,7 @@ function coordsCloseEnough(coordsToTest) {
|
|
367
368
|
throw new Error("coords being tested must be separated by a comma");
|
368
369
|
}
|
369
370
|
}
|
371
|
+
// An enum for coordinates formats
|
370
372
|
const to = Object.freeze({
|
371
373
|
DMS: 'DMS',
|
372
374
|
DM: 'DM',
|
@@ -0,0 +1,5 @@
|
|
1
|
+
// just for counting the number of test objects in the json file
|
2
|
+
// remember if you run makeTestFormatsJSON from the debugger it puts the new json file in the root directory so you have to move it here
|
3
|
+
const data = require('./testFormats.json');
|
4
|
+
let i = 0;
|
5
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/dist/mjs/tests/test.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
// when adding new formats, make sure to add them to testformats.js, and not to testFormats.json
|
2
|
+
// use makeTestFormatsJSON.js to make testFormats.json
|
1
3
|
import convert from '../converter.js';
|
2
4
|
import testFormats from './testformats.js';
|
3
5
|
import failingFormats from './failFormats.js';
|
@@ -3,13 +3,13 @@ let test = {
|
|
3
3
|
decimalCoordinates: '-24.3456, 28.92435',
|
4
4
|
toCoordinateFormat
|
5
5
|
};
|
6
|
-
console.log(test.toCoordinateFormat('DMS'));
|
6
|
+
console.log(test.decimalCoordinates, '==', test.toCoordinateFormat('DMS'));
|
7
7
|
test.decimalCoordinates = '-25.76887,28.26939';
|
8
|
-
console.log(test.toCoordinateFormat('DMS'));
|
9
|
-
console.log(test.toCoordinateFormat('DM'));
|
10
|
-
console.log(test.toCoordinateFormat('DD'));
|
8
|
+
console.log(test.decimalCoordinates, '==', test.toCoordinateFormat('DMS'));
|
9
|
+
console.log(test.decimalCoordinates, '==', test.toCoordinateFormat('DM'));
|
10
|
+
console.log(test.decimalCoordinates, '==', test.toCoordinateFormat('DD'));
|
11
11
|
test.decimalCoordinates = '-25.815928, 28.070318';
|
12
|
-
console.log(test.toCoordinateFormat('DM'));
|
12
|
+
console.log(test.decimalCoordinates, '==', test.toCoordinateFormat('DM'));
|
13
13
|
test.decimalCoordinates = '-25.000, 28.000';
|
14
|
-
console.log(test.toCoordinateFormat('DMS'));
|
15
|
-
console.log(test.toCoordinateFormat('DM'));
|
14
|
+
console.log(test.decimalCoordinates, '==', test.toCoordinateFormat('DMS'));
|
15
|
+
console.log(test.decimalCoordinates, '==', test.toCoordinateFormat('DM'));
|
@@ -0,0 +1,394 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"verbatimCoordinates": "40.123, -74.123",
|
4
|
+
"verbatimLatitude": "40.123",
|
5
|
+
"verbatimLongitude": "-74.123",
|
6
|
+
"decimalLatitude": 40.123,
|
7
|
+
"decimalLongitude": -74.123
|
8
|
+
},
|
9
|
+
{
|
10
|
+
"verbatimCoordinates": "40.123° N 74.123° W",
|
11
|
+
"verbatimLatitude": "40.123° N",
|
12
|
+
"verbatimLongitude": "74.123° W",
|
13
|
+
"decimalLatitude": 40.123,
|
14
|
+
"decimalLongitude": -74.123
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"verbatimCoordinates": "40.123° N 74.123° W",
|
18
|
+
"verbatimLatitude": "40.123° N",
|
19
|
+
"verbatimLongitude": "74.123° W",
|
20
|
+
"decimalLatitude": 40.123,
|
21
|
+
"decimalLongitude": -74.123
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"verbatimCoordinates": "40° 7´ 22.8\" N 74° 7´ 22.8\" W",
|
25
|
+
"verbatimLatitude": "40° 7´ 22.8\" N",
|
26
|
+
"verbatimLongitude": "74° 7´ 22.8\" W",
|
27
|
+
"decimalLatitude": 40.123,
|
28
|
+
"decimalLongitude": -74.123
|
29
|
+
},
|
30
|
+
{
|
31
|
+
"verbatimCoordinates": "40° 7.38’ , -74° 7.38’",
|
32
|
+
"verbatimLatitude": "40° 7.38’",
|
33
|
+
"verbatimLongitude": "-74° 7.38’",
|
34
|
+
"decimalLatitude": 40.123,
|
35
|
+
"decimalLongitude": -74.123
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"verbatimCoordinates": "N40°7’22.8’’, W74°7’22.8’’",
|
39
|
+
"verbatimLatitude": "N40°7’22.8’’",
|
40
|
+
"verbatimLongitude": "W74°7’22.8’’",
|
41
|
+
"decimalLatitude": 40.123,
|
42
|
+
"decimalLongitude": -74.123
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"verbatimCoordinates": "40°7’22.8\"N, 74°7’22.8\"W",
|
46
|
+
"verbatimLatitude": "40°7’22.8\"N",
|
47
|
+
"verbatimLongitude": "74°7’22.8\"W",
|
48
|
+
"decimalLatitude": 40.123,
|
49
|
+
"decimalLongitude": -74.123
|
50
|
+
},
|
51
|
+
{
|
52
|
+
"verbatimCoordinates": "40°7'22.8\"N, 74°7'22.8\"W",
|
53
|
+
"verbatimLatitude": "40°7'22.8\"N",
|
54
|
+
"verbatimLongitude": "74°7'22.8\"W",
|
55
|
+
"decimalLatitude": 40.123,
|
56
|
+
"decimalLongitude": -74.123
|
57
|
+
},
|
58
|
+
{
|
59
|
+
"verbatimCoordinates": "40 7 22.8, -74 7 22.8",
|
60
|
+
"verbatimLatitude": "40 7 22.8",
|
61
|
+
"verbatimLongitude": "-74 7 22.8",
|
62
|
+
"decimalLatitude": 40.123,
|
63
|
+
"decimalLongitude": -74.123
|
64
|
+
},
|
65
|
+
{
|
66
|
+
"verbatimCoordinates": "40.123 -74.123",
|
67
|
+
"verbatimLatitude": "40.123",
|
68
|
+
"verbatimLongitude": "-74.123",
|
69
|
+
"decimalLatitude": 40.123,
|
70
|
+
"decimalLongitude": -74.123
|
71
|
+
},
|
72
|
+
{
|
73
|
+
"verbatimCoordinates": "40.123°,-74.123°",
|
74
|
+
"verbatimLatitude": "40.123°",
|
75
|
+
"verbatimLongitude": "-74.123°",
|
76
|
+
"decimalLatitude": 40.123,
|
77
|
+
"decimalLongitude": -74.123
|
78
|
+
},
|
79
|
+
{
|
80
|
+
"verbatimCoordinates": "40.123N74.123W",
|
81
|
+
"verbatimLatitude": "40.123N",
|
82
|
+
"verbatimLongitude": "74.123W",
|
83
|
+
"decimalLatitude": 40.123,
|
84
|
+
"decimalLongitude": -74.123
|
85
|
+
},
|
86
|
+
{
|
87
|
+
"verbatimCoordinates": "4007.38N7407.38W",
|
88
|
+
"verbatimLatitude": "4007.38N",
|
89
|
+
"verbatimLongitude": "7407.38W",
|
90
|
+
"decimalLatitude": 40.123,
|
91
|
+
"decimalLongitude": -74.123
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"verbatimCoordinates": "40°7’22.8\"N, 74°7’22.8\"W",
|
95
|
+
"verbatimLatitude": "40°7’22.8\"N",
|
96
|
+
"verbatimLongitude": "74°7’22.8\"W",
|
97
|
+
"decimalLatitude": 40.123,
|
98
|
+
"decimalLongitude": -74.123
|
99
|
+
},
|
100
|
+
{
|
101
|
+
"verbatimCoordinates": "400722.8N740722.8W",
|
102
|
+
"verbatimLatitude": "400722.8N",
|
103
|
+
"verbatimLongitude": "740722.8W",
|
104
|
+
"decimalLatitude": 40.123,
|
105
|
+
"decimalLongitude": -74.123
|
106
|
+
},
|
107
|
+
{
|
108
|
+
"verbatimCoordinates": "N 40 7.38 W 74 7.38",
|
109
|
+
"verbatimLatitude": "N 40 7.38",
|
110
|
+
"verbatimLongitude": "W 74 7.38",
|
111
|
+
"decimalLatitude": 40.123,
|
112
|
+
"decimalLongitude": -74.123
|
113
|
+
},
|
114
|
+
{
|
115
|
+
"verbatimCoordinates": "40:7:22.8N 74:7:22.8W",
|
116
|
+
"verbatimLatitude": "40:7:22.8N",
|
117
|
+
"verbatimLongitude": "74:7:22.8W",
|
118
|
+
"decimalLatitude": 40.123,
|
119
|
+
"decimalLongitude": -74.123
|
120
|
+
},
|
121
|
+
{
|
122
|
+
"verbatimCoordinates": "40:7:23N,74:7:23W",
|
123
|
+
"verbatimLatitude": "40:7:23N",
|
124
|
+
"verbatimLongitude": "74:7:23W",
|
125
|
+
"decimalLatitude": 40.1230555555,
|
126
|
+
"decimalLongitude": -74.1230555555
|
127
|
+
},
|
128
|
+
{
|
129
|
+
"verbatimCoordinates": "40°7’23\"N 74°7’23\"W",
|
130
|
+
"verbatimLatitude": "40°7’23\"N",
|
131
|
+
"verbatimLongitude": "74°7’23\"W",
|
132
|
+
"decimalLatitude": 40.1230555555,
|
133
|
+
"decimalLongitude": -74.12305555555555
|
134
|
+
},
|
135
|
+
{
|
136
|
+
"verbatimCoordinates": "40°7’23\"S 74°7’23\"E",
|
137
|
+
"verbatimLatitude": "40°7’23\"S",
|
138
|
+
"verbatimLongitude": "74°7’23\"E",
|
139
|
+
"decimalLatitude": -40.1230555555,
|
140
|
+
"decimalLongitude": 74.12305555555555
|
141
|
+
},
|
142
|
+
{
|
143
|
+
"verbatimCoordinates": "40°7’23\" -74°7’23\"",
|
144
|
+
"verbatimLatitude": "40°7’23\"",
|
145
|
+
"verbatimLongitude": "-74°7’23\"",
|
146
|
+
"decimalLatitude": 40.1230555555,
|
147
|
+
"decimalLongitude": -74.123055555
|
148
|
+
},
|
149
|
+
{
|
150
|
+
"verbatimCoordinates": "40d 7’ 23\" N 74d 7’ 23\" W",
|
151
|
+
"verbatimLatitude": "40d 7’ 23\" N",
|
152
|
+
"verbatimLongitude": "74d 7’ 23\" W",
|
153
|
+
"decimalLatitude": 40.1230555555,
|
154
|
+
"decimalLongitude": -74.123055555
|
155
|
+
},
|
156
|
+
{
|
157
|
+
"verbatimCoordinates": "40.123N 74.123W",
|
158
|
+
"verbatimLatitude": "40.123N",
|
159
|
+
"verbatimLongitude": "74.123W",
|
160
|
+
"decimalLatitude": 40.123,
|
161
|
+
"decimalLongitude": -74.123
|
162
|
+
},
|
163
|
+
{
|
164
|
+
"verbatimCoordinates": "40° 7.38, -74° 7.38",
|
165
|
+
"verbatimLatitude": "40° 7.38",
|
166
|
+
"verbatimLongitude": "-74° 7.38",
|
167
|
+
"decimalLatitude": 40.123,
|
168
|
+
"decimalLongitude": -74.123
|
169
|
+
},
|
170
|
+
{
|
171
|
+
"verbatimCoordinates": "40° 7.38, -74° 7.38",
|
172
|
+
"verbatimLatitude": "40° 7.38",
|
173
|
+
"verbatimLongitude": "-74° 7.38",
|
174
|
+
"decimalLatitude": 40.123,
|
175
|
+
"decimalLongitude": -74.123
|
176
|
+
},
|
177
|
+
{
|
178
|
+
"verbatimCoordinates": "40 7 22.8; -74 7 22.8",
|
179
|
+
"verbatimLatitude": "40 7 22.8",
|
180
|
+
"verbatimLongitude": "-74 7 22.8",
|
181
|
+
"decimalLatitude": 40.123,
|
182
|
+
"decimalLongitude": -74.123
|
183
|
+
},
|
184
|
+
{
|
185
|
+
"verbatimCoordinates": "50°4'17.698\"south, 14°24'2.826\"east",
|
186
|
+
"verbatimLatitude": "50°4'17.698\"south",
|
187
|
+
"verbatimLongitude": "14°24'2.826\"east",
|
188
|
+
"decimalLatitude": -50.07158277777778,
|
189
|
+
"decimalLongitude": 14.400785
|
190
|
+
},
|
191
|
+
{
|
192
|
+
"verbatimCoordinates": "50d4m17.698S 14d24m2.826E",
|
193
|
+
"verbatimLatitude": "50d4m17.698S",
|
194
|
+
"verbatimLongitude": "14d24m2.826E",
|
195
|
+
"decimalLatitude": -50.07158277777778,
|
196
|
+
"decimalLongitude": 14.400785
|
197
|
+
},
|
198
|
+
{
|
199
|
+
"verbatimCoordinates": "40:26:46N,79:56:55W",
|
200
|
+
"verbatimLatitude": "40:26:46N",
|
201
|
+
"verbatimLongitude": "79:56:55W",
|
202
|
+
"decimalLatitude": 40.44611111111111,
|
203
|
+
"decimalLongitude": -79.9486111111111
|
204
|
+
},
|
205
|
+
{
|
206
|
+
"verbatimCoordinates": "40:26:46.302N 79:56:55.903W",
|
207
|
+
"verbatimLatitude": "40:26:46.302N",
|
208
|
+
"verbatimLongitude": "79:56:55.903W",
|
209
|
+
"decimalLatitude": 40.446195,
|
210
|
+
"decimalLongitude": -79.94886194444445
|
211
|
+
},
|
212
|
+
{
|
213
|
+
"verbatimCoordinates": "40°26′47″N 79°58′36″W",
|
214
|
+
"verbatimLatitude": "40°26′47″N",
|
215
|
+
"verbatimLongitude": "79°58′36″W",
|
216
|
+
"decimalLatitude": 40.44638888888889,
|
217
|
+
"decimalLongitude": -79.97666666666667
|
218
|
+
},
|
219
|
+
{
|
220
|
+
"verbatimCoordinates": "40d 26′ 47″ N 79d 58′ 36″ W",
|
221
|
+
"verbatimLatitude": "40d 26′ 47″ N",
|
222
|
+
"verbatimLongitude": "79d 58′ 36″ W",
|
223
|
+
"decimalLatitude": 40.44638888888889,
|
224
|
+
"decimalLongitude": -79.97666666666667
|
225
|
+
},
|
226
|
+
{
|
227
|
+
"verbatimCoordinates": "40.446195N 79.948862W",
|
228
|
+
"verbatimLatitude": "40.446195N",
|
229
|
+
"verbatimLongitude": "79.948862W",
|
230
|
+
"decimalLatitude": 40.446195,
|
231
|
+
"decimalLongitude": -79.948862
|
232
|
+
},
|
233
|
+
{
|
234
|
+
"verbatimCoordinates": "40,446195° 79,948862°",
|
235
|
+
"verbatimLatitude": "40,446195°",
|
236
|
+
"verbatimLongitude": "79,948862°",
|
237
|
+
"decimalLatitude": 40.446195,
|
238
|
+
"decimalLongitude": 79.948862
|
239
|
+
},
|
240
|
+
{
|
241
|
+
"verbatimCoordinates": "40° 26.7717, -79° 56.93172",
|
242
|
+
"verbatimLatitude": "40° 26.7717",
|
243
|
+
"verbatimLongitude": "-79° 56.93172",
|
244
|
+
"decimalLatitude": 40.446195,
|
245
|
+
"decimalLongitude": -79.948862
|
246
|
+
},
|
247
|
+
{
|
248
|
+
"verbatimCoordinates": "40.446195, -79.948862",
|
249
|
+
"verbatimLatitude": "40.446195",
|
250
|
+
"verbatimLongitude": "-79.948862",
|
251
|
+
"decimalLatitude": 40.446195,
|
252
|
+
"decimalLongitude": -79.948862
|
253
|
+
},
|
254
|
+
{
|
255
|
+
"verbatimCoordinates": "40.123256; -74.123256",
|
256
|
+
"verbatimLatitude": "40.123256",
|
257
|
+
"verbatimLongitude": "-74.123256",
|
258
|
+
"decimalLatitude": 40.123256,
|
259
|
+
"decimalLongitude": -74.123256
|
260
|
+
},
|
261
|
+
{
|
262
|
+
"verbatimCoordinates": "18°24S 22°45E",
|
263
|
+
"verbatimLatitude": "18°24S",
|
264
|
+
"verbatimLongitude": "22°45E",
|
265
|
+
"decimalLatitude": -18.4,
|
266
|
+
"decimalLongitude": 22.75
|
267
|
+
},
|
268
|
+
{
|
269
|
+
"verbatimCoordinates": "10.432342S 10.6345345E",
|
270
|
+
"verbatimLatitude": "10.432342S",
|
271
|
+
"verbatimLongitude": "10.6345345E",
|
272
|
+
"decimalLatitude": -10.432342,
|
273
|
+
"decimalLongitude": 10.6345345
|
274
|
+
},
|
275
|
+
{
|
276
|
+
"verbatimCoordinates": "10.00S 10.00E",
|
277
|
+
"verbatimLatitude": "10.00S",
|
278
|
+
"verbatimLongitude": "10.00E",
|
279
|
+
"decimalLatitude": -10,
|
280
|
+
"decimalLongitude": 10
|
281
|
+
},
|
282
|
+
{
|
283
|
+
"verbatimCoordinates": "00.00S 01.00E",
|
284
|
+
"verbatimLatitude": "00.00S",
|
285
|
+
"verbatimLongitude": "01.00E",
|
286
|
+
"decimalLatitude": 0,
|
287
|
+
"decimalLongitude": 1
|
288
|
+
},
|
289
|
+
{
|
290
|
+
"verbatimCoordinates": "18.24S 22.45E",
|
291
|
+
"verbatimLatitude": "18.24S",
|
292
|
+
"verbatimLongitude": "22.45E",
|
293
|
+
"decimalLatitude": -18.4,
|
294
|
+
"decimalLongitude": 22.75
|
295
|
+
},
|
296
|
+
{
|
297
|
+
"verbatimCoordinates": "27deg 15min 45.2sec S 18deg 32min 53.7sec E",
|
298
|
+
"verbatimLatitude": "27deg 15min 45.2sec S",
|
299
|
+
"verbatimLongitude": "18deg 32min 53.7sec E",
|
300
|
+
"decimalLatitude": -27.262555555555554,
|
301
|
+
"decimalLongitude": 18.54825
|
302
|
+
},
|
303
|
+
{
|
304
|
+
"verbatimCoordinates": "-23.3245° S / 28.2344° E",
|
305
|
+
"verbatimLatitude": "-23.3245° S",
|
306
|
+
"verbatimLongitude": "28.2344° E",
|
307
|
+
"decimalLatitude": -23.3245,
|
308
|
+
"decimalLongitude": 28.2344
|
309
|
+
},
|
310
|
+
{
|
311
|
+
"verbatimCoordinates": "40° 26.7717 -79° 56.93172",
|
312
|
+
"verbatimLatitude": "40° 26.7717",
|
313
|
+
"verbatimLongitude": "-79° 56.93172",
|
314
|
+
"decimalLatitude": 40.446195,
|
315
|
+
"decimalLongitude": -79.948862
|
316
|
+
},
|
317
|
+
{
|
318
|
+
"verbatimCoordinates": "27.15.45S 18.32.53E",
|
319
|
+
"verbatimLatitude": "27.15.45S",
|
320
|
+
"verbatimLongitude": "18.32.53E",
|
321
|
+
"decimalLatitude": -27.2625,
|
322
|
+
"decimalLongitude": 18.548055
|
323
|
+
},
|
324
|
+
{
|
325
|
+
"verbatimCoordinates": "-27.15.45 18.32.53",
|
326
|
+
"verbatimLatitude": "-27.15.45",
|
327
|
+
"verbatimLongitude": "18.32.53",
|
328
|
+
"decimalLatitude": -27.2625,
|
329
|
+
"decimalLongitude": 18.548055
|
330
|
+
},
|
331
|
+
{
|
332
|
+
"verbatimCoordinates": "27.15.45.2S 18.32.53.4E",
|
333
|
+
"verbatimLatitude": "27.15.45.2S",
|
334
|
+
"verbatimLongitude": "18.32.53.4E",
|
335
|
+
"decimalLatitude": -27.262556,
|
336
|
+
"decimalLongitude": 18.548167
|
337
|
+
},
|
338
|
+
{
|
339
|
+
"verbatimCoordinates": "27.15.45,2S 18.32.53,4E",
|
340
|
+
"verbatimLatitude": "27.15.45,2S",
|
341
|
+
"verbatimLongitude": "18.32.53,4E",
|
342
|
+
"decimalLatitude": -27.262556,
|
343
|
+
"decimalLongitude": 18.548167
|
344
|
+
},
|
345
|
+
{
|
346
|
+
"verbatimCoordinates": "S23.43563 ° E22.45634 °",
|
347
|
+
"verbatimLatitude": "S23.43563 °",
|
348
|
+
"verbatimLongitude": "E22.45634 °",
|
349
|
+
"decimalLatitude": -23.43563,
|
350
|
+
"decimalLongitude": 22.45634
|
351
|
+
},
|
352
|
+
{
|
353
|
+
"verbatimCoordinates": "27,71372° S 23,07771° E",
|
354
|
+
"verbatimLatitude": "27,71372° S",
|
355
|
+
"verbatimLongitude": "23,07771° E",
|
356
|
+
"decimalLatitude": -27.71372,
|
357
|
+
"decimalLongitude": 23.07771
|
358
|
+
},
|
359
|
+
{
|
360
|
+
"verbatimCoordinates": "27.45.34 S 23.23.23 E",
|
361
|
+
"verbatimLatitude": "27.45.34 S",
|
362
|
+
"verbatimLongitude": "23.23.23 E",
|
363
|
+
"decimalLatitude": -27.759444,
|
364
|
+
"decimalLongitude": 23.38972222
|
365
|
+
},
|
366
|
+
{
|
367
|
+
"verbatimCoordinates": "S 27.45.34 E 23.23.23",
|
368
|
+
"verbatimLatitude": "S 27.45.34",
|
369
|
+
"verbatimLongitude": "E 23.23.23",
|
370
|
+
"decimalLatitude": -27.759444,
|
371
|
+
"decimalLongitude": 23.38972222
|
372
|
+
},
|
373
|
+
{
|
374
|
+
"verbatimCoordinates": "53 16.3863,4 52.8171",
|
375
|
+
"verbatimLatitude": "53 16.3863",
|
376
|
+
"verbatimLongitude": "4 52.8171",
|
377
|
+
"decimalLatitude": 53.273105,
|
378
|
+
"decimalLongitude": 4.88029
|
379
|
+
},
|
380
|
+
{
|
381
|
+
"verbatimCoordinates": "50 8.2914,-5 2.4447",
|
382
|
+
"verbatimLatitude": "50 8.2914",
|
383
|
+
"verbatimLongitude": "-5 2.4447",
|
384
|
+
"decimalLatitude": 50.13819,
|
385
|
+
"decimalLongitude": -5.040745
|
386
|
+
},
|
387
|
+
{
|
388
|
+
"verbatimCoordinates": "N 48° 30,6410', E 18° 57,4583'",
|
389
|
+
"verbatimLatitude": "N 48° 30,6410'",
|
390
|
+
"verbatimLongitude": "E 18° 57,4583'",
|
391
|
+
"decimalLatitude": 48.51068,
|
392
|
+
"decimalLongitude": 18.95764
|
393
|
+
}
|
394
|
+
]
|
@@ -234,8 +234,8 @@ const coordsRegexFormats = [
|
|
234
234
|
decimalLongitude: 22.75
|
235
235
|
}
|
236
236
|
];
|
237
|
+
// additional formats we've encountered
|
237
238
|
const otherFormats = [
|
238
|
-
// additional formats we've encountered
|
239
239
|
{
|
240
240
|
verbatimCoordinates: '10.432342S 10.6345345E',
|
241
241
|
verbatimLatitude: '10.432342S',
|
@@ -1,6 +1,7 @@
|
|
1
1
|
export default toCoordinateFormat;
|
2
2
|
/**
|
3
|
-
* Converts decimalCoordinates to
|
3
|
+
* Converts decimalCoordinates to commonly used string formats
|
4
|
+
* Note that this will add degree and direction symbols to decimal coordinates
|
4
5
|
* @param {string} format Either DMS or DM
|
5
6
|
* @returns {string}
|
6
7
|
*/
|
@@ -1,6 +1,7 @@
|
|
1
1
|
//borrowed from https://www.codegrepper.com/code-examples/javascript/javascript+converting+latitude+longitude+to+gps+coordinates
|
2
2
|
/**
|
3
|
-
* Converts decimalCoordinates to
|
3
|
+
* Converts decimalCoordinates to commonly used string formats
|
4
|
+
* Note that this will add degree and direction symbols to decimal coordinates
|
4
5
|
* @param {string} format Either DMS or DM
|
5
6
|
* @returns {string}
|
6
7
|
*/
|
@@ -8,40 +9,47 @@ function toCoordinateFormat(format) {
|
|
8
9
|
if (!['DMS', 'DM', 'DD'].includes(format))
|
9
10
|
throw new Error('invalid format specified');
|
10
11
|
if (this.decimalCoordinates && this.decimalCoordinates.trim()) {
|
12
|
+
const parts = this.decimalCoordinates.split(',').map(x => Number(x.trim()));
|
13
|
+
const decimalLatitude = Number(parts[0]);
|
14
|
+
const decimalLongitude = Number(parts[1]);
|
15
|
+
const absoluteLatitude = Math.abs(decimalLatitude);
|
16
|
+
const absoluteLongitude = Math.abs(decimalLongitude);
|
17
|
+
const latDir = decimalLatitude > 0 ? "N" : "S";
|
18
|
+
const longDir = decimalLongitude > 0 ? "E" : "W";
|
19
|
+
let result;
|
11
20
|
if (format == 'DD') {
|
12
|
-
|
21
|
+
result = `${absoluteLatitude}° ${latDir}, ${absoluteLongitude}° ${longDir}`;
|
13
22
|
}
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
23
|
+
//else we need some more things
|
24
|
+
const degreesLatitude = Math.floor(absoluteLatitude);
|
25
|
+
const degreesLongitude = Math.floor(absoluteLongitude);
|
26
|
+
const minutesLatitudeNotTruncated = (absoluteLatitude - degreesLatitude) * 60;
|
27
|
+
const minutesLongitudeNotTruncated = (absoluteLongitude - degreesLongitude) * 60;
|
28
|
+
if (format == 'DM') {
|
29
|
+
const dmMinsLatitude = round(minutesLatitudeNotTruncated, 3).toFixed(3).padStart(6, '0');
|
30
|
+
const dmMinsLongitude = round(minutesLongitudeNotTruncated, 3).toFixed(3).padStart(6, '0');
|
31
|
+
result = `${degreesLatitude}° ${dmMinsLatitude}' ${latDir}, ${degreesLongitude}° ${dmMinsLongitude}' ${longDir}`;
|
32
|
+
}
|
33
|
+
if (format == "DMS") {
|
34
|
+
const latMinutes = Math.floor(minutesLatitudeNotTruncated);
|
35
|
+
const longMinutes = Math.floor(minutesLongitudeNotTruncated);
|
36
|
+
let latSeconds = ((minutesLatitudeNotTruncated - latMinutes) * 60).toFixed(1).padStart(4, '0');
|
37
|
+
let longSeconds = ((minutesLongitudeNotTruncated - longMinutes) * 60).toFixed(1).padStart(4, '0');
|
38
|
+
const latMinutesString = latMinutes.toString().padStart(2, '0');
|
39
|
+
const longMinutesString = longMinutes.toString().padStart(2, '0');
|
40
|
+
// if they both end in .0 we drop the .0
|
41
|
+
if (latSeconds.endsWith('.0"') && longSeconds.endsWith('.0"')) {
|
42
|
+
latSeconds = latSeconds.replace(/\.0"$/, '"');
|
43
|
+
longSeconds = longSeconds.replace(/\.0"$/, '"');
|
44
|
+
}
|
45
|
+
result = `${degreesLatitude}° ${latMinutesString}' ${latSeconds}" ${latDir}, ${degreesLongitude}° ${longMinutesString}' ${longSeconds}" ${longDir}`;
|
21
46
|
}
|
22
|
-
|
23
|
-
const longDirection = parts[1] >= 0 ? " E" : " W";
|
24
|
-
return `${convertedLat + latDirection}, ${convertedLong + longDirection}`;
|
47
|
+
return result;
|
25
48
|
}
|
26
49
|
else {
|
27
50
|
throw new Error('no decimal coordinates to convert');
|
28
51
|
}
|
29
52
|
}
|
30
|
-
//assumes everything is valid...
|
31
|
-
function convert(coord, format) {
|
32
|
-
const absolute = Math.abs(coord);
|
33
|
-
const degrees = Math.floor(absolute);
|
34
|
-
const minutesNotTruncated = (absolute - degrees) * 60;
|
35
|
-
if (format == 'DM') {
|
36
|
-
let dmMins = round(minutesNotTruncated, 3).toFixed(3).padStart(6, '0');
|
37
|
-
return `${degrees}° ${dmMins}'`;
|
38
|
-
}
|
39
|
-
//else
|
40
|
-
let minutes = Math.floor(minutesNotTruncated);
|
41
|
-
let seconds = ((minutesNotTruncated - minutes) * 60).toFixed(1).padStart(4, '0');
|
42
|
-
minutes = minutes.toString().padStart(2, '0');
|
43
|
-
return `${degrees}° ${minutes}' ${seconds}"`;
|
44
|
-
}
|
45
53
|
function round(num, places) {
|
46
54
|
const d = Math.pow(10, places);
|
47
55
|
return Math.round((num + Number.EPSILON) * d) / d;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "geo-coordinates-parser",
|
3
|
-
"version": "1.7.
|
3
|
+
"version": "1.7.1",
|
4
4
|
"description": "A Javascript function for reading a variety of coordinate formats and converting to decimal numbers. Builds on other efforts by returning the verbatim coordinates and the decimal coordinates all in one object.",
|
5
5
|
"type": "module",
|
6
6
|
"main": "./dist/cjs/merge.js",
|