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

@k6t12n/gis-helpers

v2.1.0

Published

GIS Helpers for calculating gis variables

Downloads

7

Readme

GIS Helpers

GIS Helpers is a library that provides utilities for calculating distances between geographic coordinates and checking if a point is inside a polygon. This library is built to assist with geospatial calculations such as distance between two latitude and longitude points, and checking if a point lies within a polygon.

NPM Version License PRs Welcome

Available in Other Languages

In addition to the JavaScript/TypeScript version, this library is also available in the following languages:

Golang

For Go developers, you can use the gis-helpers-go library to handle geographic calculations.

Repository: k6t12n/gis-helpers-go

Installation

You can install the library using either yarn or npm:

Using Yarn

yarn add @k6t12n/gis-helpers

Using npm

npm install @k6t12n/gis-helpers

Usage

Importing the Library

To use the library in your project, import the GisHelpers class:

import { GisHelpers } from 'gis-helpers';

Distance Calculation

To calculate the distance between two points, instantiate the GisHelpers class with two sets of coordinates (latitude, longitude):

const location1: [number, number] = [34.0522, -118.2437]; // Los Angeles
const location2: [number, number] = [40.7128, -74.0060];  // New York City

const distanceHelper = new GisHelpers(location1, location2);

const distanceInKm = distanceHelper.getDistance('km');
const distanceInMeters = distanceHelper.getDistance('m');

console.log(`Distance in kilometers: ${distanceInKm} km`);
console.log(`Distance in meters: ${distanceInMeters} meters`);
  • The getDistance() method takes a unit parameter:
    • 'km' for kilometers
    • 'm' for meters

Point-in-Polygon Detection

To check if a specific point lies inside a polygon, use the isPointInPolygon method:

const location1: [number, number] = [34.0522, -118.2437]; // Point to check

const polygon: [number, number][] = [
    [34.0, -118.5],
    [34.2, -118.0],
    [34.5, -118.5],
    [34.0, -119.0]
]; // Example polygon

const distanceHelper = new GisHelpers(location1);

const isInside = distanceHelper.isPointInPolygon(location1[0], location1[1], polygon);
console.log(`Is the point inside the polygon? ${isInside}`);

Methods

  • getDistance(unit: string): number
    Calculates the distance between two geographical coordinates in kilometers or meters.

  • isPointInPolygon(latitude: number, longitude: number, polygon: [number, number][]): boolean
    Determines whether a given point (latitude, longitude) is inside a polygon defined by an array of coordinates.

Contributions

Loving the project? Please feel free to contribute to this project. Whether it's suggestions, features, code refactors, testing, any help is welcome.

License

MIT