// 将经纬度点转换为平面坐标。
private IPoint GetProject(IActiveViewpActiveView,double x, double y)
{
try
{
IMap pMap =pActiveView.FocusMap;
IPoint pt = newPointClass();
ISpatialReferenceFactory
pfactory = new SpatialReferenceEnvironm
entClass();
ISpatialReference flatref =pMap.SpatialReference;
ISpatialReference earthref =pfactory.CreateGeographicCoordina
teSystem((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(IActiveViewpActiveView,double x, double y)
{
try
{
IMap pMap =pActiveView.FocusMap;
IPoint pt = newPointClass();
ISpatialReferenceFactory
pfactory = new SpatialReferenceEnvironm
entClass();
ISpatialReference flatref =pMap.SpatialReference;
ISpatialReference earthref =pfactory.CreateGeographicCoordina
teSystem((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(IActiveViewpActiveView, double inx, double iny, ref string outx, ref stringouty)
{
try
{
IMap pMap =pActiveView.FocusMap;
SpatialReferenceEnvironm
entpSpRE = new SpatialReferenceEnvironm
ent();
IGeographicCoordinateSys
tempGeoCS =pSpRE.CreateGeographicCoordina
teSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
ISpatialReference pSpr =pGeoCS;
IPoint pPoint = newESRI.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);
}
}