@ntrip/geonames
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

GeoNames.org Data File Parser

Helper class to read GeoNames data files with 0 dependencies.

import {GeoNames} from 'geonames';

GeoNames

const geoNames = new GeoNames('path/to/geonames.txt');

Methods

async *geoNames[Symbol.asyncIterator]()

Generator function to get list of places found in the data file without loading all into memory at once.

for await (let place: Place of geoNames) {
    console.log(place.name);
}
geoNames.stream()
geoNames.nearest(to: {latitude: number, longitude: number})

Finds the place nearest to the location provided, without loading all places into memory.

let nearest = geoNames.nearest({latitude: 53.33, longitude: -6.24});
console.log(`${nearest.name}, ${nearest.countryCode}`) // Dublin, IE

Place

class Place {
    id: number;

    name: string;
    asciiName: string;
    alternativeNames: string[];

    latitude: number;
    longitude: number;

    featureClass: string;
    featureCode: string;

    countryCode: string;
    alternativeCountryCode: string;

    adminCode1: string;
    adminCode2: string;
    adminCode3: string;
    adminCode4: string;

    population: number;

    elevation: number;
    digitalElevationModel: number;

    timezone: string;
    modificationDate: Date;

    // Distance of place provided location 
    distance(to: {latitude: number, longitude: number}): number;
}

Readme

Keywords

Package Sidebar

Install

npm i @ntrip/geonames

Weekly Downloads

4

Version

1.0.0

License

MIT

Unpacked Size

15 kB

Total Files

4

Last publish

Collaborators

  • nebkat