Setting coordinate system for map using .net API

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.


Comments

3 responses to “Setting coordinate system for map using .net API”

  1. Mohammad Avatar
    Mohammad

    hi, How can I extract ground sampled section in civil3d to a text file containing Station(Kilometer),offset and elevation.

  2. Hi Mohammad,
    To make the blog more readable, we only answer questions related to the post itself. If you have any other questions, would you please ask through ADN site(if you are an ADN member) or ask in autodesk discussion group?
    Thank you for your understanding.

  3. Mohammad Avatar
    Mohammad

    thanks. No I’, not a member. I ‘ll ask it in discussion group.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading