Skip to main content
Dear FME community,

 

 

I want to calculate the coordinates of the center point of a line with 2 points (begin and end point). The resulting coordinate (x,y) should be stored in two attributes, i.e. x_middle and y_middle.

 

 

I've solved it with a series of transformers, but that's not very elegant. Perhaps somebody has an idea if there's a more easier way to do this.

 

 

Kind regards

 

Thomas

 

 

Hi Thomas,

 

 

1) You don't need to calculate diffs.

 

x_middle = (_x_begin + _x_end) * 0.5

 

y_middle = (_y_begin + _y_end) * 0.5

 

 

2) The center of a line segment is equal to the center of its bounding box, so you can calculate the (x, y) based on the bounds coordinates that can be extracted with the BoundsExtractor.

 

x_middle = (_xmin + _xmax) * 0.5

 

y_middle = (_ymin + _ymax) * 0.5

 

 

3) The two expressions can be performed by an AttributeCreator.

 

 

Conclusion.

 

You can replace those transformers with a BoundsExtractor and an AttributeCreator.

 

 

Takashi
Another thought.

 

If you use @Coordinate function, just one AttributeCreator is enough.

 

 

 

See here to learn more about FME Functions.

 

FME and Factory and Function Documentation (http://docs.safe.com/fme/html/FME_FactFunc/index.html)
For a single line segment consisting of just to vertices you can of course just use Snipper.

 

Snippingmode: percentage.

 

Start:50

 

End:50

 

 

this gives you the centerpoint of the line.

 

 

Extract coordinates if needed.

 

 
..two vertices..
Many thanksTakashi. Tested both one's, and they work like a charm! :)

 

 

What I don't understand is why the functions @Coordinate and @Evaluate don't show up in the menu of my arithmetic editor. Shouldn't they be selectable from the left list? With manual inserting it works however.

 

 

Kind regards

 

Thomas

 

 


Som many possibilities with FME 🙂 Thank you Gio!
Hi Thomas,

 

 

Almost all the FME functions are wrapped with transformers. For example, the CoordinateExtractor internally calls @Coordinate function; the BoundsExtractor calls @Bounds function.

 

If you are interested in the internal of transformers, look at this file in your system with a text editor. But, be careful not to destroy the file!

 

<FME HOME>\\transformers\\fmesuite.fmx

 

 

Since transformers can be used easier and safer than using FME functions directly, probably Safe intends to recommend users to use transformers unless there is a specific reason. The situation is similar to Python/Tcl use.

 

I think that's why only few functions are shown in the Arithmetic Editor.

 

And it is also the reason that I suggested BoundsExtractor+AttributeCreator first ;)

 

 

Takashi

This could also be achieved with the CentrePointExtractor.


This could also be achieved with the CentrePointExtractor.

Good catch. In FME 2016+, the CenterPointExtractor would be the simplest solution.

 

 


Reply