Skip to content

Commit aa5424c

Browse files
committed
Support elevation for future potential use in suntimes
1 parent 61a0125 commit aa5424c

File tree

6 files changed

+641
-410
lines changed

6 files changed

+641
-410
lines changed

package-lock.json

Lines changed: 535 additions & 351 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hebcal/geo-sqlite",
3-
"version": "4.9.3",
3+
"version": "4.10.0",
44
"author": "Michael J. Radwin (https://github.com/mjradwin)",
55
"keywords": [
66
"hebcal"
@@ -28,11 +28,11 @@
2828
"geo-sqlite.d.ts"
2929
],
3030
"dependencies": {
31-
"@hebcal/cities": "^3.2.0",
32-
"@hebcal/core": "^4.3.0",
33-
"better-sqlite3": "^8.5.0",
34-
"pino": "^8.15.0",
35-
"pino-pretty": "^10.2.0",
31+
"@hebcal/cities": "^3.2.2",
32+
"@hebcal/core": "^4.5.1",
33+
"better-sqlite3": "^9.1.1",
34+
"pino": "^8.16.1",
35+
"pino-pretty": "^10.2.3",
3636
"transliteration": "^2.3.5"
3737
},
3838
"scripts": {
@@ -46,18 +46,18 @@
4646
},
4747
"license": "BSD-2-Clause",
4848
"devDependencies": {
49-
"@babel/core": "^7.22.10",
50-
"@babel/preset-env": "^7.22.10",
51-
"@babel/register": "^7.22.5",
52-
"@rollup/plugin-babel": "^6.0.3",
53-
"@rollup/plugin-commonjs": "^25.0.4",
54-
"@rollup/plugin-json": "^6.0.0",
55-
"@rollup/plugin-node-resolve": "^15.1.0",
49+
"@babel/core": "^7.23.3",
50+
"@babel/preset-env": "^7.23.3",
51+
"@babel/register": "^7.22.15",
52+
"@rollup/plugin-babel": "^6.0.4",
53+
"@rollup/plugin-commonjs": "^25.0.7",
54+
"@rollup/plugin-json": "^6.0.1",
55+
"@rollup/plugin-node-resolve": "^15.2.3",
5656
"ava": "^5.3.1",
57-
"eslint": "^8.47.0",
57+
"eslint": "^8.53.0",
5858
"eslint-config-google": "^0.14.0",
5959
"jsdoc": "^4.0.2",
6060
"jsdoc-to-markdown": "^8.0.0",
61-
"rollup": "^3.28.0"
61+
"rollup": "^4.4.0"
6262
}
6363
}

src/geodb.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const GEONAME_SQL = `SELECT
1414
g.latitude as latitude,
1515
g.longitude as longitude,
1616
g.population as population,
17+
g.gtopo30 as elevation,
1718
g.timezone as timezone
1819
FROM geoname g
1920
LEFT JOIN country c on g.country = c.iso
@@ -31,16 +32,19 @@ const GEONAME_ALL_SQL = `SELECT
3132
g.latitude as latitude,
3233
g.longitude as longitude,
3334
g.population as population,
35+
g.gtopo30 as elevation,
3436
g.timezone as timezone
3537
FROM geoname g
3638
LEFT JOIN country c on g.country = c.iso
3739
LEFT JOIN admin1 a on g.country||'.'||g.admin1 = a.key
3840
`;
3941

40-
const ZIPCODE_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving,Population
42+
const ZIPCODE_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,Elevation,
43+
TimeZone,DayLightSaving,Population
4144
FROM ZIPCodes_Primary WHERE ZipCode = ?`;
4245

