Question

Coordinate Extractor - Correct Syntax for Last Value


Badge +9

Hello all,

I am using CoordinateExtractor to extract the start and end coordinates of line features. Most lines have only a start and end but some have an intermediate vertex. I want to extract the start and end for the list created but if I use the -1 I get no results (according to the help 0 should be start and -1 should be end)

 

 

If I open the text editor it is showing a problem with the expression

 

 

Can anyone let me know what is the correct syntax to get the end point, please?


9 replies

Userlevel 3
Badge +17

I don't believe you can use negative indices within the Text Editor. 

Try adding a ListElementCounter and using the output _element_count attribute to build your expression. Since the ListElementCounter starts the count at 1, you will need to subtract one from this value to get the correct index.

For example, this expression should work to get the last x value of your list:

@Value(_indices{@Evaluate(@Value(_element_count)-1)}.x)
Badge +9

I don't believe you can use negative indices within the Text Editor. 

Try adding a ListElementCounter and using the output _element_count attribute to build your expression. Since the ListElementCounter starts the count at 1, you will need to subtract one from this value to get the correct index.

For example, this expression should work to get the last x value of your list:

@Value(_indices{@Evaluate(@Value(_element_count)-1)}.x)

Thanks @debbiatsafe, I will give that a go but even the safe doco mentions negative index values 

http://docs.safe.com/fme/2019.0/html/FME_Desktop_Documentation/FME_Transformers/Transformers/coordinateextractor.htm 

Userlevel 2
Badge +17

I don't believe you can use negative indices within the Text Editor. 

Try adding a ListElementCounter and using the output _element_count attribute to build your expression. Since the ListElementCounter starts the count at 1, you will need to subtract one from this value to get the correct index.

For example, this expression should work to get the last x value of your list:

@Value(_indices{@Evaluate(@Value(_element_count)-1)}.x)

Yes, negative index is supported in a parameter setting in some transformers, but is not supported as an index of list attribute.

This workflow is possible.

0684Q00000ArMDiQAN.png

Badge +9

Yes, negative index is supported in a parameter setting in some transformers, but is not supported as an index of list attribute.

This workflow is possible.

Thanks @takashi, very much appreciated.

Userlevel 1
Badge +21

Thanks @takashi, very much appreciated.

I get unreasonably annoyed at having to use two coordinate extractors for start and end features. I'd really like to be able to extract start and end in one go

https://knowledge.safe.com/idea/39951/coordinate-extractor-first-and-last-coordinates-on.html

Userlevel 5
Badge +25

I get unreasonably annoyed at having to use two coordinate extractors for start and end features. I'd really like to be able to extract start and end in one go

https://knowledge.safe.com/idea/39951/coordinate-extractor-first-and-last-coordinates-on.html

I'm with you on that one, just voted for the idea.

Userlevel 2
Badge +17

I get unreasonably annoyed at having to use two coordinate extractors for start and end features. I'd really like to be able to extract start and end in one go

https://knowledge.safe.com/idea/39951/coordinate-extractor-first-and-last-coordinates-on.html

I agree with you, voted too!

Userlevel 3
Badge +17

Thanks @debbiatsafe, I will give that a go but even the safe doco mentions negative index values

http://docs.safe.com/fme/2019.0/html/FME_Desktop_Documentation/FME_Transformers/Transformers/coordinateextractor.htm

Yes, it is possible to use negative index values within CoordinateExtractor if the Mode is set to Specify Coordinate. In Specify Coordinate mode, the coordinates get extracted as feature attributes instead of a list.

Based on your screenshots, I had assumed (perhaps incorrectly) you were using the All Coordinates mode in the CoordinateExtractor and defining an expression in the Value column of the User Attributes tab of the writer feature type to get the last index value of the _indices list. for this scenario, the expression I had outlined above in combination with the ListElementCounter will work in an AttributeCreator, AttributeManager, etc.

If this is not the case, my apologies and please use @takashi's excellent answer instead.

Badge

LRS_GetRouteMeas transformer did this for me, posting here as it's somewhere I searched for a solution.

 

takes each Polyline and Extracts Vertex 0 and Vertex -1 only.. as shown here.

LRS_GetRouteMeas sample

Reply