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

3654
2
Jump to solution
10-24-2014 11:28 AM
EricGoddard
New Contributor

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;

                }

            }

        }

0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor

I think the problem is that you are not saving your changes. So you create your mseg interface point it to the geometry and at the end of the code you interpolate and calculate non simple Ms. But you do not write it back to the feature.  In VB I would do something like:

dim pPolyline as IPolyline

pPolyline = inFeatures.Shape

dim mseg as IMSegmentation

mseg = pPolyline

:

:

mseg.SetAndInterpolateMsBetween(0, t_meas)

mseg.CalculateNonSimpleMs()

:

inFeature.Shape = pPolyline

' Not sure but you may need to call store at this point

inFeature.Store()

Duncan

View solution in original post

0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor

I think the problem is that you are not saving your changes. So you create your mseg interface point it to the geometry and at the end of the code you interpolate and calculate non simple Ms. But you do not write it back to the feature.  In VB I would do something like:

dim pPolyline as IPolyline

pPolyline = inFeatures.Shape

dim mseg as IMSegmentation

mseg = pPolyline

:

:

mseg.SetAndInterpolateMsBetween(0, t_meas)

mseg.CalculateNonSimpleMs()

:

inFeature.Shape = pPolyline

' Not sure but you may need to call store at this point

inFeature.Store()

Duncan

0 Kudos
EricGoddard
New Contributor

Thanks, Duncan! I changed the ICurve to an IPolyline and called inFeature.Shape = pPolyline after updating the M's and it worked. Since it is called from an event listener it wasn't necessary to make a call to Store().

Eric

0 Kudos