C#GDAL示例代码
时间: 2023-10-27 20:08:09 浏览: 73
以下是使用C#和GDAL库进行坐标转换的示例代码:
```
using OSGeo.GDAL;
public class CoordinateTransformation
{
public void TransformCoordinates()
{
// 注册所有的GDAL驱动
Gdal.AllRegister();
// 创建源坐标系
SpatialReference srcSrs = new SpatialReference(null);
srcSrs.ImportFromEPSG(4326); // EPSG 4326代表WGS84坐标系,即地理坐标系
// 创建目标坐标系
SpatialReference targetSrs = new SpatialReference(null);
targetSrs.ImportFromEPSG(3857); // EPSG 3857代表Web墨卡托投影坐标系
// 创建坐标转换对象
CoordinateTransformation transform = new CoordinateTransformation(srcSrs, targetSrs);
// 输入地理坐标
double[] lon = new double[] { 116.398, 121.473 };
double[] lat = new double[] { 39.913, 31.230 };
// 创建输出投影坐标数组
double[] x = new double[lon.Length];
double[] y = new double[lat.Length];
// 进行坐标转换
transform.TransformPoint(x, y, null);
// 输出投影坐标
for (int i = 0; i < lon.Length; i++)
{
Console.WriteLine("经度: " + lon[i] + ",纬度: " + lat[i]);
Console.WriteLine("X坐标: " + x[i] + ",Y坐标: " + y[i]);
}
}
}
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)