Solved

how to straighten line

  • 25 January 2022
  • 6 replies
  • 1 view

Hi,

is there an easy way to straighten a line.

i have created a shortest route on a grid, now i want to straighten this line as it is indicated in the picture. best with 90 degree angle

thanks in advance

icon

Best answer by takashi 26 January 2022, 16:38

View original

6 replies

Userlevel 3
Badge +26

In theory....

  • Extract the start and end points of the lines using the Snipper transformer.
  • Using the BoundingBoxExtractor, extract the bounding box of each input line, and then use the GeometryCoercer to convert to line.
  • Using the PointOnLineOverlayer, split the bounding box line with the points from the Snipper. This should give you 2 lines from the lines output port.
  • Using the Snipper, snip off each end of the lines
  • Feed the 2 lines into the Candidate port of a SpatialFilter. The Filter will be the original line. From the Passed port should be the 'straightened' line.
Badge +2

Extracting the start and end points of the feature is definitely the easiest approach. You can also accomplish this with the CoordinateExtractor, ListElementCounter and 3 VertexCreators to recreate the line with a 90 degree turn. The attached workspace might help with this if you haven't already solved it!imageExample 1 (highlighted is the new line):

imageExample 2 (highlighted is the new line):

image

Hi,

thank you for your support.

Your "90DegreeLineCreator" seems to be a good approach, but unfortunatly i cant use it with FME 2020 (we have this version on our server, so i have to use this one) and if i try it with 2021, then the result is not what i expected. the angle is on the wrong side, the angle must be on the same side as the origin line angle is (see attachment, blue line on the right side)

Userlevel 2
Badge +17

Hi @sebastiangoerck​ , I think you can use the NeighborFinder to find the vertex of your desired right angle corner. See the screenshot.straighten-line-example

Badge +2

Hi,

thank you for your support.

Your "90DegreeLineCreator" seems to be a good approach, but unfortunatly i cant use it with FME 2020 (we have this version on our server, so i have to use this one) and if i try it with 2021, then the result is not what i expected. the angle is on the wrong side, the angle must be on the same side as the origin line angle is (see attachment, blue line on the right side)

It's possible the lines we are comparing were drawn in a different order. If you swap the coordinates in the second VertexCreator that should do the trick (essentially changing which x/y axis to align to). Try setting it to this instead:

image

@Takashi Iijima​ your solution works perfect...thank you

there are always several ways that lead to the result, for me this method is best

 

thank you all for your time and your support!

Reply