43-
const ZIPCODE_ALL_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving,Population
46+
const ZIPCODE_ALL_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,Elevation,
47+
TimeZone,DayLightSaving,Population
4448
FROM ZIPCodes_Primary`;
4549

4650
const ZIP_COMPLETE_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving,Population
@@ -205,6 +209,9 @@ export class GeoDb {
205209
location.geo = 'zip';
206210
location.zip = zip;
207211
location.population = result.Population;
212+
if (result.Elevation) {
213+
location.elevation = result.Elevation;
214+
}
208215
return location;
209216
}
210217

@@ -296,6 +303,9 @@ export class GeoDb {
296303
if (result.population) {
297304
location.population = result.population;
298305
}
306+
if (result.elevation) {
307+
location.elevation = result.elevation;
308+
}
299309
return location;
300310
}
301311

@@ -337,6 +347,9 @@ export class GeoDb {
337347
population: res.Population,
338348
geo: 'zip',
339349
};
350+
if (res.Elevation) {
351+
obj.elevation = res.Elevation;
352+
}
340353
return obj;
341354
}
342355

src/geodb.spec.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ test('geoname', (t) => {
9090
geo: 'geoname',
9191
geonameid: 4119403,
9292
population: 197992,
93+
elevation: 105,
9394
admin1: 'Arkansas',
9495
};
9596
t.deepEqual(Object.assign({}, loc), expected);
@@ -119,7 +120,8 @@ test('zip', (t) => {
119120
stateName: 'Rhode Island',
120121
geo: 'zip',
121122
zip: '02912',
122-
population: 1370,
123+
population: 4739,
124+
elevation: 118,
123125
};
124126
t.deepEqual(Object.assign({}, loc), expected);
125127
});
@@ -159,7 +161,7 @@ test('autoCompleteZip', (t) => {
159161
latitude: 37.171008,
160162
longitude: -93.331857,
161163
timezone: 'America/Chicago',
162-
population: 54952,
164+
population: 55168,
163165
geo: 'zip',
164166
},
165167
{
@@ -172,7 +174,7 @@ test('autoCompleteZip', (t) => {
172174
latitude: 39.771921,
173175
longitude: -89.686047,
174176
timezone: 'America/Chicago',
175-
population: 39831,
177+
population: 39157,
176178
geo: 'zip',
177179
},
178180
];
@@ -192,7 +194,7 @@ test('autoCompleteZipPlus4', (t) => {
192194
latitude: 39.771921,
193195
longitude: -89.686047,
194196
timezone: 'America/Chicago',
195-
population: 39831,
197+
population: 39157,
196198
geo: 'zip',
197199
},
198200
];
@@ -254,19 +256,6 @@ test('autoCompleteZipMerge', (t) => {
254256
population: 154341,
255257
asciiname: 'Springfield',
256258
},
257-
{
258-
id: '62704',
259-
value: 'Springfield, IL 62704',
260-
admin1: 'IL',
261-
asciiname: 'Springfield',
262-
country: 'United States',
263-
cc: 'US',
264-
latitude: 39.771921,
265-
longitude: -89.686047,
266-
timezone: 'America/Chicago',
267-
population: 39831,
268-
geo: 'zip',
269-
},
270259
{
271260
id: '11413',
272261
value: 'Springfield Gardens, NY 11413',
@@ -277,7 +266,20 @@ test('autoCompleteZipMerge', (t) => {
277266
latitude: 40.665415,
278267
longitude: -73.749702,
279268
timezone: 'America/New_York',
280-
population: 38912,
269+
population: 42978,
270+
geo: 'zip',
271+
},
272+
{
273+
id: '62704',
274+
value: 'Springfield, IL 62704',
275+
admin1: 'IL',
276+
asciiname: 'Springfield',
277+
country: 'United States',
278+
cc: 'US',
279+
latitude: 39.771921,
280+
longitude: -89.686047,
281+
timezone: 'America/Chicago',
282+
population: 39157,
281283
geo: 'zip',
282284
},
283285
];
@@ -304,7 +306,7 @@ test('autoCompleteZipMerge2', (t) => {
304306
{i: 5223681, v: 'North Providence, Rhode Island, USA', p: 33835},
305307
{i: 5780020, v: 'Providence, Utah, USA', p: 7124},
306308
{i: 4305295, v: 'Providence, Kentucky, USA', p: 3065},
307-
{i: '27315', v: 'Providence, NC 27315', p: 2243},
309+
{i: '27315', v: 'Providence, NC 27315', p: 1892},
308310
];
309311
t.deepEqual(result, expected);
310312
});
@@ -393,7 +395,7 @@ test('autoCompleteZipPartial', (t) => {
393395
latitude: 41.822232,
394396
longitude: -71.448292,
395397
timezone: 'America/New_York',
396-
population: 43540,
398+
population: 46119,
397399
geo: 'zip',
398400
}, {
399401
id: '02908',
@@ -405,7 +407,7 @@ test('autoCompleteZipPartial', (t) => {
405407
latitude: 41.839296,
406408
longitude: -71.438804,
407409
timezone: 'America/New_York',
408-
population: 37467,
410+
population: 38507,
409411
geo: 'zip',
410412
}];
411413
t.deepEqual(result.slice(0, 2), firstTwo);

src/makeDummyZipsDb.js

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,36 @@
22
import Database from 'better-sqlite3';
33
import path from 'path';
44

5+
/*
6+
.mode insert ZIPCodes_Primary
7+
8+
SELECT ZipCode,CityMixedCase,State,StateFullName,Latitude,Longitude,Elevation,
9+
TimeZone,DayLightSaving,Population
10+
FROM ZIPCodes_Primary
11+
WHERE ZipCode IN (
12+
'65807',
13+
'62704',
14+
'11413',
15+
'01109',
16+
'01089',
17+
'19064',
18+
'02901',
19+
'02902',
20+
'02903',
21+
'02904',
22+
'02905',
23+
'02906',
24+
'02907',
25+
'02908',
26+
'02909',
27+
'02912',
28+
'02918',
29+
'02940',
30+
'27315',
31+
'42450',
32+
'84332'
33+
);
34+
*/
535
export function makeDummyZipsDb(logger, tmpDir) {
636
const testZipsPath = path.join(tmpDir, 'zips.sqlite3');
737
logger.info(testZipsPath);
@@ -13,32 +43,33 @@ export function makeDummyZipsDb(logger, tmpDir) {
1343
StateFullName TEXT,
1444
Latitude decimal(12, 6),
1545
Longitude decimal(12, 6),
46+
Elevation int,
1647
TimeZone char(2),
1748
DayLightSaving char(1),
1849
Population int
1950
);`,
2051

