Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm developing an ArcMap extension and looking for a way to change feature attributes knowing its feature class and OID (and, presumably, everything else that there is in IFeature). All layers use ArcSDE datasets.

What's the right way to do it? Should I change the data in database? It feels like I shouldn't but I can't figure out how to change feature fields values using ArcObjects. The documentation for ArcObjects looks incomplete and awkward to use.

Background info: the extension provides a custom tool that processes selected feature and changes one of its attributes. Now, feature processing involves calling a remote service so it's an asynchronous operation and I should place all my updating logic in the callback method. The tool should work with any of the project layers all of which are ArcSDE datatsets. That's basically the requirements.

If anyone can help me with an advice or a working sample, I would be really grateful. Thanks in advance.

share|improve this question
    
I just re-read your ? after posting my answer: do you already have an IFeatureClass? –  Jay Cummins Jul 6 '11 at 12:27
    
Please elaborate on what you mean by "remote service". –  Kirk Kuykendall Jul 6 '11 at 13:42
    
@Kirk Kuykendall: by that I mean a WCF service that processes feature data and returns the result asynchronously –  Dyppl Jul 7 '11 at 4:26
    
@Jay Cummins: let's say yes, I have an IFeatureClass object –  Dyppl Jul 7 '11 at 4:27
1  
I'm not certain, but by using async requests I think you'll need to consider multithreading issues. –  Kirk Kuykendall Jul 7 '11 at 14:01
add comment

1 Answer

up vote 5 down vote accepted

Below are a couple of extension methods for IFeature/IRow that show the actual setting of a value. You'll want to check out cursors and row/feature buffers if you need better performance: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/0001000002rs000000.htm

the extension methods would need to be called when you are already in an edit operation (editor.StartOperation()/editor.StopOperation()): http://resources.esri.com/help/9.3/ArcGISDesktop/dotnet/abbd6e92-04f8-4957-a205-a53773fbf023.htm

    /// <summary>
    /// Sets the value on IFeature
    /// </summary>
    /// <param name="feature">The feature with the field to be set</param>
    /// <param name="fieldName">Name of the field.</param>
    /// <param name="value">The new field value</param>
    /// <param name="ignoreMissingFields">if set to <c>true</c> [ignore missing fields].</param>
    public static void SetValue(this IFeature feature, string fieldName, object value, bool ignoreMissingFields)
    {
        (feature as IRow).SetValue(fieldName, value, ignoreMissingFields);
    }

    /// <summary>
    /// Sets the value on IRow
    /// </summary>
    /// <param name="row">The row with the field to update</param>
    /// <param name="fieldName">Name of the field.</param>
    /// <param name="value">The new field value</param>
    /// <param name="ignoreMissingFields">if set to <c>true</c> [ignore missing fields].</param>
    public static void SetValue(this IRow row, string fieldName, object value, bool ignoreMissingFields)
    {
        int index = row.Fields.FindField(fieldName);

        if (index != -1)
        {
            if (row.Fields.get_Field(index).Editable)
            {
                row.set_Value(index, value);
            }
        }
        else
        {
            if (!ignoreMissingFields)
            {
                throw new System.ArgumentException("Field '{0}' Not Found.".FormatString(fieldName));
            }
        }
    }
share|improve this answer
    
Thanks, I'll give these a try! But I have a question: is it safe to use an IFeature object way after I get it from IEnumFeature? Basically, I get all the features from the selection, send them to processing which will take some time (maybe 1 minute or more) and then invoke a callback. What I want to know is how do I edit features in this callback function, specifically, what info about feature I have to preserve before processing in order to edit it in callback (like FeatureClass, OID etc) and how do I use it –  Dyppl Jul 7 '11 at 4:33
    
Also, I think help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/… is a better link to illustrate working with edit operations seeing as I use ArcGIS 10 –  Dyppl Jul 7 '11 at 9:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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