1

My debugger crashes without showing any error.

It crashes not even catches exception on the line:

rasterWorkspace.CreateRasterCatalog(catalogName, fields, "Shape", "Raster", "defaults");

Code snippet below:

CreateRasterCatalog(@"D:\TestfGDB\TestfGDB.gdb", "Test2");

    public void CreateRasterCatalog(string fGDBPath, string catalogName)
    {
        try
        {
            IRasterWorkspaceEx rasterWorkspace = OpenFileGDBWorkspace(fGDBPath);
            IFields fields = CreateField(null, null);
            IRasterCatalog rasterCatalog = rasterWorkspace.CreateRasterCatalog(catalogName, fields, "Shape", "Raster", "defaults");
        }
        catch (Exception e)
        {
            string msg = e.Message;
        }
    }
    /// <summary>
    /// Opens a File geodatabase workspace. 
    /// </summary>
    /// <param name="filePath">FGDB file path</param>
    protected IRasterWorkspaceEx OpenFileGDBWorkspace(string filePath)
    {
        IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
        IRasterWorkspaceEx workspaceEx = (IRasterWorkspaceEx)workspaceFactory.OpenFromFile(filePath, 0);
        return workspaceEx;
    }

    public IFields CreateField(ISpatialReference rasterSpatRef, ISpatialReference geoSpatRef)
    {
        IFields fields = new Fields();
        IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields;
        ESRI.ArcGIS.Geodatabase.IField field = new ESRI.ArcGIS.Geodatabase.FieldClass();
        // create a user defined text field
        ESRI.ArcGIS.Geodatabase.IFieldEdit fieldEdit = (ESRI.ArcGIS.Geodatabase.IFieldEdit)field;

        // setup field properties
        fieldEdit.Name_2 = "OBJECTID";
        fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeOID;
        //fieldEdit.IsNullable_2 = true;
        //fieldEdit.AliasName_2 = "Sample Field Column";
        //fieldEdit.DefaultValue_2 = "test";
        //fieldEdit.Editable_2 = true;
        //fieldEdit.Length_2 = 100;
        fieldsEdit.AddField(field);


        // setup field properties
        fieldEdit.Name_2 = "Shape";
        fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry;
        //fieldEdit.IsNullable_2 = true;
        //fieldEdit.Editable_2 = true;
        fieldsEdit.AddField(field);

        // setup field properties
        fieldEdit.Name_2 = "Raster";
        fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeRaster;
        //fieldEdit.IsNullable_2 = true;
        //fieldEdit.Editable_2 = true;
        fieldsEdit.AddField(field);

        // setup field properties
        fieldEdit.Name_2 = "Name";
        fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString;
        //fieldEdit.IsNullable_2 = true;
        //fieldEdit.Editable_2 = true;
        fieldsEdit.AddField(field);

        // setup field properties
        fieldEdit.Name_2 = "Metadata";
        fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeBlob;
        //fieldEdit.IsNullable_2 = true;
        //fieldEdit.Editable_2 = true;
        fieldsEdit.AddField(field);

        // setup field properties
        fieldEdit.Name_2 = "Shape_Length";
        fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDouble;
        //fieldEdit.IsNullable_2 = true;
        //fieldEdit.Editable_2 = true;
        fieldsEdit.AddField(field);

        // setup field properties
        fieldEdit.Name_2 = "Shape_Area";
        fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDouble;
        //fieldEdit.IsNullable_2 = true;
        //fieldEdit.Editable_2 = true;
        fieldsEdit.AddField(field);

        fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; 


        //// add OID field

        //fields.addField(createOIDField("ObjectID"));
        //// add NAME field
        //fields.addField(createNameField("name"));
        //// add RASTER field
        //fields.addField(createRasterField("raster", isByRef, rasterSpatRef));
        //// add SHAPE field
        //fields.addField(createShapeField("shape", geoSpatRef));

        return fields;
    }
  • Your line IFields fields = CreateField(null, null); is passing in NULL values, but your need to set the spatialrefence of your catalog. I think these need to be changed to spatialrefences for your code to work. – Hornbydd Oct 16 '13 at 15:52
  • Thank you, passing spatial reference didn't solve the issue. However, figured using Geoprocessor is easier to create. – Chris Lim Oct 17 '13 at 12:26
  • It would be good if you upload your solution and mark it solved for others to benefit. – Hornbydd Oct 17 '13 at 14:17
1

This fixed the issue. Thanks. fGDBPath is full path of fGDB. i.e. C:\test\test.gdb

    public void CreateRasterCatalog(string fGDBPath, string catalogName)
    {
        Geoprocessor geoprocessor = new Geoprocessor();

        //Create an unmanaged raster catalog in the newly created personal GDB
        CreateRasterCatalog createRasterCatalog = new CreateRasterCatalog();

        createRasterCatalog.out_path = fGDBPath;
        createRasterCatalog.out_name = catalogName;
        createRasterCatalog.raster_management_type = "unmanaged";
        ISpatialReferenceFactory ipFactory = new SpatialReferenceEnvironmentClass();
        ISpatialReference xySpatialReference = ipFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
        createRasterCatalog.spatial_reference = xySpatialReference;
        createRasterCatalog.raster_spatial_reference = xySpatialReference;
        geoprocessor.Execute(createRasterCatalog, null);
    }

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.