AnsweredAssumed Answered

Updating and saving M values in an Editor Extension (ArcObjects 10.2 .net)

Question asked by egoddard on Oct 24, 2014
Latest reply on Oct 30, 2014 by egoddard

I have an editor extension for ArcMap 10.2 whose purpose is to populate the M values of a line feature class so that linear reference events can be located along the lines. The line feature class has 2 fields that are important for this: T_MEAS (the maximum measure value of the line), and a field indicating whether the T_MEAS should be equal to the length of the line, which we'll call T_MEAS_IS_SHAPE_L.  The T_MEAS attributes is updated and then the SetandInterpolateMsBetween() method of  IMSegmentation is called to update the measures of the start and end points of the line, and then CalculateNonSimpleMs() is called to update the remaining vertices with M values interpolated between the start/end points.

 

When in the edit session, all of this works except for the CalculateNonSimpleMs() part -- using the Identify route Locations tool will display the Measure along the line correctly, though the min and max measure values are still NaN. However, as soon as the edits are saved the M values revert to NaNs according to the Identify Route Locations tool, but the attribute values that were updated programmatically are saved. Any help understanding why the M values are not saving would be greatly appreciated! The full code is identical to the Editor Add-In walkthrough with a modified Events_OnCreateChangeFeature() method, which is below:

 

void Events_OnCreateChangeFeature(ESRI.ArcGIS.Geodatabase.IObject obj)
        {
            IFeature inFeature = (IFeature)obj;
            IFields fields = inFeature.Fields;
            IField field = null;
            
            // Set up the shape objects to update M values
            ICurve curve = inFeature.Shape as ICurve;
            IMSegmentation mseg = inFeature.Shape as IMSegmentation;
            double t_meas = 0;
            String t_meas_is_shape_length = "";

            // Get value for the T_MEAS_IS_SHAPE_L field to determine
            // if the T_MEAS should be set to the length of the line
            for (int i = 0; i < fields.FieldCount; i++)
            {
                field = fields.get_Field(i);
                if (field.Name.Equals("T_MEAS_IS_SHAPE_L"))
                {
                    t_meas_is_shape_length = (String) inFeature.get_Value(i);
                    break;
                }
            }

            for (int i = 0; i < fields.FieldCount; i++)
            {
                field = fields.get_Field(i);
                if (field.Name.Equals("T_MEAS"))
                {
                    // set T_MEAS equal to the length of the line and update
                    // T_MEAS in the attribute table
                     if(t_meas_is_shape_length.Equals("Yes")) { 
                        t_meas = curve.Length;
                        inFeature.set_Value(i, t_meas);


                    // Use the user-entered value of T_MEAS instead
                    } else if(t_meas_is_shape_length.Equals("No") && inFeature.get_Value(i) != null) {
                        t_meas = (double)inFeature.get_Value(i);
                    }
                    
                    //Update the geometry's measure values
                    mseg.SetAndInterpolateMsBetween(0, t_meas);
                    mseg.CalculateNonSimpleMs();

                    break;
                }
            }
        }

Outcomes