Friday, January 23, 2015

Parenting Win-form and WPF form in ArcMap

Be The First To Comment
Parenting of Win-form windows and WPF windows within a ArcMap application using C#.Net code snippets-

Step 1: Create a ArcMapWrapper.cs, wrapper class

        using System;
        using System.Windows.Forms;
        using ESRI.ArcGIS.Framework;

        namespace ArcMapClassLibrary2
        {
               class ArcMapWrapper:IWin32Window
               {
                    private IApplication _arcMapApplication;

                    public ArcMapWrapper( IApplication mApplication)
                    {
                       _arcMapApplication = mApplication;
                    }

                    public IntPtr Handle
                    {
                       get { return new IntPtr(_arcMapApplication.hWnd); }
           
                     }
                 }
           }

Step 2: Access from Win-form

              WinForm fm = new WinForm();                        
              ArcMapWrapper wrapper= new ArcMapWrapper(map_application);  
              fm.ShowInTaskbar = false;        
              fm.Show(wrapper);

              //Try, it behaves like a modal dialog
              //fm.ShowDialog()

Tuesday, January 13, 2015

Create standalone feature class and feature class inside feature dataset on Geodatabase using ArcObjects

Be The First To Comment
 public void StartUp()   
    {   
     try   
     {   
       //create gdb   
      const string path = "D:/SampleDatasets/NewShp";   
      const string fileGDBName = "sample.gdb";   
      const string fileGDBAddress = path + "/" + fileGDBName;   
      const string featureDatasetname="polygonFeatureClasses";   
      const string featureClassname = "MytestPolygons";   
      if (System.IO.Directory.Exists(fileGDBAddress))   
      {   
       Console.WriteLine("already exist");   
       // return;   
      }   
      Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");   
      IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);   
      IWorkspaceName workspaceName = workspaceFactory.Create(path, fileGDBName, null,ArcMap.Application.hWnd);   
      MessageBox.Show("gbd created!");   
      
      //Create feature dataset   
      IFeatureWorkspace fws = workspaceFactory.OpenFromFile(fileGDBAddress, ArcMap.Application.hWnd) as IFeatureWorkspace;   
      
     //check the existance of FeatureDataset   
      IWorkspace2 ws = fws as IWorkspace2;   
      if(ws.get_NameExists(esriDatasetType.esriDTFeatureDataset,featureDatasetname)==true)   
      {   
       MessageBox.Show("Feature dataset is already exists");   
      }  

      #region feature Class inside feature Dataset : Region_1 (Choose either Region_1 or Region_2)  
     
      //Create a spatial refrence/extract spatial refrence from map   
      //Infuture will access through the arcmap   
      ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();   
      int coordinateSystemID = (int) esriSRGeoCSType.esriSRGeoCS_WGS1984;   
      ISpatialReference spatialReference =spatialReferenceFactory.CreateGeographicCoordinateSystem(coordinateSystemID);   
      
 

© 2011 GIS and Remote Sensing Tools, Tips and more .. ToS | Privacy Policy | Sitemap

About Me