---
title: "transformPoint / transformGeoJSON"
description: "基于 gcoord 在 WGS84 / GCJ02 / BD09 / EPSG3857 间转换坐标点与 GeoJSON。"
seo_title: "transformPoint / transformGeoJSON"
seo_description: "Convert points and GeoJSON between WGS84, GCJ02, BD09 and EPSG3857 with transformPoint and transformGeoJSON, powered by gcoord."
canonical_url: "https://mapbox.mhaibaraai.cn/docs/utils/coordinate"
---
# transformPoint / transformGeoJSON

> 基于 gcoord 在 WGS84 / GCJ02 / BD09 / EPSG3857 间转换坐标点与 GeoJSON。

## 简介

`transformPoint` / `transformGeoJSON` 基于 [gcoord](https://github.com/hujiulong/gcoord){rel="[\"nofollow\"]"} 在 WGS84 / GCJ02 / BD09 / EPSG3857 间转换坐标：前者转单个经纬度点，后者转任意 GeoJSON 并返回新对象（不修改入参）。常用于把高德 / 腾讯（GCJ02）、百度（BD09）数据纠偏到 WGS84，对齐天地图与 Mapbox 底图。

两者均从 `@movk/mapbox/utils/coordinate` 导入（非自动导入）：

```ts
import { transformGeoJSON, transformPoint } from '@movk/mapbox/utils/coordinate'

const gcj02 = transformPoint([121.4737, 31.2304], 'WGS84', 'GCJ02')
const wgs84 = transformGeoJSON(raw, 'GCJ02', 'WGS84', { precision: 6 })
```

> \[\!NOTE\]
> See: /docs/extensions/coordinate
> 
> 完整的可视化示例（点纠偏、GeoJSON 纠偏、精度控制）见
> 
> 坐标转换
> 
> 扩展页。

## API

### `transformPoint()`

转换单个经纬度点，返回新坐标。

**point** (`[number, number]`) *required*: 经纬度点 \[lng, lat\]。

**from** (`CRS`) *required*: 源坐标系。

**to** (`CRS`) *required*: 目标坐标系。

**options.precision** (`number`): 输出坐标保留的小数位数，省略则保留完整精度。

返回 `[number, number]`：转换后的 `[lng, lat]`。

### `transformGeoJSON()`

转换任意 GeoJSON（点 / 线 / 面 / 集合），返回与入参同类型的新对象，不修改入参。

**geojson** (`T`) *required*: 任意 GeoJSON 对象（Feature / Geometry / FeatureCollection 等）。

**from** (`CRS`) *required*: 源坐标系。

**to** (`CRS`) *required*: 目标坐标系。

**options.precision** (`number`): 输出坐标保留的小数位数，省略则保留完整精度。

返回 `T`：与入参同类型的新 GeoJSON 对象。

### `CRS`

坐标系标识：`'WGS84'` | `'GCJ02'` | `'BD09'` | `'EPSG3857'`。

## Changelog

See commit history for [src/runtime/utils/transformPoint  transformGeoJSON.ts](https://github.com/mhaibaraai/movk-mapbox/commits/main/src/runtime/utils/transformPoint  transformGeoJSON.ts).


## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
