Exemple #1
0
        /// <summary>
        /// Opens an ArcGIS Style Dialog box instead of windows style one for shapefiles.
        /// </summary>
        public static string OpenShapeFileDialog2()
        {
            IGxDialog                 pGxDialog = new GxDialogClass();
            IGxObjectFilter           pFilter   = new GxFilterShapefilesClass();
            IGxObjectFilter           pFilter2  = new GxFilterSDEFeatureClasses();
            IGxObjectFilterCollection pFilterCollection;
            IEnumGxObject             pEnumGx;

            pFilterCollection = pGxDialog as IGxObjectFilterCollection;
            pFilterCollection.AddFilter(pFilter, true);
            pFilterCollection.AddFilter(pFilter2, true);
            pGxDialog.Title = "Browse Data";

            if ((bool)pGxDialog.DoModalOpen(0, out pEnumGx))
            {
                IGxObject pGxObject;
                pGxObject = pEnumGx.Next() as IGxObject;

                if (pGxObject is GxDataset)
                {
                    var path = pGxObject.FullName;
                    // Just in case releasing the com objects might help the issue:
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pGxObject);
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pGxDialog);
                    return(path);
                }
            }
            return(null);
        }
Exemple #2
0
 /// <summary>
 /// Opens a dialog so the user can select an existing shapefile or file geodatabase
 /// feature class.
 /// </summary>
 /// <param name="title">title for dialog</param>
 /// <returns>dataset name object for the selected feature class or null </returns>
 private IDatasetName SelectFeatureClass(string title, esriGeometryType geom)
 {
     try
     {
         IGxObjectFilter           shpFilter = new GxFilterShapefilesClass();
         IGxObjectFilter           gdbFilter = new GxFilterFGDBFeatureClassesClass();
         IGxDialog                 dlg       = new GxDialogClass();
         IGxObjectFilterCollection filters   = (IGxObjectFilterCollection)dlg;
         filters.AddFilter(shpFilter, false);
         filters.AddFilter(gdbFilter, true);
         dlg.Title = title;
         IDatasetName  dsName  = null;
         IEnumGxObject objects = null;
         if (dlg.DoModalOpen(0, out objects))
         {
             IGPUtilities2 util = new GPUtilitiesClass();
             string        name = objects.Next().FullName;
             dsName = (IDatasetName)util.CreateFeatureClassName(name);
             IFeatureWorkspace ws  = (IFeatureWorkspace)((IName)dsName.WorkspaceName).Open();
             IFeatureClass     fc  = ws.OpenFeatureClass(System.IO.Path.GetFileName(name));
             esriGeometryType  shp = fc.ShapeType;
             if (!(geom == esriGeometryType.esriGeometryAny &&
                   (shp == esriGeometryType.esriGeometryPoint ||
                    shp == esriGeometryType.esriGeometryPolyline ||
                    shp == esriGeometryType.esriGeometryPolygon)) &&
                 shp != geom)
             {
                 ShowError("Wrong geometry type.");
                 dsName = null;
             }
             dsName = (IDatasetName)((IDataset)fc).FullName;
         }
         return(dsName);
     }
     catch (Exception ex)
     {
         ShowError(ex.Message);
         return(null);
     }
 }
        /// <summary> Shows dialog for saving data.</summary>
        /// <param name="dialogTitle">The title of the dialog</param>
        /// <returns> the path to the file to save </returns>
        public static string ShowSaveDataDialog( string dialogTitle)
        {
            IGxObjectFilter shpFilter = new GxFilterShapefilesClass();
            IGxObjectFilter gdbFilter = new GxFilterFGDBFeatureClassesClass();
            List<IGxObjectFilter> gxFilterList = new List<IGxObjectFilter>(new IGxObjectFilter[] { gdbFilter, shpFilter});

            return ShowSaveDataDialog(gxFilterList, dialogTitle);
        }