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 🙏

© 2026 – Pkg Stats / Ryan Hefner

giser-convert-crs

v1.0.0

Published

China CRS geometry conversion library for WGS-84, GCJ-02, BD-09, GeoJSON and WKT.

Readme

giserConvertCrs

giserConvertCrs 是一个几何坐标系转换工具库,支持 WGS-84、GCJ-02、BD-09 之间的点、线、面、数组、GeoJSON 和 WKT 转换。

注意:npm 包名需要保持小写,因此发布包名仍为 giser-convert-crs;代码变量、浏览器全局变量、构建文件名统一使用 giserConvertCrs

坐标系写法

所有转换方法的 fromCRStoCRS 都支持下面这些写法:

| 坐标系 | 可用写法 | | --- | --- | | WGS-84 | wgs84, wgs-84, EPSG:4326, epsg:4326 | | GCJ-02 | gcj02, gcj-02 | | BD-09 | bd09ll, bd09, bd-09 |

giserConvertCrs.transform([116.397, 39.908], 'wgs84', 'gcj02');
giserConvertCrs.transform([116.397, 39.908], 'EPSG:4326', 'bd09');
giserConvertCrs.transform([116.397, 39.908], 'bd-09', 'wgs84');

坐标顺序固定为 [lon, lat],即经度在前、纬度在后。三维坐标也支持,例如 [lon, lat, height],转换后会保留高度值。

支持的输入

单个点

[116.397, 39.908]
[116.397, 39.908, 45]

点数组

[
  [116.397, 39.908],
  [117.2, 40.1]
]

GeoJSON

giserConvertCrs.transformGeoJSON(geojson, 'wgs84', 'gcj02') 里的 geojson 是标准 GeoJSON 几何对象、Feature 或 FeatureCollection。

Point:

const geojson = {
  type: 'Point',
  coordinates: [116.397, 39.908]
};

giserConvertCrs.transformGeoJSON(geojson, 'wgs84', 'gcj02');

LineString:

const geojson = {
  type: 'LineString',
  coordinates: [
    [116.397, 39.908],
    [117.2, 40.1]
  ]
};

giserConvertCrs.transformGeoJSON(geojson, 'wgs84', 'gcj02');

Polygon:

const geojson = {
  type: 'Polygon',
  coordinates: [[
    [116.0, 39.9],
    [116.1, 39.9],
    [116.1, 40.0],
    [116.0, 39.9]
  ]]
};

giserConvertCrs.transformGeoJSON(geojson, 'wgs84', 'gcj02');

FeatureCollection:

const geojson = {
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      properties: { name: '点' },
      geometry: {
        type: 'Point',
        coordinates: [116.397, 39.908]
      }
    },
    {
      type: 'Feature',
      properties: { name: '线' },
      geometry: {
        type: 'LineString',
        coordinates: [
          [116.397, 39.908],
          [117.2, 40.1]
        ]
      }
    }
  ]
};

giserConvertCrs.transformGeoJSON(geojson, 'wgs84', 'gcj02');

还支持 MultiPointMultiLineStringMultiPolygonGeometryCollection

WKT

'POINT(116.397 39.908)'
'LINESTRING(116 39, 117 40)'
'POLYGON((116 39, 117 39, 117 40, 116 39))'
'MULTIPOINT((116 39), (117 40))'
'MULTILINESTRING((116 39, 117 40), (118 41, 119 42))'
'MULTIPOLYGON(((116 39, 117 39, 117 40, 116 39)))'

安装

npm install giser-convert-crs

引入方式

ES Module

import giserConvertCrs, { WKT, GPS } from 'giser-convert-crs';

const point = giserConvertCrs.transform([116.397, 39.908], 'wgs84', 'gcj02');
const geometry = WKT.parse('LINESTRING(116 39, 117 40)');
const bd09 = GPS.wgs84_bd09ll(116.397, 39.908);

Script

<script src="https://unpkg.com/giser-convert-crs/dist/giserConvertCrs.umd.js"></script>
<script>
  const point = giserConvertCrs.transform([116.397, 39.908], 'wgs84', 'gcj02');
</script>

API

giserConvertCrs.transform(input, fromCRS, toCRS)

统一转换入口,会根据输入类型自动处理:

  • 输入坐标数组时,返回坐标数组。
  • 输入 GeoJSON 时,返回同结构的新 GeoJSON。
  • 输入 WKT 字符串时,返回 WKT 字符串。
giserConvertCrs.transform([116.397, 39.908], 'wgs84', 'gcj02');
giserConvertCrs.transform([[116.397, 39.908], [117.2, 40.1]], 'wgs84', 'bd09ll');
giserConvertCrs.transform('LINESTRING(116 39, 117 40)', 'wgs84', 'gcj02');

giserConvertCrs.transformPoint(coord, fromCRS, toCRS)

giserConvertCrs.transformPoint([116.397, 39.908], 'wgs84', 'gcj02');

giserConvertCrs.transformPoints(points, fromCRS, toCRS)

giserConvertCrs.transformPoints([[116.397, 39.908], [117.2, 40.1]], 'wgs84', 'gcj02');

giserConvertCrs.transformGeoJSON(geojson, fromCRS, toCRS)

const result = giserConvertCrs.transformGeoJSON(geojson, 'wgs84', 'gcj02');

giserConvertCrs.transformWKT(wkt, fromCRS, toCRS)

giserConvertCrs.transformWKT('POINT(116.397 39.908)', 'wgs84', 'gcj02');
giserConvertCrs.transformWKT('POLYGON((116 39, 117 39, 117 40, 116 39))', 'wgs84', 'gcj02');

giserConvertCrs.WKT

const geojson = giserConvertCrs.WKT.parse('MULTIPOINT((116 39), (117 40))');
const wkt = giserConvertCrs.WKT.stringify({
  type: 'LineString',
  coordinates: [[116, 39, 10], [117, 40, 20]]
});

giserConvertCrs.GPS

giserConvertCrs.GPS.wgs84_gcj02(116.397, 39.908);
giserConvertCrs.GPS.gcj02_wgs84(116.403243, 39.909403);
giserConvertCrs.GPS.gcj02_wgs84_precise(116.403243, 39.909403);
giserConvertCrs.GPS.gcj02_bd09ll(116.403243, 39.909403);
giserConvertCrs.GPS.bd09ll_gcj02(116.409, 39.915);
giserConvertCrs.GPS.wgs84_bd09ll(116.397, 39.908);
giserConvertCrs.GPS.bd09ll_wgs84(116.409, 39.915);

注意事项

  1. 坐标顺序固定为 [lon, lat]
  2. WGS-84 和 GCJ-02 的加偏转换只对中国范围内坐标生效,中国境外坐标会原样返回。
  3. gcj02_wgs84 是常规近似反算,gcj02_wgs84_precise 是更高精度反算。
  4. 不支持的坐标系会抛出错误,例如 epsg:3857

License

MIT