Skip to content

Commit

Permalink
Support elevation for future potential use in suntimes
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Nov 13, 2023
1 parent 61a0125 commit aa5424c
Show file tree
Hide file tree
Showing 6 changed files with 641 additions and 410 deletions.
886 changes: 535 additions & 351 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hebcal/geo-sqlite",
"version": "4.9.3",
"version": "4.10.0",
"author": "Michael J. Radwin (https://github.com/mjradwin)",
"keywords": [
"hebcal"
Expand Down Expand Up @@ -28,11 +28,11 @@
"geo-sqlite.d.ts"
],
"dependencies": {
"@hebcal/cities": "^3.2.0",
"@hebcal/core": "^4.3.0",
"better-sqlite3": "^8.5.0",
"pino": "^8.15.0",
"pino-pretty": "^10.2.0",
"@hebcal/cities": "^3.2.2",
"@hebcal/core": "^4.5.1",
"better-sqlite3": "^9.1.1",
"pino": "^8.16.1",
"pino-pretty": "^10.2.3",
"transliteration": "^2.3.5"
},
"scripts": {
Expand All @@ -46,18 +46,18 @@
},
"license": "BSD-2-Clause",
"devDependencies": {
"@babel/core": "^7.22.10",
"@babel/preset-env": "^7.22.10",
"@babel/register": "^7.22.5",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.1.0",
"@babel/core": "^7.23.3",
"@babel/preset-env": "^7.23.3",
"@babel/register": "^7.22.15",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"ava": "^5.3.1",
"eslint": "^8.47.0",
"eslint": "^8.53.0",
"eslint-config-google": "^0.14.0",
"jsdoc": "^4.0.2",
"jsdoc-to-markdown": "^8.0.0",
"rollup": "^3.28.0"
"rollup": "^4.4.0"
}
}
17 changes: 15 additions & 2 deletions src/geodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const GEONAME_SQL = `SELECT
g.latitude as latitude,
g.longitude as longitude,
g.population as population,
g.gtopo30 as elevation,
g.timezone as timezone
FROM geoname g
LEFT JOIN country c on g.country = c.iso
Expand All @@ -31,16 +32,19 @@ const GEONAME_ALL_SQL = `SELECT
g.latitude as latitude,
g.longitude as longitude,
g.population as population,
g.gtopo30 as elevation,
g.timezone as timezone
FROM geoname g
LEFT JOIN country c on g.country = c.iso
LEFT JOIN admin1 a on g.country||'.'||g.admin1 = a.key
`;

const ZIPCODE_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving,Population
const ZIPCODE_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,Elevation,
TimeZone,DayLightSaving,Population
FROM ZIPCodes_Primary WHERE ZipCode = ?`;

