Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I'm attempting to load a large number of features (up to 310k) into a feature class. It is functional at the moment, but speed is a major issue. It takes about .42 seconds per 1000 features. I've seen references to putting the feature class in LoadOnlyMode, but to do so I need to cast to IFeatureClassLoad. This cast always fails.

Here is how the feature class is created. It's nearly ripped straight out of an esri example page. I'm passing in a scratchworkspace created using the ScratchWorkspaceFactory, and thats pretty much the only thing of importance.

public IFeatureClass CreateFeatureClass(IWorkspace workspace, IFeatureDataset featureDataset, Type modelType, String featureClassName, UID CLSID, UID CLSEXT, String strConfigKeyword)
        if (featureClassName == "") return null;

        IFeatureClass featureClass;
        var featureWorkspace = (IFeatureWorkspace)workspace;

        var dataset = workspace.Datasets[esriDatasetType.esriDTFeatureClass].Next();
        while (dataset != null)
            if (dataset.Name == featureClassName)
                featureClass = featureWorkspace.OpenFeatureClass(featureClassName);
                return featureClass;

        // assign the class id value if not assigned
        if (CLSID == null)
            CLSID = new UID();

        IObjectClassDescription objectClassDescription = new FeatureClassDescription();
        var name = new FeatureClassName {NameString = "Collisions"};

        // create the fields using the required fields method
        var fields = objectClassDescription.RequiredFields;
        IFieldsEdit fieldsEdit = (IFieldsEdit)fields; // Explicit Cast

        var typeField = new Field();
        var editableField = (IFieldEdit)typeField;

        editableField.Name_2 = "TYPE";
        editableField.Type_2 = esriFieldType.esriFieldTypeString;
        editableField.IsNullable_2 = true;
        editableField.AliasName_2 = "TYPE";
        editableField.DefaultValue_2 = "Collision";
        editableField.Editable_2 = true;
        editableField.Length_2 = 100;

        foreach (var property in modelType.GetProperties().Where(x => x.GetCustomAttributes(typeof(SearchableAttribute), false).Any()))
            var returnType = property.GetGetMethod().ReturnType;
            var searchData = (SearchableAttribute)property.GetCustomAttributes(typeof(SearchableAttribute), false).First();
            IField field = new Field();
            var fieldEdit = (IFieldEdit)field;

            fieldEdit.Name_2 = searchData.DisplayName.Trim();
            fieldEdit.Type_2 = returnType == typeof(DateTime) ? esriFieldType.esriFieldTypeDate : esriFieldType.esriFieldTypeString;
            fieldEdit.IsNullable_2 = true;
            fieldEdit.AliasName_2 = searchData.DisplayName;
            fieldEdit.DefaultValue_2 = string.Empty;
            fieldEdit.Editable_2 = true;
            fieldEdit.Length_2 = 250;

            // add field to field collection
        fields = (IFields)fieldsEdit;

        String strShapeField = "";

        // locate the shape field
        for (var j = 0; j < fields.FieldCount; j++)
            var field = fields.Field[j];
            if (field.Type == esriFieldType.esriFieldTypeGeometry)
                strShapeField = field.Name;
                IGeometryDef geomDef = new GeometryDef();
                var geometryDefEdit = (IGeometryDefEdit)geomDef;
                geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                geometryDefEdit.SpatialReference_2 = ArcMap.Document.FocusMap.SpatialReference;
                ((IFieldEdit)field).GeometryDef_2 = geomDef;

        // Use IFieldChecker to create a validated fields collection.
        IFieldChecker fieldChecker = new FieldChecker();
        IEnumFieldError enumFieldError = null;
        IFields validatedFields = null;
        fieldChecker.ValidateWorkspace = (IWorkspace)workspace;
        fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

        // The enumFieldError enumerator can be inspected at this point to determine 
        // which fields were modified during validation.

        // finally create and return the feature class
        if (featureDataset == null)// if no feature dataset passed in, create at the workspace level
            featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, esriFeatureType., strShapeField, strConfigKeyword);
            featureClass = featureDataset.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword);

        return featureClass;

Once that's done I attempt to load the features from a list of geometry points. The code starts like this:

var featureWorkspace = (IFeatureWorkspace) workspace;
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(FeatureClassName);
var loader = featureClass as IFeatureClassLoad;
if (loader != null) loader.LoadOnlyMode = true;
var schemaLock = (ISchemaLock) featureClass;

where the loader variable is always null. am i missing something obvious? is my feature class not compatible with that interface?


In case anyone else comes across this, the problem here was that i was using the ScratchWorkspaceFactory. that class creates a personal geodatabase, and its features cannot be cast to IFeatureClassLoad. FileGDBScratchWorkspaceFactory creates Local file workspaces, and its feature classes can be cast to IFeatureClassLoad. Devil is in the details.

share|improve this question

marked as duplicate by Devdatta Tengshe, Petr Krebs, MappaGnosis, Zachary, iant Feb 26 '13 at 13:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

What kind of geodatabase are you using? File, Personal Or SDE? – Devdatta Tengshe Feb 24 '13 at 6:30
I have no idea what I'm doing with arcgis in general, so i imagine I'm using whatever the default thing is. – nathan gonzalez Feb 24 '13 at 18:33
@nathan, open up the data you're working with in ArcCatalog, it should tell you. If you can't figure it out, post a screenshot. – blah238 Feb 24 '13 at 19:52
ArcGIS developers need to have a basic understanding of the desktop apps and workflows IMO. Crack open the ArcGIS Desktop help and click around a bit, not too hard to figure out the basics. You do have Desktop installed right? – blah238 Feb 24 '13 at 20:18
@DevdattaTengshe, apparently i was using a personalgdb due to my use of the ScratchWorkspaceFactory. once i started using FileGDBScratchWorkspaceFactory blah238 pointed out to me i was able to cast successfully. – nathan gonzalez Feb 25 '13 at 4:30
up vote 5 down vote accepted

From the help on IFeatureClassLoad:

IFeatureClassLoad is an optional interface supported by feature classes in ArcSDE and feature classes and tables in File Geodatabase.

So because IFeatureClassLoad is an optional interface, you can't assume it is always available.

In fact it is only available on feature classes in SDE and feature classes and tables in file geodatabases. It is not implemented for shapefiles or personal geodatabase feature classes or tables, for example.

share|improve this answer
So, given i cant cast to that interface, is there any way to make the load faster? – nathan gonzalez Feb 24 '13 at 18:34
See this answer for some good tips: Performance of ArcGISScripting and large spatial data sets – blah238 Feb 24 '13 at 19:58
If that doesn't help, ask a new question. – blah238 Feb 24 '13 at 19:59

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