/metro-ru

Russian Cities metro (subway) stations data with methods for calculating a distance between given coordinate and station (using Haversine formula)

Primary LanguageTypeScriptMIT LicenseMIT

Metro RU

Module type: MinChrome Module type: MinNode Module type: CJS+ESM Module type: target-ES2016

Russian Cities metro (subway) stations data with methods for calculating a distance between given coordinate and station (using Haversine formula):

  • Moscow Metro
  • Saint Petersburg Metro
  • Kazan Metro
  • Ekaterinburg Metro
  • in progress Nizhny Novgorod Metro
  • in progress Novosibirsk Metro
  • in progress Samara Metro

Use

with HTML

<script src="https://cdn.jsdelivr.net/npm/@riaskov/metro-ru@1/dist/browser/metro-ru.min.js"></script>

with Node.js

package.json:

"dependencies": {
  "@riaskov/metro-ru": "^1.x.x"
}

your code:

import { getClosestStations } from '@riaskov/metro-ru'

console.log(getClosestStations(City.Moscow, 55.640918, 37.754337, 2))

TODO

  • add English translation of stations names
  • add an address of each station
  • create super-minimal (<10 KBytes; now it's 70 KBytes) version for browser
  • add mocha/chai tests

API

Data structures

Available cities:

enum City {
    Moscow = "Moscow",
    SaintPetersburg = "SaintPetersburg",
    Ekaterinburg = "Ekaterinburg",
    Kazan = "Kazan"
}

Metro station description:

interface MetroStation {
    name: string
    nameTranslit: string
    lat: number
    lon: number
    lineColor: string
    lineName: string
    lineNameTranslit: string
    order: number
}
Field Type Description
name string Russian name of station
nameTranslit string Transliterated name of station
lat number Latitude of your coordinate
lon number Longitude of your coordinate
lineColor string Color of the line in #HEX
lineName string Russian name of the line
lineNameTranslit string Transliterated name of the line
order number Order of the station in the line (from 0 - the Northern station)

Functions

Getting the closest station by city and coordinate (Lat+Lon)

function getClosestStation(
    city: City,
    lat: number,
    lon: number,
): [MetroStation, number] | null

Params:

Param Type Description
city City Name of the city in Russian
lat number Latitude of your coordinate
lon number Longitude of your coordinate

Returns the closest station (MetroStation-part) with distance in meters (number-part) from the given coordinate. Returns null if you pass an incorrect city name.

Example:

import { City, getClosestStation } from "@riaskov/metro-ru"

console.log(getClosestStation(City.Moscow, 55.640918, 37.754337))
Show example's output
[
  {
      name: 'Алма-Атинская',
      nameTranslit: 'Alma-Atinskaya',
      lat: 55.63349,
      lon: 37.765678, 
      lineColor: '#4FB04F',
      lineName: 'Замоскворецкая',
      lineNameTranslit: 'Zamoskvoretskaya',
      order: 21
  },
  1090
]

Getting the N closest stations by city and coordinate (Lat+Lon)

import { City, getClosestStations } from "@riaskov/metro-ru"

function getClosestStations(
    city: City,
    lat: number,
    lon: number,
    n: number,
): [MetroStation, number][] | null

Params:

Param Type Description
city City Name of the city in Russian
lat number Latitude of your coordinate
lon number Longitude of your coordinate

Returns an array of N closest stations (MetroStation-part) with distances in meters (number-part) (array of tuples like [MetroStation, number]). Returns null if you pass an incorrect city name.

Example:

import { getClosestStations } from '@riaskov/metro-ru'

console.log(getClosestStations(City.Moscow, 55.640918, 37.754337, 2))
Show example's output
[
  [
    {
      name: 'Алма-Атинская',
      nameTranslit: 'Alma-Atinskaya', 
      lat: 55.63349,
      lon: 37.765678,
      lineColor: '#4FB04F',
      lineName: 'Замоскворецкая',
      lineNameTranslit: 'Zamoskvoretskaya',
      order: 21
    },
    1090
  ],
  [
    {
      name: 'Марьино',
      nameTranslit: 'Marino',
      lat: 55.649158,
      lon: 37.743844,
      lineColor: '#BED12C',
      lineName: 'Люблинско-Дмитровская',
      lineNameTranslit: 'Lyublinsko-Dmitrovskaya',
      order: 16
    },
    1128
  ]
]

License

MIT (see the LICENSE file).

Acknowledgements

This project uses Open Data files provided data.mos.ru (Creative Commons Attribution 3.0)