5

ArcGIS 10.1 with VB2010 I am using the GxDialog to get the users option to save a feature class. The target can be a shapefile, geodatabase, or Dataset inside a geodatabase. I can’t wrap my head around how I am supposed to parse the Workspace, FeatureDataset, and FeatureClass name to use in creating the feature class.

So far I have

    'setup the save dialog
    Dim pGxDialog As IGxDialog = New GxDialog
    Dim pGxObjFilterSh As IGxObjectFilter = New GxFilterShapefiles          'shapefiles
    Dim pGxObjFilterPg As IGxObjectFilter = New GxFilterPGDBFeatureClasses  'personal geodb (Access db)
    'Dim pGxObjFilterFg As IGxObjectFilter = New GxFilterFGDBFeatureClasses  'file geodb (ESRI db)
    Dim pGxObjectFilterCollection As IGxObjectFilterCollection = CType(pGxDialog, IGxObjectFilterCollection)
    pGxObjectFilterCollection.AddFilter(pGxObjFilterSh, True)
    pGxObjectFilterCollection.AddFilter(pGxObjFilterPg, False) 'this one actually contains both file and personal geodb feature classes
    'pGxObjectFilterCollection.AddFilter(pGxObjFilterFg, False)

    'get the users selection (it can be a shapefile or a geodb). Catalog paths consist of two parts: the workspace and the base name.
    If pGxDialog.DoModalSave(MyApp.hWnd) Then
        Dim catalogPath As String = My.Computer.FileSystem.CombinePath(pGxDialog.FinalLocation.FullName, pGxDialog.Name)
        Dim workspaceCategory As String = pGxDialog.FinalLocation.Category
        Debug.Print(String.Format("catalogPath={0}, workspaceCategory={1}", catalogPath, workspaceCategory))
        Debug.Print("ClassID={0}", pGxDialog.FinalLocation.ClassID)

        'I can use the workspaceCategory to get the target type. But how do I split out either the entire string path or
        'the pGxDialog to create a Workspace object. How do I set up the objects to allow a Feature Dataset?
  Select Case workspaceCategory
      Case "Personal Geodatabase", "Personal Geodatabase Feature Dataset"
          'personal geodb (Access database C:\myData\mypGDB.mdb)
          wkspFactory = New AccessWorkspaceFactory
          pCLSID.Value = "esriGeodatabase.Feature"
      Case "File Geodatabase", "File Geodatabase Feature Dataset"
          'file geodb (File database C:\myData\myfGDB.gdb)
          wkspFactory = New FileGDBWorkspaceFactory
          pCLSID.Value = "esriGeodatabase.Feature"
      Case "Folder"
          'shapefile (c:\mydata\)
          wkspFactory = New ShapefileWorkspaceFactory
          pCLSID.Value = "esriCore.Feature"
      Case Else
          Throw New Exception("Unsupported workspace category: " & workspaceCategory)
  End Select
    End If
  • There's a bit of code gis.stackexchange.com/questions/246467/… that contains a working DoModalSave in the first part of the code, that may help you a little bit. – Michael Stimson Jul 7 '17 at 1:52
  • Thanks for the tip. That code basically gets the catalogPath using IGxObject which you can get from the GxDialog itself. let me look if anything else is exposed through IGxObject. – sinDizzy Jul 7 '17 at 15:03
3

I've used this to open a workspace before. this only does File GDBs and Shapefiles though, I haven't worked with Access DBs before. Check out here to get an idea of what other things IGxObject can potentially represent.

private void GetWorkspace()
{
    IEnumGxObject pEnumGxObj = null;
    IGxDialog pGxDialog = new GxDialog();
    IGxObjectFilter pGxObjFilter = new GxFilterContainers();
    pGxDialog.AllowMultiSelect = false;
    pGxDialog.ObjectFilter = pGxObjFilter;
    pGxDialog.Title = "Select Workspace";
    pGxDialog.ButtonCaption = "Open";

    if (pGxDialog.DoModalOpen(0, out pEnumGxObj))
    {
        IGxObject gxObj = pEnumGxObj.Next();
        IWorkspace ws = null;

        if (gxObj is IGxDatabase)
        {
            IGxDatabase pGxDatabase = gxObj as IGxDatabase;

            ws = pGxDatabase.Workspace;
        }
        else if (gxObj is IGxFolder)
        {
            IGxFolder gxFolder = gxObj as IGxFolder;
            IGxFile file = gxFolder as IGxFile;
            IWorkspaceFactory wsf = new ShapefileWorkspaceFactory();
            ws = wsf.OpenFromFile(file.Path, 0);
        }
    }
}
  • That's for DoModalOpen. I am using DoModalSave. However I think I can use DoModalOpen since its just a dialog. – sinDizzy Jul 6 '17 at 22:51
  • Access databases (personal GDB) are very similar to file GDB, a major difference is in creating a workspace object via an IWorkspaceFactory (= new AccessWorkspaceFactory()), after that there isn't much difference in the methods; the pGDB only supports one level of spatial index but fGDB supports 3. There is a difference between open and save, the object exists with open, properties can be gained for it, I vaguely recall the IGxObject on save has a workspace and name but don't recall if the feature dataset is in it or not. Try debug, break on the first line after save and look at the values. – Michael Stimson Jul 7 '17 at 1:45
  • Thank you. I have all the code for creating workspaces for various types of feature classes. I think I am good there. I just don't see how I get all the parameters needed from GxDialog.DoModalSave. I just tested and can't use DoModalOpen since that requires an existing feature class. For my purposes the user is creating a brand new feature class. – sinDizzy Jul 7 '17 at 14:57
  • @sinDizzy Did you ever get this sorted? – Barbarossa Oct 5 '18 at 14:01
  • Not really. I instead opted to not let the user type in their final location. I instead force them to browse to it. – sinDizzy Oct 7 '18 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.