proj4 报 unknown projection: EPSG:4547
同样的转换代码,换一个 EPSG 码就抛异常,控制台只说「未知投影」。
现象
浏览器控制台报:
Uncaught Error: unknown projection: EPSG:4547
at proj4 (proj4.js:1:1)
at <anonymous>:1:1
同一份代码把目标换成 EPSG:3857 就正常,
EPSG:4326 也正常,只有 4547、4526、4490 这些 CGCS2000 相关码报错。
原因
proj4js 自带一张内置定义表,覆盖 4326、3857、326xx、327xx 等常用码,
但并不包含中国国家 2000 坐标系的全部 EPSG 定义。
传入未注册的码时,内部查表返回 undefined,直接抛错。
需要注意:4490 在部分版本里也不在内置表中,
只是有些构建把 EPSG:4326 的定义复用了过来,才看起来能用。
这种「能用」是不可靠的,因为它没有 ellps=GRS80。
排查过程
- 在控制台执行
proj4.defs('EPSG:4547'),返回undefined即未注册。 - 执行
proj4.defs('EPSG:3857')作对照,返回一个对象说明内置表可用。 - 到 EPSG 官网或 proj4js 的
defs.js里查该码的 PROJ 字符串。 - 确认注册时
defs的两个参数没有被写反,第一个必须是形如EPSG:xxxx的名称。
console.log(proj4.defs('EPSG:4547')); // undefined
console.log(proj4.defs('EPSG:3857')); // { title: 'WGS 84 / Pseudo-Mercator', ... }
解决方案
在使用前显式注册。CGCS2000 3 度带 111°E(带号 37)的 PROJ 字符串如下,
参数顺序不能乱,lon_0 错一位整片数据就偏 3 度。
// EPSG:4547 = CGCS2000 / 3-degree Gauss-Kruger CM 111E
proj4.defs('EPSG:4547',
'+proj=tmerc +lat_0=0 +lon_0=111 +k=1 +x_0=500000 +y_0=0' +
' +ellps=GRS80 +units=m +no_defs');
// EPSG:4490 = CGCS2000 地理 2D
proj4.defs('EPSG:4490',
'+proj=longlat +ellps=GRS80 +no_defs');
// 之后即可正常转换
proj4('EPSG:4547', 'EPSG:4490', [500000, 3800000]);
// => [111.0, 34.32] 左右
OpenLayers 项目里则要交给 register,不要绕过它直接用 proj4。
import { register } from 'ol/proj/proj4';
import proj4 from 'proj4';
proj4.defs('EPSG:4547', '+proj=tmerc +lat_0=0 +lon_0=111 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs');
register(proj4);
验证
注册后 proj4.defs('EPSG:4547') 返回对象;
用中央经线上的点 111, 34.32 正算,x 必须恰好是 500000,y 在 3800000 附近。
const xy = proj4('EPSG:4490', 'EPSG:4547', [111, 34.32]);
console.assert(Math.abs(xy[0] - 500000) < 0.001, '假东不对');
console.assert(Math.abs(xy[1] - 3800000) < 500, '纵坐标量级不对');
适用版本
| 库 | 版本 | 内置 4490 / 4547 |
|---|---|---|
| proj4js | 2.6 ~ 2.9 | 均不含 |
| proj4js | 2.10 ~ 2.11 | 4490 部分构建含,4547 不含 |
| ol/proj | 7.x ~ 9.x | 4326 / 3857 免注册,其它需 register |
| Leaflet | 1.x | 使用 proj4leaflet 时同样必须先 defs |
经纬志(2026)。《proj4 报 unknown projection: EPSG:4547》。https://www.jingweizhi.com/cookbook/proj4-defs-missing.html(访问日期 2026-11-03)。