---
title: "transformPoint / transformGeoJSON"
description: "Convert coordinate points and GeoJSON between WGS84, GCJ02, BD09 and EPSG3857 using gcoord."
canonical_url: "https://mapbox.mhaibaraai.cn/en/docs/utils/coordinate"
---
# transformPoint / transformGeoJSON

> Convert coordinate points and GeoJSON between WGS84, GCJ02, BD09 and EPSG3857 using gcoord.

## Introduction

`transformPoint` / `transformGeoJSON` convert coordinates between WGS84, GCJ02, BD09 and EPSG3857 using [gcoord](https://github.com/hujiulong/gcoord): the former converts a single longitude/latitude point, the latter converts any GeoJSON and returns a new object (without mutating the input). Commonly used to correct datum offsets in Amap / Tencent (GCJ02) or Baidu (BD09) data back to WGS84, aligning Tianditu and Mapbox base maps.

Both are imported from `@movk/mapbox/utils/coordinate` (not auto-imported):

```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
> 
> Full visual examples (point correction, GeoJSON correction, precision control) are available on the 
> 
> Coordinate Conversion
> 
>  extension page.

## API

### `transformPoint()`

Convert a single longitude/latitude point and return the new coordinates.

**point** (`[number, number]`) *required*: Longitude/latitude point [lng, lat].

**from** (`CRS`) *required*: Source coordinate reference system.

**to** (`CRS`) *required*: Target coordinate reference system.

**options.precision** (`number`): Number of decimal places to keep in the output coordinates. Omit to retain full precision.

Returns `[number, number]`: the converted `[lng, lat]`.

### `transformGeoJSON()`

Convert any GeoJSON (point / line / polygon / collection) and return a new object of the same type as the input, without mutating the original.

**geojson** (`T`) *required*: Any GeoJSON object (Feature / Geometry / FeatureCollection, etc.).

**from** (`CRS`) *required*: Source coordinate reference system.

**to** (`CRS`) *required*: Target coordinate reference system.

**options.precision** (`number`): Number of decimal places to keep in the output coordinates. Omit to retain full precision.

Returns `T`: a new GeoJSON object of the same type as the input.

### `CRS`

Coordinate reference system identifier: `'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).

---

- [gcoord](https://github.com/hujiulong/gcoord)


## Sitemap

See the full [sitemap](https://mapbox.mhaibaraai.cn/sitemap.md) for all pages.
