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

positic

v1.0.13

Published

simple geospatial analysis for browser and node

Downloads

12

Readme

positic

Build Status

manipulate positions from GeoJSON.

install

$ npm install --save positic

or

$ yarn add positic

Usage

Javascript

// CommonsJs
const createTrack = require('positic').createTrack;

// ES Modules
import { createTrack } from 'positic';

TypeScript

import { Track, createTrack } from 'positic';

const track: Track = createTrack([5.77367, 45.07122, 279.608]);

api

createTrack: (positions: Positions[]) => Track

Given any valid position array, return an object that manipulate positions and calculate data.

type definitions

  • based types
type Longitude = number;
type Latitude = number;
type Altitude = number;
type Loss = number;
type Gain = number;
type Distance = number;
type Position = [Longitude, Latitude, Altitude?];
type Elevation = {
  positive: number;
  negative: number;
};
type Area = {
  minLongitude: number;
  maxLongitude: number;
  minLatitude: number;
  maxLatitude: number;
};
type Statistics = [Distance, Gain, Loss];
  • Track
type Track = {
  getPositionsAt: (...distances: number[]) => Position[];
  getPositionsIndicesAt: (...distances: number[]) => number[];
  getPositionIndex: (position: Position) => number;
  slice: (start?: number, end?: number) => Path;
  getLength: () => number;
  getElevation: (smoothingFactor?: number) => Elevation;
  getBoundingBox: () => Area;
  findClosestPosition: (currentLocation: Position) => Position;
  getProgressionStatistics: (currentPathIndex: number) => Statistics;
};

Track usage

import { createTrack } = from "positic";

const positions = [
  [5.77367, 45.07122, 279.608],
  [5.77367, 45.07122, 279.608],
  [5.77407, 45.07117, 279.926],
  [5.77467, 45.07108, 280.112],
  [5.77487, 45.07091, 280.871],
  [5.77501, 45.07069, 281.516],
  [5.77515, 45.07045, 282.205],
  [5.77573, 45.07057, 280.301],
  ...,
  [6.30269, 45.54447, 320],
  [6.30273, 45.54463, 320],
  [6.30281, 45.5447, 320],
  [6.30275, 45.54486, 320],
  [6.30267, 45.54509, 320],
  [6.30259, 45.54522, 320],
  [6.30245, 45.54534, 320],
  [6.30233, 45.54542, 320]
  ];

const track = createTrack(positions);

or

const track = createTrack(GeoJSON.features[0].geometry.coordinates);
  • calculate track length
const distance = track.getLength();
// distance = 144670 (in meters);
  • calculate track elevation
const elevation = track.getElevation();
// elevation = {positive:1243.33, negative:1209.34} (in meters)
  • calculate track bounding box
const area = track.getBoundingBox();
// area = {
// "maxLatitude": 45.55014,
// "maxLongitude": 6.30281,
// "minLatitude": 45.06822,
// "minLongitude": 5.77311,
// }
  • get positions at 10km and 20km marks
const marks = [10000, 20000];
const positions = get.getPositionsAt(...marks);
// positions = [
//     [5.77501, 45.07069, 281.516],
//     [6.30259, 45.54522, 320],
//]
  • find the closest track position to a given position
const PARIS = [2.3488, 48.8534];
const closestPosition = track.findClosestPosition(PARIS);
// closestPosition = [6.30259, 45.54522, 320]
  • get progression statistics
const currentIndex = 1200;
const statistics = track.getProgressionStatistics(currentIndex);
// statistics = [120.23, 6787.34, 5683.22] (distance in meters, positive elevation in meters, negative elevation in meters)

generic helper functions

  • calculate distance between two positions
import { calculateDistance } from 'positic';

const origin = [37.618423, 55.751244];
const destination = [2.3488, 48.8534];

const distance = calculateDistance(origin, destination);
// distance = 2486688.9750256147 (in meters)
  • calculate bearing between two positions
import { calculateBearing } from 'positic';

const origin = [-3.94915, 51.2194];
const destination = [-3.95935, 51.2392];

const bearing = calculateBearing(origin, destination);
// bearing = 342.1247653798634 (in deg)
  • check if position is in a given area
import { isInArea } from 'positic';

const current = [-3.94915, 51.2194];

const area = {
  maxLatitude: 49.07122,
  minLatitude: 40.07122,
  minLongitude: 1.77367,
  maxLongitude: 9.77367
};
const isIn = isInArea(current, area);
// isIn = true / false
  • check if position is in a given radius
import { isRadius } from 'positic';

const current = [-3.94915, 51.2194];
const center = [6.23828, 45.50127, 888.336];
const radius = 70;

const isIn = location.isInRadius(current, center, radius);
// isIn = true / false

TypeScript

positic includes TypeScript definitions.

License

MIT