Skip to main content
Solved

how to straighten line

  • January 25, 2022
  • 6 replies
  • 96 views

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

Best answer by takashi

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

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.

6 replies

dustin
Influencer
Forum|alt.badge.img+31
  • Influencer
  • 627 replies
  • January 25, 2022

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.

chrisatsafe
Contributor
Forum|alt.badge.img+2
  • Contributor
  • 606 replies
  • January 25, 2022

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)


takashi
Celebrity
  • 7842 replies
  • Best Answer
  • January 26, 2022

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


chrisatsafe
Contributor
Forum|alt.badge.img+2
  • Contributor
  • 606 replies
  • January 26, 2022

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!