Select to view content in your preferred language

Geometry Editor - programmatically select last vertex in a polygon or polyline?

618
5
Jump to solution
01-04-2024 11:22 AM
Labels (2)
Mike_Quetel
Occasional Contributor

Hi, 

I'm working on swapping out the sketch editor with the new geometry editor. I have a need to be able to programmatically select the last vertex in the current part of a polyline or polygon geometry.  This might be necessary if the user interactively selected another vertex during the sketch.  I can't see a straightforward way to accomplish this via existing APIs.  Would appreciate a pointer from anyone who is more knowledgeable it this area.

Thanks!

 

0 Kudos
1 Solution

Accepted Solutions
williambohrmann3
Esri Contributor

Hello @Mike_Quetel ,

Yes, this is possible. First, determine the index of the last vertex of your multipart (polygon/polyline). Then use the SelectVertex method, passing in your geometry part and that last vertex index. For example:

 

var lastVertexIndex = ((Multipart)YourGeometryEditor.Geometry).Parts[0].Count - 1;
YourGeometryEditor.SelectVertex(0, lastVertexIndex);

 

Your calculation of lastVertexIndex might differ depending on the amount of parts of the geometry and if dealing with a polygon or polyline.

-William

View solution in original post

5 Replies
williambohrmann3
Esri Contributor

Hello @Mike_Quetel ,

Yes, this is possible. First, determine the index of the last vertex of your multipart (polygon/polyline). Then use the SelectVertex method, passing in your geometry part and that last vertex index. For example:

 

var lastVertexIndex = ((Multipart)YourGeometryEditor.Geometry).Parts[0].Count - 1;
YourGeometryEditor.SelectVertex(0, lastVertexIndex);

 

Your calculation of lastVertexIndex might differ depending on the amount of parts of the geometry and if dealing with a polygon or polyline.

-William

Mike_Quetel
Occasional Contributor

Appreciate the pointer in the right direction!

0 Kudos
williambohrmann3
Esri Contributor

You are welcome! Upon consulting our geometry editor expert, a few more details to consider. You'll want to further adjust the index if it is a polygon type with current code, for example

var indexAdjustment = geom.getGeometryType() == GeometryType.POLYLINE ? 0 : 1;

and ensuring that select is not called when geometry has 0 points or index is -1. There is definitely prettier ways to refactor the code, typecasting works here but you also might consider separate cases for polygon vs polyline for easier code readability. Up to you how you would like your implementation of select last vertex 🙂 
Feel free to post in ArcGIS Ideas if this a method you would like included in our API.

0 Kudos
Mike_Quetel
Occasional Contributor

Thank you again!  The reason I was asking is that I am trying to work around some odd behavior I'm seeing (200.2) when trying to insert a vertex at the end of a polyline or polygon.  My understanding is that InsertVertex inserts after the currently selected vertex or at the end, if nothing is selected.  If I interactively select a vertex that isn't the last one, then call ClearSelection(), InsertVertex() is still inserting after the vertex that was selected prior to calling ClearSelection().  I confirmed that SelectedElement is null before calling insert.  Might be a bug.

0 Kudos
williambohrmann3
Esri Contributor

Hi @Mike_Quetel 

We've looked into your bug and haven't been able to reproduce it on our end. Feel free to provide a reproducer and we'll gladly take another look.

0 Kudos