使用GDAL库进行坐标转换的步骤如下:
using OSGeo.GDAL;
using OSGeo.OSR;
Gdal.AllRegister();
OSR.SpatialReference source = new OSR.SpatialReference("");
source.ImportFromEPSG(4326); // 源坐标系为WGS84经纬度坐标系
OSR.SpatialReference target = new OSR.SpatialReference("");
target.ImportFromEPSG(3857); // 目标坐标系为Web墨卡托投影坐标系
OSR.CoordinateTransformation transform = new OSR.CoordinateTransformation(source, target);
double[] sourcePoint = new double[] { 102.0, 30.0 }; // 源坐标点经度和纬度
double[] targetPoint = new double[3]; // 用于保存转换后的目标坐标点
transform.TransformPoint(targetPoint, sourcePoint);
转换后的目标坐标点可以从targetPoint数组中获取,一般情况下目标坐标点的前两个元素分别为转换后的横坐标和纵坐标。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:C# gdal 空间分析功能介绍