const ZIPCODE_ALL_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving,Population
const ZIPCODE_ALL_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,Elevation,
TimeZone,DayLightSaving,Population
FROM ZIPCodes_Primary`;

const ZIP_COMPLETE_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving,Population
Expand Down Expand Up @@ -205,6 +209,9 @@ export class GeoDb {
location.geo = 'zip';
location.zip = zip;
location.population = result.Population;
if (result.Elevation) {
location.elevation = result.Elevation;
}
return location;
}

Expand Down Expand Up @@ -296,6 +303,9 @@ export class GeoDb {
if (result.population) {
location.population = result.population;
}
if (result.elevation) {
location.elevation = result.elevation;
}
return location;
}

Expand Down Expand Up @@ -337,6 +347,9 @@ export class GeoDb {
population: res.Population,
geo: 'zip',
};
if (res.Elevation) {
obj.elevation = res.Elevation;
}
return obj;
}

Expand Down
44 changes: 23 additions & 21 deletions src/geodb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ test('geoname', (t) => {
geo: 'geoname',
geonameid: 4119403,
population: 197992,
elevation: 105,
admin1: 'Arkansas',
};
t.deepEqual(Object.assign({}, loc), expected);
Expand Down Expand Up @@ -119,7 +120,8 @@ test('zip', (t) => {
stateName: 'Rhode Island',
geo: 'zip',
zip: '02912',
population: 1370,
population: 4739,
elevation: 118,
};
t.deepEqual(Object.assign({}, loc), expected);
});
Expand Down Expand Up @@ -159,7 +161,7 @@ test('autoCompleteZip', (t) => {
latitude: 37.171008,
longitude: -93.331857,
timezone: 'America/Chicago',
population: 54952,
population: 55168,
geo: 'zip',
},
{
Expand All @@ -172,7 +174,7 @@ test('autoCompleteZip', (t) => {
latitude: 39.771921,
longitude: -89.686047,
timezone: 'America/Chicago',
population: 39831,
population: 39157,
geo: 'zip',
},
];
Expand All @@ -192,7 +194,7 @@ test('autoCompleteZipPlus4', (t) => {
latitude: 39.771921,
longitude: -89.686047,
timezone: 'America/Chicago',
population: 39831,
population: 39157,
geo: 'zip',
},
];
Expand Down Expand Up @@ -254,19 +256,6 @@ test('autoCompleteZipMerge', (t) => {
population: 154341,
asciiname: 'Springfield',
},
{
id: '62704',
value: 'Springfield, IL 62704',
admin1: 'IL',
asciiname: 'Springfield',
country: 'United States',
cc: 'US',
latitude: 39.771921,
longitude: -89.686047,
timezone: 'America/Chicago',
population: 39831,
geo: 'zip',
},
{
id: '11413',
value: 'Springfield Gardens, NY 11413',
Expand All @@ -277,7 +266,20 @@ test('autoCompleteZipMerge', (t) => {
latitude: 40.665415,
longitude: -73.749702,
timezone: 'America/New_York',
population: 38912,
population: 42978,
geo: 'zip',
},
{
id: '62704',
value: 'Springfield, IL 62704',
admin1: 'IL',
asciiname: 'Springfield',
country: 'United States',
cc: 'US',
latitude: 39.771921,
longitude: -89.686047,
timezone: 'America/Chicago',
population: 39157,
geo: 'zip',
},
];
Expand All @@ -304,7 +306,7 @@ test('autoCompleteZipMerge2', (t) => {
{i: 5223681, v: 'North Providence, Rhode Island, USA', p: 33835},
{i: 5780020, v: 'Providence, Utah, USA', p: 7124},
{i: 4305295, v: 'Providence, Kentucky, USA', p: 3065},
{i: '27315', v: 'Providence, NC 27315', p: 2243},
{i: '27315', v: 'Providence, NC 27315', p: 1892},
];
t.deepEqual(result, expected);
});
Expand Down Expand Up @@ -393,7 +395,7 @@ test('autoCompleteZipPartial', (t) => {
latitude: 41.822232,
longitude: -71.448292,
timezone: 'America/New_York',
population: 43540,
population: 46119,
geo: 'zip',
}, {
id: '02908',
Expand All @@ -405,7 +407,7 @@ test('autoCompleteZipPartial', (t) => {
latitude: 41.839296,
longitude: -71.438804,
timezone: 'America/New_York',
population: 37467,
population: 38507,
geo: 'zip',
}];
t.deepEqual(result.slice(0, 2), firstTwo);
Expand Down
73 changes: 52 additions & 21 deletions src/makeDummyZipsDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@
import Database from 'better-sqlite3';
import path from 'path';

/*
.mode insert ZIPCodes_Primary
SELECT ZipCode,CityMixedCase,State,StateFullName,Latitude,Longitude,Elevation,
TimeZone,DayLightSaving,Population
FROM ZIPCodes_Primary
WHERE ZipCode IN (
'65807',
'62704',
'11413',
'01109',
'01089',
'19064',
'02901',
'02902',
'02903',
'02904',
'02905',
'02906',
'02907',
'02908',
'02909',
'02912',
'02918',
'02940',
'27315',
'42450',
'84332'
);
*/
export function makeDummyZipsDb(logger, tmpDir) {
const testZipsPath = path.join(tmpDir, 'zips.sqlite3');
logger.info(testZipsPath);
Expand All @@ -13,32 +43,33 @@ export function makeDummyZipsDb(logger, tmpDir) {
StateFullName TEXT,
Latitude decimal(12, 6),
Longitude decimal(12, 6),
Elevation int,
TimeZone char(2),
DayLightSaving char(1),
Population int
);`,