21-
`INSERT INTO ZIPCodes_Primary VALUES ('65807','Springfield','MO','Missouri',37.171008,-93.331857,6,'Y',54952);
22-
INSERT INTO ZIPCodes_Primary VALUES ('62704','Springfield','IL','Illinois',39.771921,-89.686047,6,'Y',39831);
23-
INSERT INTO ZIPCodes_Primary VALUES ('11413','Springfield Gardens','NY','New York',40.665415,-73.749702,5,'Y',38912);
24-
INSERT INTO ZIPCodes_Primary VALUES ('01109','Springfield','MA','Massachusetts',42.118748,-72.549032,5,'Y',30250);
25-
INSERT INTO ZIPCodes_Primary VALUES ('01089','West Springfield','MA','Massachusetts',42.125682,-72.641677,5,'Y',28391);
26-
INSERT INTO ZIPCodes_Primary VALUES ('19064','Springfield','PA','Pennsylvania',39.932544,-75.342975,5,'Y',24459);
27-
INSERT INTO ZIPCodes_Primary VALUES ('02901','Providence','RI','Rhode Island',41.823800000000002086,-71.413300000000008438,'5','Y',0);
28-
INSERT INTO ZIPCodes_Primary VALUES ('02902','Providence','RI','Rhode Island',41.823800000000002086,-71.413300000000008438,'5','Y',0);
29-
INSERT INTO ZIPCodes_Primary VALUES ('02903','Providence','RI','Rhode Island',41.818167000000006083,-71.409728000000001202,'5','Y',10780);
30-
INSERT INTO ZIPCodes_Primary VALUES ('02904','Providence','RI','Rhode Island',41.854637999999999564,-71.437492000000002434,'5','Y',29359);
31-
INSERT INTO ZIPCodes_Primary VALUES ('02905','Providence','RI','Rhode Island',41.786946000000000367,-71.399191999999995772,'5','Y',25223);
32-
INSERT INTO ZIPCodes_Primary VALUES ('02906','Providence','RI','Rhode Island',41.838150000000000616,-71.393139000000003235,'5','Y',28387);
33-
INSERT INTO ZIPCodes_Primary VALUES ('02907','Providence','RI','Rhode Island',41.795126000000006882,-71.424763999999996144,'5','Y',27445);
34-
INSERT INTO ZIPCodes_Primary VALUES ('02908','Providence','RI','Rhode Island',41.839295999999999153,-71.438804000000004634,'5','Y',37467);
35-
INSERT INTO ZIPCodes_Primary VALUES ('02909','Providence','RI','Rhode Island',41.822232000000001406,-71.448291999999993251,'5','Y',43540);
36-
INSERT INTO ZIPCodes_Primary VALUES ('02912','Providence','RI','Rhode Island',41.826254000000000488,-71.402501999999996584,'5','Y',1370);
37-
INSERT INTO ZIPCodes_Primary VALUES ('02918','Providence','RI','Rhode Island',41.844266000000001071,-71.434915999999999414,'5','Y',0);
38-
INSERT INTO ZIPCodes_Primary VALUES ('02940','Providence','RI','Rhode Island',41.823800000000002086,-71.413300000000008438,'5','Y',0);
39-
INSERT INTO ZIPCodes_Primary VALUES ('27315','Providence','NC','North Carolina',36.500447999999998671,-79.393259999999994391,'5','Y',2243);
40-
INSERT INTO ZIPCodes_Primary VALUES ('42450','Providence','KY','Kentucky',37.391308000000003097,-87.762130999999996561,'6','Y',4063);
41-
INSERT INTO ZIPCodes_Primary VALUES ('84332','Providence','UT','Utah',41.673151999999999972,-111.81449999999999445,'7','Y',7218);
52+
`INSERT INTO ZIPCodes_Primary VALUES('01089','West Springfield','MA','Massachusetts',42.125681999999997628,-72.641676999999997832,179,'5','Y',28835);
53+
INSERT INTO ZIPCodes_Primary VALUES('01109','Springfield','MA','Massachusetts',42.118747999999994746,-72.549031999999993303,209,'5','Y',30968);
54+
INSERT INTO ZIPCodes_Primary VALUES('02901','Providence','RI','Rhode Island',41.823800000000002086,-71.413300000000008438,9,'5','Y',0);
55+
INSERT INTO ZIPCodes_Primary VALUES('02902','Providence','RI','Rhode Island',41.823800000000002086,-71.413300000000008438,9,'5','Y',0);
56+
INSERT INTO ZIPCodes_Primary VALUES('02903','Providence','RI','Rhode Island',41.818167000000006083,-71.409728000000001202,26,'5','Y',13264);
57+
INSERT INTO ZIPCodes_Primary VALUES('02904','Providence','RI','Rhode Island',41.854637999999999564,-71.437492000000002434,75,'5','Y',31542);
58+
INSERT INTO ZIPCodes_Primary VALUES('02905','Providence','RI','Rhode Island',41.786946000000000367,-71.399191999999995772,58,'5','Y',26334);
59+
INSERT INTO ZIPCodes_Primary VALUES('02906','Providence','RI','Rhode Island',41.838150000000000616,-71.393139000000003235,89,'5','Y',25559);
60+
INSERT INTO ZIPCodes_Primary VALUES('02907','Providence','RI','Rhode Island',41.795126000000006882,-71.424763999999996144,61,'5','Y',29827);
61+
INSERT INTO ZIPCodes_Primary VALUES('02908','Providence','RI','Rhode Island',41.839295999999999153,-71.438804000000004634,120,'5','Y',38507);
62+
INSERT INTO ZIPCodes_Primary VALUES('02909','Providence','RI','Rhode Island',41.822232000000001406,-71.448291999999993251,89,'5','Y',46119);
63+
INSERT INTO ZIPCodes_Primary VALUES('02912','Providence','RI','Rhode Island',41.826254000000000488,-71.402501999999996584,118,'5','Y',4739);
64+
INSERT INTO ZIPCodes_Primary VALUES('02918','Providence','RI','Rhode Island',41.844266000000001071,-71.434915999999999414,185,'5','Y',3125);
65+
INSERT INTO ZIPCodes_Primary VALUES('02940','Providence','RI','Rhode Island',41.823800000000002086,-71.413300000000008438,9,'5','Y',0);
66+
INSERT INTO ZIPCodes_Primary VALUES('11413','Springfield Gardens','NY','New York',40.665415000000004752,-73.749701999999999202,13,'5','Y',42978);
67+
INSERT INTO ZIPCodes_Primary VALUES('19064','Springfield','PA','Pennsylvania',39.932544000000000039,-75.342974999999992036,270,'5','Y',25045);
68+
INSERT INTO ZIPCodes_Primary VALUES('27315','Providence','NC','North Carolina',36.500447999999998671,-79.393259999999994391,474,'5','Y',1892);
69+
INSERT INTO ZIPCodes_Primary VALUES('42450','Providence','KY','Kentucky',37.391308000000003097,-87.762130999999996561,416,'6','Y',3909);
70+
INSERT INTO ZIPCodes_Primary VALUES('62704','Springfield','IL','Illinois',39.771920999999998969,-89.686047000000002071,579,'6','Y',39157);
71+
INSERT INTO ZIPCodes_Primary VALUES('65807','Springfield','MO','Missouri',37.171007999999998716,-93.331856999999995849,1239,'6','Y',55168);
72+
INSERT INTO ZIPCodes_Primary VALUES('84332','Providence','UT','Utah',41.673151999999999972,-111.81449999999999445,4650,'7','Y',8238);
4273
`,
4374
`CREATE VIRTUAL TABLE ZIPCodes_CityFullText
4475
USING fts4(ZipCode,CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving,Population);`,

zips-dummy.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CREATE TABLE ZIPCodes_Primary (
44
State char(2),
55
Latitude decimal(12, 6),
66
Longitude decimal(12, 6),
7+
Elevation int NULL,
78
TimeZone char(2) NULL,
89
DayLightSaving char(1) NULL,
910
Population int NULL

0 commit comments

Comments
 (0)