@dwayneparton/geojson-to-gpx

中文文档
0.2.0发布于 2024/03/24MITTypeScriptES Module零依赖近 30 天下载 5511

Converts GeoJson to GPX

原始使用文档
文档目录7 节
  1. Contributions
  2. Goals and Parameters
  3. Installation
  4. Supports
  5. GeoJson
  6. Geometries
  7. Example

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();

版本与发布记录

@dwayneparton/geojson-to-gpx 共发布 33 个版本,首次发布于 2023/01/14;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.2.0latest2024/03/242 年前
0.1.02023/12/172 年前
0.0.302023/10/293 年前
0.0.292023/09/193 年前
0.0.282023/06/113 年前
0.0.272023/06/113 年前

关于 @dwayneparton/geojson-to-gpx 的常见问题

@dwayneparton/geojson-to-gpx 是什么?

Converts GeoJson to GPX

如何安装 @dwayneparton/geojson-to-gpx?

在项目目录运行 npm install @dwayneparton/geojson-to-gpx,或使用 pnpm add / yarn add / bun add。

@dwayneparton/geojson-to-gpx 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dwayneparton/geojson-to-gpx 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dwayneparton/geojson-to-gpx 可以商用吗?

@dwayneparton/geojson-to-gpx 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dwayneparton/geojson-to-gpx 的下载量有多少?

根据 npm 官方下载统计,@dwayneparton/geojson-to-gpx 在 2026/10/13 – 2026/11/11 这 30 天内被下载 5,511 次,日均约 184 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dwayneparton/geojson-to-gpx 还在维护吗?

最新版本 0.2.0 发布于 2024/03/24(2 年前);至今共发布 33 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/01/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。