0.2.0 • Published 2 months ago

@dwayneparton/geojson-to-gpx v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months 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

2 months ago

0.1.0

5 months ago

0.0.30

6 months ago

0.0.29

8 months ago

0.0.20

11 months ago

0.0.21

11 months ago

0.0.22

11 months ago

0.0.23

11 months ago

0.0.24

11 months ago

0.0.25

11 months ago

0.0.15

11 months ago

0.0.16

11 months ago

0.0.17

11 months ago

0.0.18

11 months ago

0.0.19

11 months ago

0.0.14

11 months ago

0.0.26

11 months ago

0.0.27

11 months ago

0.0.28

11 months ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

1.0.0

1 year ago