Skip to content

Node-NTRIP/geonames

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;
}