Question

Remove specific vertices in a list from a polyline

  • 17 September 2021
  • 3 replies
  • 5 views

Badge +3

Hello,

 

How would I remove specific vertices from a feature that are stored in a list, the vertex remover only allows one vertex be removed.

 

I have a list with:

 

Coordinate Index - vertices_to_remove{}.vertice_index

X - vertices_to_remove{}.x

Y - vertices_to_remove{}.y

Z - vertices_to_remove{}.z

 

Thanks

 

Capture


3 replies

Badge +2

Hi @od10​ ,

 

Just to confirm here, does your list contain the coordinate pairs or the indices for the vertices you want to remove? 

2021-09-20_14-25-47If the latter, try the attached workspace. I'll try to summarize what's happening it in as few words as possible below:

 

You'll need to loop for this to work. One way of accomplishing this is to use a custom transformer with a loop output. Alternatively, you can also accomplish this using the WorkspaceRunner and calling a child workspace but that will likely be a bit slower. 

 

Using the custom (looping) transformer, will look something like this:

2021-09-20_14-59-58Where you are performing an iterative loop to remove one vertex after another. You'll need to adjust the parameter values to point them to your list containing the indices you want to remove. The way this works is for every loop, the VertexRemover is dynamically being set to step through each element in your vertex to remove list using the following expression:

@Value(VertexToRemove{@Value(_count)}._creation_instance)-@Value(_count)

This expression sets the list element based on the current iteration of the loop (note it subtracts the count to account for the next time the feature is passed into the loop). For the screenshot below, each red notch indicates a vertex that was removed.

2021-09-20_15-07-54Same feature with preserve geometry set to no. 2021-09-20_15-18-03Try it out and let me know if it works. If it doesn't and you are able to share a sample feature, I'd be happy to take another look. 

 

Other helpful resources:

Badge +3

Hi chrisatsafe,

 

In the end I used a pythoncaller to loop through the list of vertices and removed them in descending order.

 

Thanks for the help. 

Userlevel 4
Badge +30

Hi @od10​ ,

 

Just to confirm here, does your list contain the coordinate pairs or the indices for the vertices you want to remove? 

2021-09-20_14-25-47If the latter, try the attached workspace. I'll try to summarize what's happening it in as few words as possible below:

 

You'll need to loop for this to work. One way of accomplishing this is to use a custom transformer with a loop output. Alternatively, you can also accomplish this using the WorkspaceRunner and calling a child workspace but that will likely be a bit slower. 

 

Using the custom (looping) transformer, will look something like this:

2021-09-20_14-59-58Where you are performing an iterative loop to remove one vertex after another. You'll need to adjust the parameter values to point them to your list containing the indices you want to remove. The way this works is for every loop, the VertexRemover is dynamically being set to step through each element in your vertex to remove list using the following expression:

@Value(VertexToRemove{@Value(_count)}._creation_instance)-@Value(_count)

This expression sets the list element based on the current iteration of the loop (note it subtracts the count to account for the next time the feature is passed into the loop). For the screenshot below, each red notch indicates a vertex that was removed.

2021-09-20_15-07-54Same feature with preserve geometry set to no. 2021-09-20_15-18-03Try it out and let me know if it works. If it doesn't and you are able to share a sample feature, I'd be happy to take another look. 

 

Other helpful resources:

Nice job @chrisatsafe​ 

Reply