转载自:http://blog.sina.com.cn/s/blog_6ed3b5170101jdj4.html
// 将经纬度点转换为平面坐标。
private IPoint GetProject(IActiveView pActiveView,double x, double y)
{
try
{
IMap pMap = pActiveView.FocusMap;
IPoint pt = new PointClass();
ISpatialReferenceFactory pfactory = new SpatialReferenceEnvironmentClass();
ISpatialReference flatref = pMap.SpatialReference;
ISpatialReference earthref = pfactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
pt.PutCoords(x, y);
IGeometry geo = (IGeometry)pt;
geo.SpatialReference = earthref;
geo.Project(flatref);
return pt;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
}
}
// 将平面坐标转换为经纬度。
private IPoint GetGeo(IActiveView pActiveView,double x, double y)
{
try
{
IMap pMap = pActiveView.FocusMap;
IPoint pt = new PointClass();
ISpatialReferenceFactory pfactory = new SpatialReferenceEnvironmentClass();
ISpatialReference flatref = pMap.SpatialReference;
ISpatialReference earthref = pfactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
pt.PutCoords(x, y);
IGeometry geo = (IGeometry)pt;
geo.SpatialReference = flatref;
geo.Project(earthref);
double xx = pt.X;
return pt;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
}
}
在使用时:IActiveView pActiveView = axMapControl1.ActiveView;
其他参考:::
public static void bj54tojingweiduAo(IActiveView pActiveView, double inx, double iny, ref string outx, ref string outy)
{
try
{
IMap pMap = pActiveView.FocusMap;
SpatialReferenceEnvironment pSpRE = new SpatialReferenceEnvironment();
IGeographicCoordinateSystem pGeoCS = pSpRE.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
ISpatialReference pSpr = pGeoCS;
IPoint pPoint = new ESRI.ArcGIS.Geometry.Point();
pPoint.X = inx;
pPoint.Y = iny;
IGeometry pGeo = pPoint;
pGeo.SpatialReference = pMap.SpatialReference;
pGeo.Project(pSpr);//坐标转换,由当前地图坐标转为北京54经纬度坐标
double jwd_jd = pPoint.X;
double jwd_wd = pPoint.Y;
//转化成度、分、秒
//经度
int Jd, Wd, Jf, Wf;
double temp;
Single Jm, Wm;
Jd = (int)jwd_jd; //度
temp = (jwd_jd - Jd) * 60;
Jf = (int)temp; //分
temp = (temp - Jf) * 60;
Jm = Convert.ToInt32(temp); //秒
//纬度
Wd = (int)jwd_wd; //度
temp = (jwd_wd - Wd) * 60;
Wf = (int)temp; //分
temp = (temp - Wf) * 60;
Wm = Convert.ToInt32(temp); //秒
outx = Jd + "度" + Jf + "分" + Jm + "秒";
outy = Wd + "度" + Wf + "分" + Wm + "秒";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}