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

related-geo

v3.0.2

Published

extensions for doeing area, distance searches using lat/lng fields

Downloads

4

Readme

related-geo

Lets you filter and order records by their GPS position.

npm Travis node

Features: - compute the distance for every row to a given set of coordinates - return items that are inside a box on a map - order rows by distance to a point - filter events based on the distance to a point - any combination of the items above

The extension works with two different strategies to get the fastest results when executing searches on the distance. Its generally not recommended to work on very large data sets. If you are looking for items in a reasonable small radius the extension uses strategy A to limit the dataset to that radius which makes it possible to return an ordered dataset in a reasonable amount of time. If you don't limit the set by a reasonable small radius the extension uses strategy B which is somewhat slower but performs better when there is no limit to the radius. You may configure what that radius is with the radius option. The configuration can be set per table. The default offset to switch from strategy A to strategy B is 20 km. If you have many items inside such a radius you should set it to a smaller number. In any case a sequantial scan is used to compute the distance.

installation

npm i related-geo

Postgres

You should create an index on your latitude and longitude columns using the gist extension

    CREATE INDEX name_of_index on table USING gist(ll_to_earth(latColumn, lngColumn));

MySQL

You should create an index on your latitude and longitude columns

API

Get an related ORM instance

var   RelatedORM = require('related')
    , RelatedGEO = require('related-geo')

var related = new RelatedORM(config);

Add the extension

related.use(new RelatedGEO());

The extension tries to apply the filters and selects to columns with the following names:

  • latitude: lat, latitude
  • longitude: lng, lon, long, longitude

If your tables contain gps fields with different names you may add them as option when you instantiate the extension

related.use(new RelatedGEO({
      latColumns: ['myLat', 'customLat']
    , lngColumns: ['myLng']
}));

If you want to define a custom offset to switch from strategy A to startegy B for doing radius searches you can define it in the options. You may define a global value and addiotionally a custom value per table.

related.use(new RelatedGEO({
      offsetRadius: 10000
    , myDb: {
        myTableName: {
            offsetRadius: 2000
        }
    }
}));

Distance

Find venues inside a radius around a given position, order by distance

orm.db.venue([RelatedORM.select('distance').distanceFrom(lat, lng)], {
    distance: RelatedORM.filter.lt(2000)
})
.order('distance')
.limit(100)
.find()
.then()
.catch();

Box

Find venues inside of a box

orm.db.venue({
    RelatedORM.filter.insideBox(latTop, lngLeft, latBottom, lngRight)
})
.limit(100)
.then()
.catch();

Combined

Find venues inside of a box, order them by distance to the center of the box

orm.db.venue([RelatedORM.select('distance').distanceFrom(RelatedORM.function.getCenter(latTop, lngLeft, latBottom, lngRight))], {
    RelatedORM.filter.insideBox(latTop, lngLeft, latBottom, lngRight)
})
.order('distance')
.limit(100)
.find()
.then()
.catch();