Mapguide - add gridfiles to transformation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This is cross posted from the Map Developer forum. I know I shouldn't do that but answers are rare there.
I am trying to simulate the manual process of adding grid files to coordinate transformation definitions (MAPCSLIBRARY - Edit). The code below generates a "System is Protected" error and I can't figure out why - or how to solve this.
Here's the contents of the post.
I want to add the Canada NTV2_0.gsb file to the built in NAD27_to_NAD83 transformation definition. I am getting a "system is protected" error. I think part of the problem is the collection I am trying to pass. I have the gsb file in the folder but it is not assigned to the transformation yet.
I am trying to automate the manual process (MAPCSLIBRARY - Edit). According to the MapGuide documentation "NewGridFile Creates a new, empty MgCoordinateSystemGeodeticTransformGridFile object that can be added to the collection set via SetGridFiles". That is the part I can't figure out.
The error occurs on defparams.SetGridFiles(newgridfiles); Below it is commented out - remove the comments for the error msg.
[CommandMethod("modtrans")] public void modtrans() { Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; string msg = "modtrans"; // MgCoordinateSystemFactory csysfactory = new MgCoordinateSystemFactory(); MgCoordinateSystemCatalog csyscatalog = csysfactory.GetCatalog(); MgCoordinateSystemGeodeticTransformDefDictionary transformsdict = csyscatalog.GetGeodeticTransformDefDictionary(); MgCoordinateSystemEnum transformsenum = transformsdict.GetEnum(); MgStringCollection transformnames = transformsenum.NextName(transformsdict.GetSize()); for (int i = 0; i < transformsdict.GetSize(); i++) { MgCoordinateSystemGeodeticTransformDef transformdef = transformsdict.GetGeodeticTransformationDef(transformnames.GetItem(i)); if (transformdef.GetTransformName().ToString() == "NAD27_to_NAD83") { MgCoordinateSystemGeodeticInterpolationTransformDefParams defparams = transformdef.GetParameters() as MgCoordinateSystemGeodeticInterpolationTransformDefParams; MgDisposableCollection gridfilelist = defparams.GetGridFiles(); MgDisposableCollection newgridfiles = new MgDisposableCollection(); if (gridfilelist.GetCount() > 0) { msg += "\noriginal gridfile count " + gridfilelist.GetCount(); for (int j = 0; j < gridfilelist.GetCount(); j++) { MgCoordinateSystemGeodeticTransformGridFile gridfile = (MgCoordinateSystemGeodeticTransformGridFile)gridfilelist.GetItem(j); msg += "\ngrid file " + gridfile.GetFileName(); newgridfiles.Add(gridfile); }// for int j }// if gridfile count > 0 // this is what I am trying to do // from the MapGuide API Reference I am using // virtual MgCoordinateSystemGeodeticTransformGridFile* MgCoordinateSystemGeodeticInterpolationTransformDefParams::NewGridFile // () [pure virtual] // Creates a new, empty MgCoordinateSystemGeodeticTransformGridFile object that can be added to the collection set via SetGridFiles. // Returns: // Returns a new, unitialized MgCoordinateSystemGeodeticTransformGridFile instance The caller is resonsible for disposing // the object if no longer needed. MgCoordinateSystemGeodeticTransformGridFile addgsbfile = defparams.NewGridFile(); string gsbdestination = "C:\\ProgramData\\Autodesk\\Geospatial Coordinate Systems 14.00\\Canada"; string gridfilename = gsbdestination + "\\ntv2_0.gsb"; addgsbfile.SetFileName(gridfilename); addgsbfile.SetFileFormat(2); // ntv2 newgridfiles.Add(addgsbfile); msg += "\nnew gridfile count " + newgridfiles.GetCount(); // this generates a "The coordinate system initialization failed. The system is protected" error // defparams.SetGridFiles(newgridfiles); }// if its the transformation to change }// for int i ed.WriteMessage(msg); }// modtrans