using ProjNet.CoordinateSystems;
using ProjNet.Converters.WellKnownText;
using ProjNet.CoordinateSystems.Transformations;
///
/// 坐标位置结构体
///
public struct stPosition
{
public double X;
public double Y;
public stPosition(double x, double y)
{
X = x;
Y = y;
}
}
///
/// 将地理坐标转换为投影坐标
///
/// 原坐标系
/// 目标坐标系
/// 原始数据
/// 结果数据
/// 成功返回true
public static bool DegreeToMeter(ICoordinateSystem fromCS, ICoordinateSystem toCS, List
{
bool bRes = false;
results = new List
try
{
CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();
ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(toCS, fromCS);
results = trans.MathTransform.TransformList(pts);
bRes = true;
}
catch (SystemException sysEx)
{
}
return bRes;
}
///
/// 将投影坐标系数据转换为地理坐标系数据
///
/// 原坐标系
/// 目标坐标系
/// 原始数据
/// 结果数据
/// 成功返回true
public static bool MeterToDegree(ICoordinateSystem fromCS, ICoordinateSystem toCS, List
{
bool bRes = false;
results = new List
try
{
CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();
ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(fromCS, toCS);
results = trans.MathTransform.TransformList(pts);
bRes = true;
}
catch (SystemException sysEx)
{
}
return bRes;
}
///
/// 北京54投影坐标转换为地理坐标
///
/// 带号
/// 中央经线
/// 原始投影坐标数据
/// 转换后地理坐标
public static void BJ54PrjToGeo(int iCodeNum, double dCenter_Meridian, stPosition sourPt, out stPosition destPt)
{
destPt = new stPosition(0, 0);
try
{
//高斯克吕格投影类型|横轴莫卡托投影类型
string bj1954Lcc = string.Format(“PROJCS[“hejl”,”
+ “GEOGCS[“GCS_Beijing_1954”,”
+ “DATUM[“D_Beijing_1954”, SPHEROID[“Krasovsky_1940”, 6378245.0, 298.3]],”
+ “PRIMEM[“Greenwich”, 0.0],”
+ “UNIT[“Degree”, 0.017453292519943299]],”
+ “PROJECTION[“Transverse Mercator”],”
+ “PARAMETER[“False_Easting”, {0}500000.0],”
+ “PARAMETER[“False_Northing”, 0.0],”
+ “PARAMETER[“Central_Meridian”, {1} ],”
+ “PARAMETER[“Scale_Factor”, 1],”
+ “PARAMETER[“Latitude_Of_Origin”, 0],”
+ “UNIT[“Meter”, 1]];”, iCodeNum, dCenter_Meridian);
IProjectedCoordinateSystem fromCS = CoordinateSystemWktReader.Parse(bj1954Lcc) as IProjectedCoordinateSystem;
GeographicCoordinateSystem toCS = (GeographicCoordinateSystem)fromCS.GeographicCoordinateSystem;
List
double[] xy = new double[] { sourPt.X, sourPt.Y };
pts.Add(xy);
List
//执行转换函数
MeterToDegree(fromCS, toCS, pts, out results);
destPt.X = results[0][0];
destPt.Y = results[0][1];
}
catch (SystemException sysEx)
{
}
}
///
/// 北京54地理坐标转换为投影坐标,批量转换
///
/// 带号
/// 中央经线
/// 原始投影坐标数据
/// 转换后地理坐标
public static void GeoToBJ54Prj(int iCodeNum, double dCenter_Meridian, stPosition sourPt, out stPosition destPt)
{
destPt = new stPosition(0, 0);
try
{
//高斯克吕格投影类型|横轴莫卡托投影类型
作者:金龙-Super
来源:CSDN
原文:https://blog.csdn.net/gishjl/article/details/7637789?utm_source=copy
版权声明:本文为博主原创文章,转载请附上博文链接!