0.2.0 • Published 1 year ago

@dwayneparton/geojson-to-gpx v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Convert GeoJson to GPX

codecov

Designed to be a browser library. Will interpret a geojson object into a gpx XMLDocument. From there you can convert it to a string for download or post process the document.

Can be used with Node though by doing something like:

  import { DOMImplementation } from '@xmldom/xmldom';
  import GeoJsonToGpx from "@dwayneparton/geojson-to-gpx"
  const implementation = new DOMImplementation();
  const gpx = GeoJsonToGpx(geojson, options, implementation);

Contributions

Contributions welcome.

Goals and Parameters

Installation

npm install @dwayneparton/geojson-to-gpx

Supports

GeoJson

  • Feature
  • FeatureCollection - each feature(LineSting|MultiLineString) is interpreted into it's own trk, (Point|MultiPoint) will be new wpt

Geometries

  • Point
  • MultiPoint - adds wpt for each point
  • LineString
  • MultiLineString - each link string is broken out into a net trkseg

Incompatible Geometries are ignored. Why? The GPX format is designed for storing waypoints, tracks, and routes.

Example

This examples converts a geojson object to a gpx file for users to download.

import GeoJsonToGpx from "@dwayneparton/geojson-to-gpx"

const options = {
  metadata: {
    name: 'A grand adventure',
    author: {
      name: 'Dwayne Parton',
      link: {
        href: 'https://www.dwayneparton.com'
      }
    }
  }
}

const geojson = { 
  type: "Feature",
  properties : {
    name : 'Slow journey from null island'
  },
  geometry: {
    type: "LineString",
    coordinates: [
      [0.0, 0.0],
      [0.0, 1.0],
      [0.0, 2.0],
      [0.0, 3.0]
    ]
  },
};

// Will convert geojson into xml document
const gpx = GeoJsonToGpx(geojson, options);

// convert document to string or post process it
const gpxString = new XMLSerializer().serializeToString(gpx);

// @see https://stackoverflow.com/questions/10654971/create-text-file-from-string-using-js-and-html5
const link = document.createElement('a');
link.download = 'geojson-to-gpx.gpx';
const blob = new Blob([gpxString], {type: 'text/xml'});
link.href = window.URL.createObjectURL(blob);
link.click();
0.2.0

1 year ago

0.1.0

1 year ago

0.0.30

2 years ago

0.0.29

2 years ago

0.0.20

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

0.0.15

2 years ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

0.0.14

2 years ago

0.0.26

2 years ago

0.0.27

2 years ago

0.0.28

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

1.0.0

2 years ago