Hebcal ES6 interface to GeoNames and USA ZIP code SQLite databases
npm install @hebcal/geo-sqliteThis package is designed for the hebcal.com and may not be generally reusable.
It requires two separate databases, one made from GeoNames.org data (available
via a Creative Commons license) and a USA ZIP code database (commercial license).
bash
$ npm install @hebcal/geo-sqlite
$ ./node_modules/.bin/download-and-make-dbs
`Synopsis
`js
import {Location} from '@hebcal/core';
import {GeoDb} from '@hebcal/geo-sqlite';
import pino from 'pino';
const logger = pino();const db = new GeoDb(logger, 'zips.sqlite3', 'geonames.sqlite3');
const loc1 = db.lookupZip('90210'); // Beverly Hills, California
const loc2 = db.lookupGeoname(293397); // Tel Aviv
const loc3 = db.lookupLegacyCity('IL-Netanya');
db.close();
`Classes
- GeoDb
Wrapper around sqlite databases
Functions
- buildGeonamesSqlite(opts)
Builds geonames.sqlite3 from files downloaded from geonames.org
- doSql(logger, db, ...sqls)
- doFile(logger, db, infile, tableName, expectedFields, callback)
GeoDb
Wrapper around sqlite databasesKind: global class
* GeoDb
* new GeoDb(logger, zipsFilename, geonamesFilename)
* _instance_
* .zipCache : Map.<string, Location>
* .geonamesCache : Map.<number, Location>
* .legacyCities : Map.<string, number>
* .countryNames : Map.<string, string>
* .close()
* .lookupZip(zip) ⇒ Location
* .lookupGeoname(geonameid) ⇒ Location
* .lookupLegacyCity(cityName) ⇒ Location
* .autoComplete(qraw, latlong) ⇒ Array.<Object>
* .cacheZips()
* .cacheGeonames()
* _static_
* [.transliterate(source, [options])](#GeoDb.transliterate) ⇒ string
* .geonameCityDescr(cityName, admin1, countryName) ⇒ string
* .version()
$3
| Param | Type |
| --- | --- |
| logger | any |
| zipsFilename | string |
| geonamesFilename | string |
$3
Kind: instance property of GeoDb
$3
Kind: instance property of GeoDb
$3
Kind: instance property of GeoDb
$3
Kind: instance property of GeoDb
$3
Closes database handlesKind: instance method of GeoDb
$3
Kind: instance method of GeoDb| Param | Type |
| --- | --- |
| zip | string |
$3
Kind: instance method of GeoDb| Param | Type |
| --- | --- |
| geonameid | number |
$3
Kind: instance method of GeoDb| Param | Type |
| --- | --- |
| cityName | string |
$3
Generates autocomplete results based on a query stringKind: instance method of GeoDb
| Param | Type | Default |
| --- | --- | --- |
| qraw | string | |
| latlong | boolean | false |
$3
Reads entire ZIP database and caches in-memoryKind: instance method of GeoDb
$3
Reads entire geonames database and caches in-memoryKind: instance method of GeoDb
$3
Convenience wrapper of the transliterate function from transliteration npm package.
Transliterate the string source and return the result.Kind: static method of GeoDb
| Param | Type |
| --- | --- |
| source | string |
| [options] | any |
$3
Builds a city description from geonameid string componentsKind: static method of GeoDb
| Param | Type | Description |
| --- | --- | --- |
| cityName | string | e.g. 'Tel Aviv' or 'Chicago' |
| admin1 | string | e.g. 'England' or 'Massachusetts' |
| countryName | string | full country name, e.g. 'Israel' or 'United States' |
$3
Returns the version of the GeoDb packageKind: static method of GeoDb
buildGeonamesSqlite(opts)
Builds geonames.sqlite3` from files downloaded from geonames.orgKind: global function
| Param | Type |
| --- | --- |
| opts | any |
| Param | Type |
| --- | --- |
| logger | pino.Logger |
| db | Database |
| ...sqls | string |
| Param | Type |
| --- | --- |
| logger | pino.Logger |
| db | Database |
| infile | string |
| tableName | string |
| expectedFields | number |
| callback | function |