By Daniel Du
You probably have already known that we can get the current coordinate system of map with following code snippet:
[CommandMethod("GetMapCoordinateSystem")]
public void GetMapCoordinateSystem()
{
AcMapMap currentMap = AcMapMap.GetCurrentMap();
string srs = currentMap.GetMapSRS();
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application
.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("current coordinate system is : " + srs);
}
And I have been asked many times, how to set a coordinate system to a map? Here is the solution:
[CommandMethod("SetMapCoordinateSystem")]
public void SetMapCoordinateSystem()
{
//the parameter is coordinate system code
SetMapSRS("CA-I");
string wkt = AcMapMap.GetCurrentMap().GetMapSRS();
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application
.DocumentManager.MdiActiveDocument.Editor;
MgCoordinateSystemFactory coordSysFac =
new MgCoordinateSystemFactory();
string code = coordSysFac.ConvertWktToCoordinateSystemCode(wkt);
ed.WriteMessage("\n MapSRS is Changed to: " + code + "\n");
}
public void SetMapSRS(string srsCode)
{
Autodesk.Gis.Map.MapApplication mapApp = Autodesk.Gis.Map
.HostMapApplicationServices.Application;
Autodesk.Gis.Map.Project.ProjectModel projModel
= mapApp.ActiveProject;
projModel.Projection = srsCode;
}
Hope this helps.