You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

EasyGIS.NET中BritishNationalGrid坐标系Shapefile加载后不可见问题咨询

British National Grid Shapefile Not Visible in EasyGIS.NET (With Mercator Projection Enabled)

我来帮你分析下这两个问题,结合EasyGIS.NET的工作机制逐一解答:

问题1:为何British National Grid Shapefile已加载却不可见?

这是坐标系范围不匹配导致的典型问题:

  • 当你设置sfMap1.UseMercatorProjection = true时,地图实际使用的是**Web Mercator(EPSG:3857)**坐标系,这个坐标系的坐标范围约为±20037508米,覆盖全球范围。
  • 而British National Grid(EPSG:27700)的坐标范围仅为x: 0~650000米、y: 0~1250000米,仅覆盖英国本土。
  • 你没有对Shapefile的坐标做转换,这些小范围的坐标会被渲染到Web Mercator坐标系的极小区域(相对于全球范围几乎是一个点),超出了当前地图视图的可见范围,所以看起来是空白,但数据确实已经加载(鼠标悬停能看到记录就是最直接的证明)。

问题2:British National Grid Shapefile是否会自动转换为WGS84坐标系?若需手动处理,具体方法是什么?

EasyGIS.NET不会自动进行坐标系转换,必须手动处理。具体步骤如下:

核心思路

将Shapefile的原始British National Grid(EPSG:27700)坐标转换为地图当前使用的Web Mercator(EPSG:3857)坐标(因为你开启了UseMercatorProjection = true,地图实际渲染用的是这个坐标系,而非你设置的WGS84)。

代码实现

// 加载Shapefile
ShapeFile shapeFile = new ShapeFile(path);

// 1. 获取或指定Shapefile的原始坐标系
// 如果Shapefile带有.prj文件,EasyGIS会自动读取,直接用下面的代码即可
var sourceCrs = shapeFile.CoordinateReferenceSystem;
// 如果没有.prj文件,手动指定British National Grid(EPSG:27700)
// var sourceCrs = EGIS.Projections.CoordinateReferenceSystemFactory.Default.GetCRSById(27700);

// 2. 指定目标坐标系:Web Mercator(EPSG:3857)
var targetCrs = EGIS.Projections.CoordinateReferenceSystemFactory.Default.GetCRSById(3857);

// 3. 创建坐标转换对象
var transformation = EGIS.Projections.CoordinateTransformationFactory.Default.CreateTransformation(sourceCrs, targetCrs);

// 4. 遍历所有记录,转换几何图形坐标
if (transformation != null)
{
    foreach (var record in shapeFile.Records)
    {
        if (record.Geometry != null)
        {
            record.Geometry.Transform(transformation);
        }
    }
}

// 5. 添加到地图并设置渲染属性
this.sfMap1.AddShapeFile(shapeFile);
shapeFile.RenderSettings.SelectFillColor = Color.Green;
shapeFile.RenderSettings.SelectOutlineColor = Color.Blue;
shapeFile.RenderSettings.IsSelectable = true;
shapeFile.SelectRecord(0, true);

补充说明

  • 如果你关闭UseMercatorProjection = false,地图使用的是你设置的WGS84(EPSG:4326)坐标系,此时British National Grid的米级坐标和WGS84的经纬度(范围±180, ±90)差异极大,所以图形显示位置不正确,这和你观察到的现象完全一致。
  • 确保你的Shapefile带有.prj文件,EasyGIS才能自动识别原始坐标系;如果没有,一定要手动指定EPSG:27700,否则转换会失败。

内容的提问来源于stack exchange,提问作者Richard

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 12:27:44