@hebcal/geo-sqlite 5.6.0 → 5.7.0
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/bin/build-geonames-sqlite +33 -14
- package/bin/download-and-make-dbs +10 -3
- package/dist/index.js +31 -4
- package/package.json +6 -5
|
@@ -2,32 +2,51 @@
|
|
|
2
2
|
|
|
3
3
|
import {buildGeonamesSqlite} from '@hebcal/geo-sqlite';
|
|
4
4
|
import {pino} from 'pino';
|
|
5
|
+
import minimist from 'minimist';
|
|
6
|
+
|
|
7
|
+
const argv = minimist(process.argv.slice(2), {
|
|
8
|
+
boolean: ['help', 'quiet'],
|
|
9
|
+
string: ['population'],
|
|
10
|
+
alias: {h: 'help', q: 'quiet'},
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
if (argv.help) {
|
|
14
|
+
usage();
|
|
15
|
+
process.exit(0);
|
|
16
|
+
}
|
|
5
17
|
|
|
6
18
|
const logger = pino({
|
|
7
|
-
|
|
19
|
+
level: argv.quiet ? 'warn' : 'info',
|
|
8
20
|
transport: {
|
|
9
21
|
target: 'pino-pretty',
|
|
10
22
|
options: {translateTime: 'SYS:standard', ignore: 'pid,hostname'},
|
|
11
23
|
},
|
|
12
24
|
});
|
|
13
25
|
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
console.error(`Usage: build-geonames-sqlite geonames.sqlite3 ${infiles}`);
|
|
26
|
+
const args = argv._;
|
|
27
|
+
if (args.length !== 7) {
|
|
28
|
+
usage();
|
|
18
29
|
process.exit(1);
|
|
19
30
|
}
|
|
20
31
|
|
|
21
|
-
const
|
|
22
|
-
dbFilename:
|
|
23
|
-
countryInfotxt:
|
|
24
|
-
cities5000txt:
|
|
25
|
-
citiesPatch:
|
|
26
|
-
admin1CodesASCIItxt:
|
|
27
|
-
ILtxt:
|
|
28
|
-
ILalternate:
|
|
32
|
+
const options = {
|
|
33
|
+
dbFilename: args[0],
|
|
34
|
+
countryInfotxt: args[1],
|
|
35
|
+
cities5000txt: args[2],
|
|
36
|
+
citiesPatch: args[3],
|
|
37
|
+
admin1CodesASCIItxt: args[4],
|
|
38
|
+
ILtxt: args[5],
|
|
39
|
+
ILalternate: args[6],
|
|
29
40
|
logger: logger,
|
|
30
41
|
};
|
|
31
|
-
|
|
42
|
+
if (argv.population) {
|
|
43
|
+
options.population = +argv.population;
|
|
44
|
+
}
|
|
45
|
+
buildGeonamesSqlite(options).then(() => {
|
|
32
46
|
console.log('Done!');
|
|
33
47
|
});
|
|
48
|
+
|
|
49
|
+
function usage() {
|
|
50
|
+
const infiles = 'countryInfo.txt cities5000.txt cities-patch.txt admin1CodesASCII.txt IL.txt IL-alternatenames.txt';
|
|
51
|
+
console.log(`Usage: build-geonames-sqlite geonames.sqlite3 ${infiles}`);
|
|
52
|
+
}
|
|
@@ -5,14 +5,20 @@ set -x
|
|
|
5
5
|
TMPDIR=`mktemp -d /tmp/geonames.XXXXXX`
|
|
6
6
|
CURDIR=`pwd`
|
|
7
7
|
|
|
8
|
+
# optionally specify minimum city population size with POPULATION=750
|
|
9
|
+
POPULATION=${POPULATION:-"0"}
|
|
10
|
+
|
|
11
|
+
# optionally specify a geonames export file such as cities500 or cities5000
|
|
12
|
+
CITIES=${CITIES:-"cities1000"}
|
|
13
|
+
|
|
8
14
|
curl -o $TMPDIR/countryInfo.txt http://download.geonames.org/export/dump/countryInfo.txt
|
|
9
15
|
curl -o $TMPDIR/admin1CodesASCII.txt http://download.geonames.org/export/dump/admin1CodesASCII.txt
|
|
10
|
-
curl -o $TMPDIR
|
|
16
|
+
curl -o $TMPDIR/$CITIES.zip http://download.geonames.org/export/dump/$CITIES.zip
|
|
11
17
|
curl -o $TMPDIR/IL.zip http://download.geonames.org/export/dump/IL.zip
|
|
12
18
|
curl -o $TMPDIR/alt-IL.zip http://download.geonames.org/export/dump/alternatenames/IL.zip
|
|
13
19
|
|
|
14
20
|
cd $TMPDIR
|
|
15
|
-
unzip
|
|
21
|
+
unzip $CITIES.zip
|
|
16
22
|
unzip alt-IL.zip
|
|
17
23
|
mv IL.txt alt-IL.txt
|
|
18
24
|
rm readme.txt
|
|
@@ -22,9 +28,10 @@ cd $CURDIR
|
|
|
22
28
|
|
|
23
29
|
#npx --package '@hebcal/geo-sqlite' build-geonames-sqlite \
|
|
24
30
|
$CURDIR/node_modules/.bin/build-geonames-sqlite \
|
|
31
|
+
--population=$POPULATION \
|
|
25
32
|
$CURDIR/geonames.sqlite3 \
|
|
26
33
|
$TMPDIR/countryInfo.txt \
|
|
27
|
-
$TMPDIR
|
|
34
|
+
"$TMPDIR/$CITIES.txt" \
|
|
28
35
|
"$CURDIR/node_modules/@hebcal/geo-sqlite/cities-patch.txt" \
|
|
29
36
|
$TMPDIR/admin1CodesASCII.txt \
|
|
30
37
|
$TMPDIR/IL.txt \
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @hebcal/geo-sqlite v5.
|
|
1
|
+
/*! @hebcal/geo-sqlite v5.7.0 */
|
|
2
2
|
import Database from 'better-sqlite3';
|
|
3
3
|
import QuickLRU from 'quick-lru';
|
|
4
4
|
import { Location, Locale } from '@hebcal/core';
|
|
@@ -511,7 +511,7 @@ function munge(s) {
|
|
|
511
511
|
}
|
|
512
512
|
|
|
513
513
|
// DO NOT EDIT THIS AUTO-GENERATED FILE!
|
|
514
|
-
const version = '5.
|
|
514
|
+
const version = '5.7.0';
|
|
515
515
|
|
|
516
516
|
const GEONAME_SQL = `SELECT
|
|
517
517
|
g.name as name,
|
|
@@ -1044,6 +1044,17 @@ class GeoDb {
|
|
|
1044
1044
|
}
|
|
1045
1045
|
}
|
|
1046
1046
|
|
|
1047
|
+
const fcodeKeep = {
|
|
1048
|
+
PPL: true, // populated place a city, town, village, or other agglomeration of
|
|
1049
|
+
PPLA: true, // seat of a first-order administrative division seat of a first-order administrative division (PPLC takes precedence over PPLA)
|
|
1050
|
+
PPLA2: true, // seat of a second-order administrative division
|
|
1051
|
+
PPLA3: true, // seat of a third-order administrative division
|
|
1052
|
+
PPLC: true, // capital of a political entity
|
|
1053
|
+
PPLL: true, // populated locality an area similar to a locality but with a small
|
|
1054
|
+
PPLX: true, // section of populated place
|
|
1055
|
+
STLMT: true, // israeli settlement
|
|
1056
|
+
};
|
|
1057
|
+
|
|
1047
1058
|
/**
|
|
1048
1059
|
* Builds `geonames.sqlite3` from files downloaded from geonames.org
|
|
1049
1060
|
* @param {any} opts
|
|
@@ -1117,11 +1128,27 @@ async function buildGeonamesSqlite(opts) {
|
|
|
1117
1128
|
a[3] = '';
|
|
1118
1129
|
return true;
|
|
1119
1130
|
};
|
|
1120
|
-
|
|
1131
|
+
const minPopulation = opts.population;
|
|
1132
|
+
const citiesFilter = (a) => {
|
|
1133
|
+
const fcode = a[7];
|
|
1134
|
+
logger.debug(a[0], a[1], fcode);
|
|
1135
|
+
if (!fcodeKeep[fcode]) {
|
|
1136
|
+
return false;
|
|
1137
|
+
}
|
|
1138
|
+
if (minPopulation) {
|
|
1139
|
+
const population = a[14];
|
|
1140
|
+
if (fcode === 'PPL' && population && population < minPopulation) {
|
|
1141
|
+
return false;
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
a[3] = '';
|
|
1145
|
+
return true;
|
|
1146
|
+
};
|
|
1147
|
+
await doFile(logger, db, cities5000txt, 'geoname', 19, citiesFilter);
|
|
1121
1148
|
await doFile(logger, db, citiesPatch, 'geoname', 19, truncateAlternateNames);
|
|
1122
1149
|
await doFile(logger, db, ILtxt, 'geoname', 19, (a) => {
|
|
1123
1150
|
a[3] = '';
|
|
1124
|
-
return a[6] == 'P' &&
|
|
1151
|
+
return a[6] == 'P' && fcodeKeep[a[7]];
|
|
1125
1152
|
});
|
|
1126
1153
|
|
|
1127
1154
|
doSql(logger, db,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hebcal/geo-sqlite",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.0",
|
|
4
4
|
"author": "Michael J. Radwin (https://github.com/mjradwin)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hebcal"
|
|
@@ -38,10 +38,11 @@
|
|
|
38
38
|
"@hebcal/cities": "^6.1.0",
|
|
39
39
|
"@hebcal/core": "^6.0.6",
|
|
40
40
|
"better-sqlite3": "^12.5.0",
|
|
41
|
+
"minimist": "^1.2.8",
|
|
41
42
|
"pino": "^10.1.0",
|
|
42
43
|
"pino-pretty": "^13.1.3",
|
|
43
44
|
"quick-lru": "^7.3.0",
|
|
44
|
-
"transliteration": "^2.
|
|
45
|
+
"transliteration": "^2.6.0"
|
|
45
46
|
},
|
|
46
47
|
"scripts": {
|
|
47
48
|
"build:rollup": "rollup -c",
|
|
@@ -59,16 +60,16 @@
|
|
|
59
60
|
},
|
|
60
61
|
"license": "BSD-2-Clause",
|
|
61
62
|
"devDependencies": {
|
|
62
|
-
"@eslint/js": "^9.39.
|
|
63
|
+
"@eslint/js": "^9.39.2",
|
|
63
64
|
"@rollup/plugin-json": "^6.1.0",
|
|
64
65
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
65
66
|
"ava": "^6.4.1",
|
|
66
|
-
"eslint": "^9.39.
|
|
67
|
+
"eslint": "^9.39.2",
|
|
67
68
|
"eslint-config-google": "^0.14.0",
|
|
68
69
|
"eslint-plugin-n": "^17.23.1",
|
|
69
70
|
"globals": "^16.5.0",
|
|
70
71
|
"jsdoc": "^4.0.5",
|
|
71
72
|
"jsdoc-to-markdown": "^9.1.3",
|
|
72
|
-
"rollup": "^4.53.
|
|
73
|
+
"rollup": "^4.53.5"
|
|
73
74
|
}
|
|
74
75
|
}
|