Here is the vector layer loading method, because the layer itself is already produced by the Mxd class project file, so directly using the Mxd loading mode
If(Axmapcontrol1.checkmxfile (Shpfile))//determine if an mxd file{IArray pArry; PArry=axmapcontrol1.readmxmaps (Shpfile, Type.Missing); IMap PMap; for(inti =0; i < Parry.count; i++) {PMap= Parry.get_element (i) asIMap; if(Pmap.name = ="Layers") {Axmapcontrol1.mousepointer=Esricontrolsmousepointer.esripointerhourglass; Axmapcontrol1.loadmxfile (Shpfile,0, Type.Missing); Axmapcontrol1.mousepointer=Esricontrolsmousepointer.esripointerdefault; } }
///Here is how the raster layer is loaded, you need to open the Iworkspace
StringFilePath ="file path"; stringPathName =System.IO.Path.GetDirectoryName (FilePath); stringFileName =System.IO.Path.GetFileName (FilePath); Iworkspacefactory pwsf; Pwsf=NewRasterworkspacefactoryclass (); Iworkspace PWS; PWS= Pwsf.openfromfile (PathName,0); Irasterworkspace Prws; Prws= PWS asIrasterworkspace; Irasterdataset Prasterdataset; Prasterdataset=Prws.openrasterdataset (fileName); Irasterpyramid Praspyrmid; Praspyrmid= Prasterdataset asIrasterpyramid; if(Praspyrmid! =NULL) { if(!(praspyrmid.present)) {praspyrmid.create (); }} Iraster Praster; Praster=Prasterdataset.createdefaultraster (); Irasterlayer Prasterlayer; Prasterlayer=NewRasterlayerclass (); Prasterlayer.createfromraster (Praster); ILayer PLayer= Prasterlayer asILayer; Axmapcontrol1.addlayer (PLayer,2);//set the display hierarchy for a raster layer
Loading of ArcGis Engine vector layers and raster layers