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

togpx

v0.5.4

Published

convert geojson to gpx

Downloads

14,066

Readme

togpx

Converts GeoJSON to GPX.

Build Status

Usage

  • as a command line tool:

      $ npm install -g togpx
      $ togpx file.geojson > file.gpx
  • as a nodejs library:

      $ npm install togpx
    
      var togpx = require('togpx');
      togpx(geojson_data);
  • as a browser library:

      <script src='togpx.js'></script>
    
      togpx(geojson_data);

API

togpx( geojson, options )

  • geojson: the GeoJSON data.
  • options: optional. The following options can be used:
    • creator: Specify a creator string that is used to specify the software that created the final GPX file. Default is togpx.
    • metadata: An object containing metadata about the to be converted dataset. Will be included in the GPX in the <metadata> tag. Usefull for providing information like copyright, time, desc, etc.
    • featureTitle: Defines a callback that is used to construct a title (<name>) for a given GeoJSON feature. The callback is called with the GeoJSON feature's properties object.
    • featureDescription: Defines a callback that is used to construct a description (<desc>) for a given GeoJSON feature. The callback is called with the GeoJSON feature's properties object.
    • featureLink: Defines a callback that is used to construct an URL (<link>) for a given GeoJSON feature. The callback is called with the GeoJSON feature's properties object.
    • featureCoordTimes: Defines a callback that is called for each feature to determine timestamps of each coordinate. Gets called with the current feature as a parameter, must return an array of UTC ISO 8601 timestamp strings for each coordinate of the feature. Alternatively. this option can be a string, in which case the corresponding feature property is used to read the times array.

The result is a string of GPX XML.

GPX

The conversion from GeoJSON to GPX is (by definition) lossy, because not every GeoJSON feature can be represented with the simple data types present in GPX files and GPX does not support arbitrary feature properties. This library tries to convert as much geometry and information as possible:

  • Points are converted to Waypoints.
  • Lines are converted to Tracks.
  • (Multi)Polygons are represented as a Track of their outline(s).
  • By default, the name tag of GPX elements will be determined by a simple heuristic that searches for the following GeoJSON properties to construct a meaningful title: name, ref, id
  • By default, the desc tag of GPX elements will be constructed by concatenating all respective GeoJSON properties.
  • Elevation is included in the output if the GeoJSON coordinates contain altitude as a third value ([lon, lat, altitude])
  • Timestamps are included in the GPX output if the GeoJSON has a times or coordTimes property that is an array of UTC ISO 8601 timestamp strings. See the featureCoordTimes option for customizing this behaviour.