`INSERT INTO ZIPCodes_Primary VALUES ('65807','Springfield','MO','Missouri',37.171008,-93.331857,6,'Y',54952);
INSERT INTO ZIPCodes_Primary VALUES ('62704','Springfield','IL','Illinois',39.771921,-89.686047,6,'Y',39831);
INSERT INTO ZIPCodes_Primary VALUES ('11413','Springfield Gardens','NY','New York',40.665415,-73.749702,5,'Y',38912);
INSERT INTO ZIPCodes_Primary VALUES ('01109','Springfield','MA','Massachusetts',42.118748,-72.549032,5,'Y',30250);
INSERT INTO ZIPCodes_Primary VALUES ('01089','West Springfield','MA','Massachusetts',42.125682,-72.641677,5,'Y',28391);
INSERT INTO ZIPCodes_Primary VALUES ('19064','Springfield','PA','Pennsylvania',39.932544,-75.342975,5,'Y',24459);
INSERT INTO ZIPCodes_Primary VALUES ('02901','Providence','RI','Rhode Island',41.823800000000002086,-71.413300000000008438,'5','Y',0);
INSERT INTO ZIPCodes_Primary VALUES ('02902','Providence','RI','Rhode Island',41.823800000000002086,-71.413300000000008438,'5','Y',0);
INSERT INTO ZIPCodes_Primary VALUES ('02903','Providence','RI','Rhode Island',41.818167000000006083,-71.409728000000001202,'5','Y',10780);
INSERT INTO ZIPCodes_Primary VALUES ('02904','Providence','RI','Rhode Island',41.854637999999999564,-71.437492000000002434,'5','Y',29359);
INSERT INTO ZIPCodes_Primary VALUES ('02905','Providence','RI','Rhode Island',41.786946000000000367,-71.399191999999995772,'5','Y',25223);
INSERT INTO ZIPCodes_Primary VALUES ('02906','Providence','RI','Rhode Island',41.838150000000000616,-71.393139000000003235,'5','Y',28387);
INSERT INTO ZIPCodes_Primary VALUES ('02907','Providence','RI','Rhode Island',41.795126000000006882,-71.424763999999996144,'5','Y',27445);
INSERT INTO ZIPCodes_Primary VALUES ('02908','Providence','RI','Rhode Island',41.839295999999999153,-71.438804000000004634,'5','Y',37467);
INSERT INTO ZIPCodes_Primary VALUES ('02909','Providence','RI','Rhode Island',41.822232000000001406,-71.448291999999993251,'5','Y',43540);
INSERT INTO ZIPCodes_Primary VALUES ('02912','Providence','RI','Rhode Island',41.826254000000000488,-71.402501999999996584,'5','Y',1370);
INSERT INTO ZIPCodes_Primary VALUES ('02918','Providence','RI','Rhode Island',41.844266000000001071,-71.434915999999999414,'5','Y',0);
INSERT INTO ZIPCodes_Primary VALUES ('02940','Providence','RI','Rhode Island',41.823800000000002086,-71.413300000000008438,'5','Y',0);
INSERT INTO ZIPCodes_Primary VALUES ('27315','Providence','NC','North Carolina',36.500447999999998671,-79.393259999999994391,'5','Y',2243);
INSERT INTO ZIPCodes_Primary VALUES ('42450','Providence','KY','Kentucky',37.391308000000003097,-87.762130999999996561,'6','Y',4063);
INSERT INTO ZIPCodes_Primary VALUES ('84332','Providence','UT','Utah',41.673151999999999972,-111.81449999999999445,'7','Y',7218);
`INSERT INTO ZIPCodes_Primary VALUES('01089','West Springfield','MA','Massachusetts',42.125681999999997628,-72.641676999999997832,179,'5','Y',28835);
INSERT INTO ZIPCodes_Primary VALUES('01109','Springfield','MA','Massachusetts',42.118747999999994746,-72.549031999999993303,209,'5','Y',30968);
INSERT INTO ZIPCodes_Primary VALUES('02901','Providence','RI','Rhode Island',41.823800000000002086,-71.413300000000008438,9,'5','Y',0);
INSERT INTO ZIPCodes_Primary VALUES('02902','Providence','RI','Rhode Island',41.823800000000002086,-71.413300000000008438,9,'5','Y',0);
INSERT INTO ZIPCodes_Primary VALUES('02903','Providence','RI','Rhode Island',41.818167000000006083,-71.409728000000001202,26,'5','Y',13264);
INSERT INTO ZIPCodes_Primary VALUES('02904','Providence','RI','Rhode Island',41.854637999999999564,-71.437492000000002434,75,'5','Y',31542);
INSERT INTO ZIPCodes_Primary VALUES('02905','Providence','RI','Rhode Island',41.786946000000000367,-71.399191999999995772,58,'5','Y',26334);
INSERT INTO ZIPCodes_Primary VALUES('02906','Providence','RI','Rhode Island',41.838150000000000616,-71.393139000000003235,89,'5','Y',25559);
INSERT INTO ZIPCodes_Primary VALUES('02907','Providence','RI','Rhode Island',41.795126000000006882,-71.424763999999996144,61,'5','Y',29827);
INSERT INTO ZIPCodes_Primary VALUES('02908','Providence','RI','Rhode Island',41.839295999999999153,-71.438804000000004634,120,'5','Y',38507);
INSERT INTO ZIPCodes_Primary VALUES('02909','Providence','RI','Rhode Island',41.822232000000001406,-71.448291999999993251,89,'5','Y',46119);
INSERT INTO ZIPCodes_Primary VALUES('02912','Providence','RI','Rhode Island',41.826254000000000488,-71.402501999999996584,118,'5','Y',4739);
INSERT INTO ZIPCodes_Primary VALUES('02918','Providence','RI','Rhode Island',41.844266000000001071,-71.434915999999999414,185,'5','Y',3125);
INSERT INTO ZIPCodes_Primary VALUES('02940','Providence','RI','Rhode Island',41.823800000000002086,-71.413300000000008438,9,'5','Y',0);
INSERT INTO ZIPCodes_Primary VALUES('11413','Springfield Gardens','NY','New York',40.665415000000004752,-73.749701999999999202,13,'5','Y',42978);
INSERT INTO ZIPCodes_Primary VALUES('19064','Springfield','PA','Pennsylvania',39.932544000000000039,-75.342974999999992036,270,'5','Y',25045);
INSERT INTO ZIPCodes_Primary VALUES('27315','Providence','NC','North Carolina',36.500447999999998671,-79.393259999999994391,474,'5','Y',1892);
INSERT INTO ZIPCodes_Primary VALUES('42450','Providence','KY','Kentucky',37.391308000000003097,-87.762130999999996561,416,'6','Y',3909);
INSERT INTO ZIPCodes_Primary VALUES('62704','Springfield','IL','Illinois',39.771920999999998969,-89.686047000000002071,579,'6','Y',39157);
INSERT INTO ZIPCodes_Primary VALUES('65807','Springfield','MO','Missouri',37.171007999999998716,-93.331856999999995849,1239,'6','Y',55168);
INSERT INTO ZIPCodes_Primary VALUES('84332','Providence','UT','Utah',41.673151999999999972,-111.81449999999999445,4650,'7','Y',8238);
`,
`CREATE VIRTUAL TABLE ZIPCodes_CityFullText
USING fts4(ZipCode,CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving,Population);`,
Expand Down
1 change: 1 addition & 0 deletions zips-dummy.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CREATE TABLE ZIPCodes_Primary (
State char(2),
Latitude decimal(12, 6),
Longitude decimal(12, 6),
Elevation int NULL,
TimeZone char(2) NULL,
DayLightSaving char(1) NULL,
Population int NULL
Expand Down

0 comments on commit aa5424c

Please sign in to comment.