Select to view content in your preferred language

Using QueryBuilder dialog with raster files

1040
3
05-31-2012 02:43 PM
GaryPoole
Deactivated User
I'm using the built in QueryBuilder dialog to design my 'where' clauses with shapefiles. This code works great for me:
       
                IQueryBuilder queryBuilder = new QueryBuilder();
                String whereClause = String.Empty;
                String fullPath = "C:\\Test\\Shapefile.shp";

                String path = Path.GetDirectoryName(fullPath);
                String filename = Path.GetFileName(fullPath);

                // Set up the Shapefile query
                IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
                IWorkspace workspace = workspaceFactory.OpenFromFile(path, 0);

                IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
                IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(filename);

                ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = new ESRI.ArcGIS.Carto.FeatureLayer();
                featureLayer.FeatureClass = featureClass as IFeatureClass;

                ESRI.ArcGIS.Carto.ILayer layer = featureLayer;
                queryBuilder.Layer = layer;
                queryBuilder.WhereClause = whereClause;

                queryBuilder.DoModal(SettingsManager.ArcDesktopApplication.hWnd);


Now I'd like to do the same but with using a raster file. After several hours of investigating, I haven't found the magic solution. Any ideas?

Thanks!
0 Kudos
3 Replies
GaryPoole
Deactivated User
Any ideas anyone? I know this can be done, as it is used with the CON (Input conditional raster) geoprocess. Any help would be greatly appreciated!
0 Kudos
GaryPoole
Deactivated User
In case anyone is interested, the solution was to implement IQueryPropertyPage
0 Kudos
ChaoWang
Esri Contributor
Here's the detailed info:

(a)create a query property page by using IQueryPropertyPage interface
(b)Put the query property page in a property sheet by using AddPage method of the IComPropertySheet interface
(c)Display the property sheet in the application by using the EditProperties method of IComPropertySheet interface.

Sample codes with which I can open the query builder for rasters on my end successfully, please note the code is for demonstration purposes and please modify if necessary:

        String fullPath = @"C:\temp\testhillshade"; // Please modify the path here

            String path = Path.GetDirectoryName(fullPath);
            String filename = Path.GetFileName(fullPath);

            // Set up the Shapefile query
            //IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
            //IWorkspace workspace = workspaceFactory.OpenFromFile(path, 0);

            //IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
            //IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(filename);

            //Open raster workspacefactory
            IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();
            IWorkspace workspace = workspaceFactory.OpenFromFile(path, 0);

            //Raster dataset
            IRasterWorkspace RasterWorkspace = (IRasterWorkspace)workspace;
            IRasterDataset rasterDS = RasterWorkspace.OpenRasterDataset(filename);

            //Raster layer
            ESRI.ArcGIS.Carto.IRasterLayer rasterLayer = new ESRI.ArcGIS.Carto.RasterLayer();
            rasterLayer.CreateFromDataset(rasterDS);

            IQueryPropertyPage pQueryPropertyPage = new QueryPropertyPageClass();
            pQueryPropertyPage.Table = rasterLayer as ITable;
       
            ISet pSet = new SetClass();
            pSet.Add(rasterLayer);
            IComPropertySheet pSheet = new ComPropertySheetClass();
            pSheet.AddCategoryID(new UID());
            pSheet.AddPage(pQueryPropertyPage);
            pSheet.Title = "query";
            if (pSheet.EditProperties(pSet, ArcMap.Application.hWnd))
            {
            }

Here are also documents talking about the  property page:
Extending ArcObjects:Creating Property Pages
http://edndoc.esri.com/arcobjects/9.2/CPP_VB6_VBA_VCPP_Doc/COM/ExtendAO/PropertyPages.htm#Implementi...

How to open a layer's property pages using VBA in ArcMap
http://resources.arcgis.com/content/kbase?fa=articleShow&d=17082

Hope this helps,
Chelsea
0 Kudos