using OSGeo.GDAL;
using OSGeo.OSR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Chapter02
{
class Program
{
static void Main(string[] args)
{
SetGCS();
Console.WriteLine("\n" + "坐标转换:");
CoordinateTransform();
Console.ReadKey();
}static void SetGCS()
{
SpatialReference osr = new SpatialReference("");
//设置地理坐标系
//osr.SetGeogCS("My GCS",
//"WGS_1984",
//"My WGS84 Spheroid",
//Osr.SRS_WGS84_SEMIMAJOR,
//Osr.SRS_WGS84_INVFLATTENING,
//"Greenwich", 0.0,
//"degree",
//0.017453925199433);
osr.SetWellKnownGeogCS("WGS84");
//osr.SetWellKnownGeogCS("EPSG:4326");
//osr.SetFromUserInput("");
string strWkt;
osr.ExportToWkt(out strWkt);
Console.WriteLine("普通WKT:");
Console.WriteLine(strWkt);
Console.WriteLine();
string strPrettyWkt;
osr.ExportToPrettyWkt(out strPrettyWkt, 0);
Console.WriteLine("美观WKT:");
Console.WriteLine(strPrettyWkt);
}static void CoordinateTransform()
{
//string strXian80 = "+proj=tmerc+lat_0=0+lon_0=117 +k=1+ x_0=39500000+y_0=0 +ellps=";
//strXian80 += "IAU76+towgs84=34.65192983,-69.97976937,-69.52875538,-0.56104022,";
//strXian80 += "-1.34050334,1.9067841,-0.27446825 +units=m +no_defs";
string filePath = @"E:\TEMP\project\123.tif";
Gdal.AllRegister();
Dataset ds = Gdal.Open(filePath, Access.GA_ReadOnly);
string temp = ds.GetProjectionRef();
Console.WriteLine(temp);
SpatialReference oXian80 = new SpatialReference(temp);
SpatialReference oLatLong;
//构造投影坐标系
//oXian80.SetFromUserInput(strXian80);
//获取该投影坐标系统中的地理坐标系
oLatLong = oXian80.CloneGeogCS();
//构造一个从UTM投影坐标系统到地理坐标系统的转换关系
CoordinateTransformation ct = new CoordinateTransformation(oXian80, oLatLong);
if(ct==null)
{
Console.WriteLine("构造坐标转换关系失败");
return;
}double[] dX = new double[2] {39464667.861,39458907.868 };
double[] dY = new double[2] { 4441766.356, 4444406.349 };
double[] dZ = new double[2] { 0, 0 };
Console.WriteLine("转换前:");
Console.WriteLine("1:({0},{1})", dX[0], dY[0]);
Console.WriteLine("2:({0},{1})", dX[1], dY[1]);
ct.TransformPoints(2, dX, dY, dZ);
Console.WriteLine("转换后:");
Console.WriteLine("1:({0},{1})", dX[0], dY[0]);
Console.WriteLine("2:({0},{1})", dX[1], dY[1]);
}
}
}
【C/C++/C#与RS|GDAL创建坐标系与坐标转换】效果:
文章图片
推荐阅读
- c/c++|有感 Visual Studio 2015 RTM 简介 - 八年后回归 Dot Net,终于迎来了 Mvc 时代,盼走了 Web 窗体时代...
- C/C++|C/C++ basis 02
- Qt实战|Qt+OpenCV联合开发(二十一)--图像翻转与旋转
- Qt实战|Qt+OpenCV联合开发(十四)--图像感兴趣区域(ROI)的提取
- Qt实战|Qt+OpenCV联合开发(十三)--通道分离与合并
- opencv|Qt+OpenCV联合开发(十六)--图像几何形状绘制
- Qt实战|Qt+OpenCV联合开发(十七)--随机数与随机颜色
- SNAT的MASQUERADE地址选择与端口选择
- IPTABLES的连接跟踪与NAT分析
- IPVS分析