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

arc

v0.1.4

Published

draw great circle arcs

Downloads

48,402

Readme

arc.js

Calculate great circles routes as lines in GeoJSON or WKT format.

Algorithms from https://edwilliams.org/avform.htm#Intermediate

Includes basic support for splitting lines that cross the dateline, based on a partial port of code from OGR.

Install

$ npm install --save arc

License

BSD

Usage

Require the library in node.js like:

var arc = require('arc');

Use in the browser like:

<script src="./arc.js"></script>

API

1) Create start and end coordinates

First we need to declare where the arc should start and end

var start = { x: -122, y: 48 };
var end = { x: -77, y: 39 };

Note that x here is longitude in degrees and y is latitude in degrees.

2) Create GreatCircle object

Next we pass the start/end to the GreatCircle constructor, along with an optional object representing the properties for this future line.

var generator = new arc.GreatCircle(start, end, {'name': 'Seattle to DC'});

3) Generate a line arc

Then call the Arc function on the GreatCircle object to generate a line:

var line = generator.Arc(100,{offset:10});

The line will be a raw sequence of the start and end coordinates plus an arc of intermediate coordinate pairs.

> line
{
  properties: { name: 'Seattle to DC' },
  geometries: [
    {
      coords:
       [ [ -122, 48 ],
         [ -112.06162, 47.724167 ],
         [ -102.384043, 46.608132 ],
         [ -93.227189, 44.716217 ],
         [ -84.74824, 42.144155 ],
         [ -77, 39 ] ],
      length: 6
    }
  ]
}

Arc options

The first argument to Arc specifies the number of intermediate vertices you want in the resulting line. The higher the number the more dense and accurate the line will be.

The second argument is an optional object to declare options. The offset option controls the likelyhood that lines will be split which cross the dateline. The higher the number the more likely. The default value is 10, which means lines within 10 degress of the dateline will be split. For lines that cross and dateline and are also near the poles you will likely need a higher value to trigger splitting. It is unclear to me (@springmeyer) what the drawbacks are of high offsets. I simply ported the code from OGR's gdal/ogr/ogrgeometryfactory.cpp and have not taken the time to fully comprehend how it works.

4) Convert line to GeoJSON geometry

To serialize to a GeoJSON geometry:

> line.json();
{ geometry:
   { type: 'LineString',
     coordinates: [ [Object], [Object], [Object], [Object], [Object], [Object] ] },
  type: 'Feature',
  properties: { name: 'Seattle to DC' } }

Or to WKT (Well known text):

> line.wkt();
'LINESTRING(-122 48,-112.061619 47.724167,-102.384043 46.608131,-93.227188 44.716217,-84.748239 42.144155,-77 38.999999)'

It is then up to you to add up these features to create fully fledged geodata. See the examples/ directory for sample code to create a GeoJSON feature collection from multiple routes.