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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@sparta-utils/gps-transform-utils

v1.0.1

Published

一个支持三参数与七参数的 GPS 坐标转换工具,适用于 WGS84 转 CGCS2000、北京54 等坐标系的正向与反向平面投影计算。

Readme

@sparta-utils/gps-transform-utils

一个支持 三参数 / 七参数 的 GPS 坐标转换工具,可用于 WGS84 → CGCS2000 / 北京54 的投影转换,并支持反向坐标还原。

基于 proj4js,适用于地理信息系统、测绘数据校正等场景。


📦 安装方式

npm install @sparta-utils/gps-transform-utils

✨ 功能特色

✅ 支持 三参数(ΔX, ΔY, ΔZ)转换

✅ 支持 七参数(含旋转角、比例)转换

✅ 自动判断中央经线(三度带)

✅ 支持反向投影(平面 → GPS 坐标)

✅ 支持 CGCS2000 / 北京54 坐标系

✅ TypeScript 强类型定义

🚀 使用示例

1️⃣ 三参数转换

import { gpsToPlaneBy3Params } from '@sparta-utils/gps-transform-utils';

const gps = { lng: 117.1234, lat: 39.1234 };
const params = { dx: 15, dy: -154, dz: -82 };

const result = gpsToPlaneBy3Params('北京54', params, gps);
console.log('三参数坐标:', result);

2️⃣ 七参数转换

import { gpsToPlaneBy7Params } from '@sparta-utils/gps-transform-utils';

const gps = { lng: 117.1234, lat: 39.1234 };
const params = {
  dx: 15,
  dy: -154,
  dz: -82,
  rx: 0.0,   // 秒
  ry: 0.0,
  rz: 0.0,
  scale: 0.0 // ppm
};

const result = gpsToPlaneBy7Params('北京54', params, gps);
console.log('七参数坐标:', result);

3️⃣ 反向还原(平面坐标 → GPS 坐标)

import { planeToGps } from '@sparta-utils/gps-transform-utils';

const plane = { x: 500320.888, y: 4321939.137 };
const gps = planeToGps('北京54', { dx: 15, dy: -154, dz: -82 }, plane, 117);
console.log('还原坐标:', gps);

🧾 参数说明

GPS 坐标对象(输入)

| 字段 | 类型 | 说明 | | ----- | -------- | ---------- | | lng | number | 经度,单位:十进制度 | | lat | number | 纬度,单位:十进制度 |

三参数(适用于 gpsToPlaneBy3Params)

| 字段 | 类型 | 说明 | | ---- | -------- | ------- | | dx | number | X轴偏移(米) | | dy | number | Y轴偏移(米) | | dz | number | Z轴偏移(米) |

七参数(适用于 gpsToPlaneBy7Params)

| 字段 | 类型 | 说明 | | ------- | -------- | --------------- | | dx | number | X轴偏移(米) | | dy | number | Y轴偏移(米) | | dz | number | Z轴偏移(米) | | rx | number | X轴旋转(秒) | | ry | number | Y轴旋转(秒) | | rz | number | Z轴旋转(秒) | | scale | number | 比例缩放(ppm,百万分之一) |

返回坐标(平面坐标)

| 字段 | 类型 | 说明 | | --- | -------- | ------ | | x | number | 东坐标(米) | | y | number | 北坐标(米) |

📌 中央经线说明

工具自动按三度带判断中央经线:

// 例如经度 117.5 会被判定为中央经线 120°
centralMeridian = Math.floor(lng / 3 + 1) * 3;

如需手动指定,可在方法中传入 centralMeridian 参数。

🔗 依赖说明

proj4