coordtransform-rs
Provides coordinate transformations between BD09, GCJ02, WGS84, and EPSG:3857, implemented in Rust with no third-party dependencies.
This is the Rust port of the Go version.
Coordinate System Description
- WGS84: Global longitude/latitude coordinate system used by GPS/GNSS and most GIS datasets.
- GCJ02: Offset coordinate system commonly used by map services in mainland China.
- BD09: Baidu coordinate system derived from GCJ02.
- EPSG:3857: Web Mercator projection widely used by web mapping services.
Features
- GCJ02 -> BD09 (
gcj02_to_bd09) - BD09 -> GCJ02 (
bd09_to_gcj02) - BD09 -> GCJ02 fast mode (
bd09_to_gcj02_fast) - WGS84 -> GCJ02 (
wgs84_to_gcj02) - GCJ02 -> WGS84 (
gcj02_to_wgs84) - GCJ02 -> WGS84 fast mode (
gcj02_to_wgs84_fast) - WGS84 -> BD09 (
wgs84_to_bd09) - BD09 -> WGS84 (
bd09_to_wgs84) - WGS84 -> EPSG:3857 (
wgs84_to_epsg3857) - EPSG:3857 -> WGS84 (
epsg3857_to_wgs84) - GCJ02 -> EPSG:3857 (
gcj02_to_epsg3857) - EPSG:3857 -> GCJ02 (
epsg3857_to_gcj02) - BD09 -> EPSG:3857 (
bd09_to_epsg3857) - EPSG:3857 -> BD09 (
epsg3857_to_bd09) - Mainland China GCJ02 region check (
is_in_gcj02_region) - High-performance mainland conversion APIs
- In-place batch conversion APIs
GCJ02/BD09 offsets are only applied inside the mainland China transform region. Outside the region, geographic coordinates remain WGS84.
Installation
Add the following to your Cargo.toml:
[]
= "0.3.0"
Quick Start
use *;
Other APIs
use *;
let inside = is_in_gcj02_region;
let gcj = wgs84_to_gcj02_in_mainland;
let wgs = gcj02_to_wgs84_in_mainland;
let _ = gcj02_to_wgs84_fast;
let _ = bd09_to_gcj02_fast;
let mut points = ;
wgs84_to_gcj02_in_place;
Batch APIs:
wgs84_to_gcj02_in_placegcj02_to_wgs84_in_placewgs84_to_gcj02_in_mainland_in_placegcj02_to_wgs84_in_mainland_in_placewgs84_to_bd09_in_placebd09_to_wgs84_in_place
Strict EPSG:3857 APIs:
try_wgs84_to_epsg3857try_epsg3857_to_wgs84wgs84_to_epsg3857_clamped
Testing
License
This project is licensed under the MIT License - see the LICENSE file for details.
The embedded mainland China transform-region data is derived from OpenStreetMap data and remains subject to ODbL 1.0.
OpenStreetMap contributors: https://www.openstreetmap.org/copyright
Related Projects
中文
提供 BD09、GCJ02、WGS84、EPSG:3857 坐标系之间的相互转换,基于 Rust 实现,无第三方依赖。
这是 Go版本 的 Rust 移植版本。
坐标系说明
- WGS84坐标系:GPS/GNSS 和大多数 GIS 数据使用的全球经纬度坐标系。
- GCJ02坐标系:中国大陆地图服务常用的偏移坐标系。
- BD09坐标系:百度坐标系,基于 GCJ02 进行转换。
- EPSG:3857坐标系:Web Mercator 投影坐标系,广泛用于 Web 地图服务。
功能特性
- GCJ02 -> BD09 (
gcj02_to_bd09) - BD09 -> GCJ02 (
bd09_to_gcj02) - BD09 -> GCJ02 快速模式 (
bd09_to_gcj02_fast) - WGS84 -> GCJ02 (
wgs84_to_gcj02) - GCJ02 -> WGS84 (
gcj02_to_wgs84) - GCJ02 -> WGS84 快速模式 (
gcj02_to_wgs84_fast) - WGS84 -> BD09 (
wgs84_to_bd09) - BD09 -> WGS84 (
bd09_to_wgs84) - WGS84 -> EPSG:3857 (
wgs84_to_epsg3857) - EPSG:3857 -> WGS84 (
epsg3857_to_wgs84) - GCJ02 -> EPSG:3857 (
gcj02_to_epsg3857) - EPSG:3857 -> GCJ02 (
epsg3857_to_gcj02) - BD09 -> EPSG:3857 (
bd09_to_epsg3857) - EPSG:3857 -> BD09 (
epsg3857_to_bd09) - 中国大陆 GCJ02 转换区域判断 (
is_in_gcj02_region) - 中国大陆高性能转换 API
- 原地批量转换 API
GCJ02/BD09 偏移只在中国大陆转换区域内应用。区域外的地理坐标保持 WGS84。
安装
在你的 Cargo.toml 中添加:
[]
= "0.3.0"
快速开始
use *;
其他 API
use *;
// 判断是否位于 GCJ02 转换区域
let inside = is_in_gcj02_region;
// 已知坐标位于中国大陆时,可以跳过区域判断
let gcj = wgs84_to_gcj02_in_mainland;
let wgs = gcj02_to_wgs84_in_mainland;
// 快速逆转换
let _ = gcj02_to_wgs84_fast;
let _ = bd09_to_gcj02_fast;
// 原地批量转换
let mut points = ;
wgs84_to_gcj02_in_place;
批量转换 API:
wgs84_to_gcj02_in_placegcj02_to_wgs84_in_placewgs84_to_gcj02_in_mainland_in_placegcj02_to_wgs84_in_mainland_in_placewgs84_to_bd09_in_placebd09_to_wgs84_in_place
严格 EPSG:3857 API:
try_wgs84_to_epsg3857try_epsg3857_to_wgs84wgs84_to_epsg3857_clamped
测试
许可证
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。
内嵌的中国大陆转换区域数据基于 OpenStreetMap 数据简化生成,相关地理数据遵循 ODbL 1.0。
OpenStreetMap contributors: https://www.openstreetmap.org/copyright