Skip to main content
Question

Calculate coordinates of the center of a line

  • January 6, 2015
  • 9 replies
  • 493 views

Forum|alt.badge.img
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

 

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

9 replies

takashi
Celebrity
  • January 6, 2015
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

takashi
Celebrity
  • January 6, 2015
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)

gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • January 6, 2015
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.

 

 

gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • January 6, 2015
..two vertices..

Forum|alt.badge.img
  • Author
  • January 6, 2015
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

 

 


Forum|alt.badge.img
  • Author
  • January 6, 2015
Som many possibilities with FME :) Thank you Gio!

takashi
Celebrity
  • January 7, 2015
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

Forum|alt.badge.img
  • April 5, 2017

This could also be achieved with the CentrePointExtractor.


takashi
Celebrity
  • April 5, 2017

This could also be achieved with the CentrePointExtractor.

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