npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nearest-mrt

v2.1.1

Published

Helper function for geospatial feature engineering

Downloads

852

Readme

nearest-mrt

A helper function for geospatial feature engineering. To find the nearest MRT station given a location's longitude & latitude.

Credits Singapore Land Authority (SLA) OneMap API service for location data.

To use

npm install --save nearest-mrt
import getNearestMrt from 'nearest-mrt'

const target = [103.736083, 1.341832]

/**
 * @param lnglat - coordinates of query location (required)
 * @param excludeFuture - whether to exclude future stations ({boolean}, default false)
 * @param radius - limit radius of search in meters ({numeric}, default 1000)
 */
const nearestMRT = getNearestMrt(target, false, 2000)
console.log(nearestMRT)

Sample output

{
  "query": {
    "lnglat": [
      103.736083,
      1.341832
    ],
    "excludeFuture": false,
    "radius": 2000
  },
  "result": [
    {
      "rank": 1,
      "station": {
        "name": "CHINESE GARDEN",
        "code": "EW25",
        "longitude": 103.7327666,
        "latitude": 1.3422449,
        "x": 16809.69,
        "y": 36044.45,
        "line": {
          "NSL": 0,
          "EWL": 1,
          "CGL": 0,
          "NEL": 0,
          "CCL": 0,
          "DTL": 0,
          "TEL": 0,
          "JRL": 0
        },
        "operational": 1,
        "interchange": 0,
        "locations": [
          {
            "platform": "EW25",
            "longitude": 103.7327663,
            "latitude": 1.3422443,
            "x": 16809.65,
            "y": 36044.37
          }
        ],
        "transfers": []
      },
      "distance": 372
    },
    {
      "rank": 2,
      "station": {
        "name": "JURONG EAST",
        "code": "NS1 EW24 JE5",
        "longitude": 103.7421539,
        "latitude": 1.3332951,
        "x": 17854.36,
        "y": 35054.77,
        "line": {
          "NSL": 1,
          "EWL": 1,
          "CGL": 0,
          "NEL": 0,
          "CCL": 0,
          "DTL": 0,
          "TEL": 0,
          "JRL": 2
        },
        "operational": 1,
        "interchange": 1,
        "locations": [
          {
            "platform": "NS1",
            "longitude": 103.7422651,
            "latitude": 1.3330741,
            "x": 17866.73,
            "y": 35030.34
          },
          {
            "platform": "EW24",
            "longitude": 103.7422651,
            "latitude": 1.3330741,
            "x": 17866.73,
            "y": 35030.34
          }
        ],
        "transfers": [
          {
            "from": "NSL",
            "to": "EWL",
            "distance": 0
          },
          {
            "from": "EWL",
            "to": "NSL",
            "distance": 0
          }
        ]
      },
      "distance": 1161
    },
    {
      "rank": 3,
      "station": {
        "name": "BUKIT BATOK",
        "code": "NS2",
        "longitude": 103.7495558,
        "latitude": 1.348992,
        "x": 18678.17,
        "y": 36790.44,
        "line": {
          "NSL": 1,
          "EWL": 0,
          "CGL": 0,
          "NEL": 0,
          "CCL": 0,
          "DTL": 0,
          "TEL": 0,
          "JRL": 0
        },
        "operational": 1,
        "interchange": 0,
        "locations": [
          {
            "platform": "NS2",
            "longitude": 103.7495554,
            "latitude": 1.3489914,
            "x": 18678.13,
            "y": 36790.36
          }
        ],
        "transfers": []
      },
      "distance": 1695
    },
    {
      "rank": 4,
      "station": {
        "name": "LAKESIDE",
        "code": "EW26",
        "longitude": 103.7209246,
        "latitude": 1.3442249,
        "x": 15491.81,
        "y": 36263.44,
        "line": {
          "NSL": 0,
          "EWL": 1,
          "CGL": 0,
          "NEL": 0,
          "CCL": 0,
          "DTL": 0,
          "TEL": 0,
          "JRL": 0
        },
        "operational": 1,
        "interchange": 0,
        "locations": [
          {
            "platform": "EW26",
            "longitude": 103.7209243,
            "latitude": 1.3442242,
            "x": 15491.77,
            "y": 36263.36
          }
        ],
        "transfers": []
      },
      "distance": 1708
    }
  ],
  "accurateAsOf": 1539273600000
}

If you prefer a CSV output

const nearestMRT = getNearestMrt(target, false, 2000)
console.log(nearestMRT.toFlatObjects())
console.log(nearestMRT.toTable())
console.log(nearestMRT.toCSV())

Sample flat object output:

Sample CSV output

Interpreting output

  • 0 - False
  • 1 - True
  • 2 - Will be true in future (Planned but under construction)