Skip to main content
Question

Calculate coordinates of the center of a line

  • January 6, 2015
  • 9 replies
  • 391 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

 

 

9 replies

takashi
Influencer
  • 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
Influencer
  • 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
Influencer
  • 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
Influencer
  • April 5, 2017
amit wrote:

This could also be achieved with the CentrePointExtractor.

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

 

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings