2

So I am creating a fairly small, and hopefully simple, editor extension. This is in Arc 10.4.

What I would like to do is this. If a user is editing a feature and is manipulating the edit sketch, when they move a point I want any other coincident vertices in other features to move with it. Executing this should be easy enough:

  1. Loop through all feature classes in the GDB
  2. Buffer the original point and execute a spatial query
  3. See if the original point exists on any discovered features
  4. If a feature has the original point, move to the new location

#2 is the problem. The issue is that the OnVertexMoved event only provides the new point location, not the old. My first try was to get the selected feature from the Editor and then pull other information from the IEditSketch interface like so:

            //from inside OnVertexMoved
            IFeature source_feature = ArcMap.Editor.EditSelection.Next();
            IEditSketch e_sketch = ArcMap.Editor as IEditSketch;
            IGeometryCollection gc = source_feature.Shape as IGeometryCollection;
            IGeometry geo_part = gc.Geometry[e_sketch.Part];
            IPoint orig_point = (geo_part as IPointCollection).Point[e_sketch.Vertex];

But e_sketch.Part and e_sketch.Vertex are both invalid (-1). Is there a good way to grab the original vertex location? At this point the original feature's geometry should be unmodified so even just the part and/or index of the vertex should be sufficient.

2
  • Did you try casting source_feature to IFeatureChanges, then finding the point in OriginalShape? To get an index for the point, try looping through each point in IEditsketch.Geometry to find closest point to e_sketch.vertex (distance should be zero). Commented Jul 23, 2018 at 18:51
  • The issue is that would require a point at the original location. I only have the new, moved location of the point, which could end up being closer to a different point than the original location.
    – danielm
    Commented Jul 23, 2018 at 19:24

1 Answer 1

2

I managed to hack together a solution for this.

First I hooked up the OnVertexSelectionChanged event on the IEditEvents5_Event interface. From there I looped over every vertex on the current sketch geometry until I found a selected vertex (I'm requiring that only 1 vertex be selected for this). I was then able to cache the coordinates until I needed for OnVertexMoved.

(ArcMap.Editor as IEditEvents5_Event).OnVertexSelectionChanged += OnPointSelectionChanged;

//...

private void OnPointSelectionChanged()
{
    //class level, cached point to use in VertexMoved event
    selected_point = null;
    var sketch = ArcMap.Editor as IEditSketch3;
    if (sketch.SelectedVertexCount == 1)
    {
        int part = 0;
        foreach(var geometry in getParts(sketch.Geometry))
        {
            IPointCollection pc = geometry as IPointCollection;
            IPoint g_point = null;
            if(pc == null)
            {
                if(geometry is IPoint && sketch.IsVertexSelected(part,0))
                    g_point = geometry as IPoint;
            }
            else
            {
                for(int i = 0; i < pc.PointCount; i++)
                {
                    if (sketch.IsVertexSelected(part, i))
                        g_point = pc.Point[i]; ;
                }
            }

            if(g_point != null)
            {
                selected_point = new Point();
                selected_point.PutCoords(g_point.X, g_point.Y);
                return;
            }

            part++;
        }
    }
}

I was not able to find a better way, but IsVertexSelected, must be checking something, somewhere; but I don't know what object that is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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