Skip to main content
Question

How do I build a line from two geometries (or attributes) of a feature

  • Dec 8, 2020 9:55 PM UTC
  • 7 replies
  • 664 views

I can't fathom how to do this as a newbie.

 

My feature has two attributes, start_coord and end_coord.

On a row by row basis, I want to create a line out of these two points. They are currently WKT POINT geometries that I have created from coordinates. 

 

I have attempted to use LineBuilder but that appears to build a line out of all my features (rows) so 44 rows output one messy line. 

 

I suppose the PostGIS approach would be something along the lines of:

ST_MakeLine(ST_GeomFromText(Attribute From Feature), ST_GeomFromText('Attribute From Feature'), ST_GeomFromText('Different Attribute From Same Feature'))

 

Any advice would be wonderful. 

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.

7 replies

Forum|alt.badge.img+2

@trialing​ Try the VertexCreator. You can use two in a row, one to Replace wit Point and the second to Add Point


geomancer
Evangelist
Forum|alt.badge.img+71
  • Evangelist
  • Dec 9, 2020 6:50 AM UTC

As you mentioned starting with coordinates, you may also be interested in the GeometryReplacer. 

Set the Geometry Encoding to OGC Well Known Text, and format the Geometry Source like a WKT Linestring using the coordinates of the start point and end point:

LINESTRING (@Value(X_Start) @Value(Y_Start), @Value(X_End) @Value(Y_End))

GeometryReplacer_WKT_LineString_from_Coordinates


bwn
Evangelist
Forum|alt.badge.img+26
  • Evangelist
  • Dec 9, 2020 7:36 AM UTC

Do you really need the Line Start Point and Stop Point Attributes to be Point WKT strings? That is somewhat unnecessary in FME.

As per @Mark Stoakes​'s post, generally you pass the Start Point X, Y numeric values into VertexCreator #1 to initialise the Geometry as a Point (Set as: Replace with Point), and then transform this to a 2 point line by sending these Points to a VertexCreator #2 (Set as: Add Point) that will add a second point and transform these to Lines using the separate end coordinates numeric X,Y,{Z} values.

 

Coincidentally, it is also not necessary in PostGIS/ST_MakeLine(). Using VertexCreator like this is aligned to the more usual application of ST_MakeLine as Eg.

ST_MakeLine(ST_MakePoint(x_start, y_start), ST_MakePoint(x_end, y_end))

ie. No need to make the Points into WKT strings if already have the X, Y coordinates as numerics.


  • Author
  • Dec 9, 2020 9:35 AM UTC

As you mentioned starting with coordinates, you may also be interested in the GeometryReplacer. 

Set the Geometry Encoding to OGC Well Known Text, and format the Geometry Source like a WKT Linestring using the coordinates of the start point and end point:

LINESTRING (@Value(X_Start) @Value(Y_Start), @Value(X_End) @Value(Y_End))

GeometryReplacer_WKT_LineString_from_Coordinates

This is perfect. I do have the non POINT coords. Thank you!


  • Author
  • Dec 9, 2020 9:39 AM UTC

Do you really need the Line Start Point and Stop Point Attributes to be Point WKT strings? That is somewhat unnecessary in FME.

As per @Mark Stoakes​'s post, generally you pass the Start Point X, Y numeric values into VertexCreator #1 to initialise the Geometry as a Point (Set as: Replace with Point), and then transform this to a 2 point line by sending these Points to a VertexCreator #2 (Set as: Add Point) that will add a second point and transform these to Lines using the separate end coordinates numeric X,Y,{Z} values.

 

Coincidentally, it is also not necessary in PostGIS/ST_MakeLine(). Using VertexCreator like this is aligned to the more usual application of ST_MakeLine as Eg.

ST_MakeLine(ST_MakePoint(x_start, y_start), ST_MakePoint(x_end, y_end))

ie. No need to make the Points into WKT strings if already have the X, Y coordinates as numerics.

I did, previous to this process I had to extract coordinates from a polygon and convert to points so I could query nearest neighbour from a different dataset. I do still have access to the coordinate attribution so you are right, absolutely no need to create the line from points. 

I am new to this and for some reason I am developing fairly complex solutions first when I should really go step by step but so far it is working well enough. 

Thanks again 


Forum|alt.badge.img
  • Mar 14, 2023 3:51 PM UTC

As you mentioned starting with coordinates, you may also be interested in the GeometryReplacer. 

Set the Geometry Encoding to OGC Well Known Text, and format the Geometry Source like a WKT Linestring using the coordinates of the start point and end point:

LINESTRING (@Value(X_Start) @Value(Y_Start), @Value(X_End) @Value(Y_End))

GeometryReplacer_WKT_LineString_from_Coordinates

Is it also possible to use this linestring with Z coordinates? 


Forum|alt.badge.img
  • Mar 14, 2023 3:54 PM UTC

Do you really need the Line Start Point and Stop Point Attributes to be Point WKT strings? That is somewhat unnecessary in FME.

As per @Mark Stoakes​'s post, generally you pass the Start Point X, Y numeric values into VertexCreator #1 to initialise the Geometry as a Point (Set as: Replace with Point), and then transform this to a 2 point line by sending these Points to a VertexCreator #2 (Set as: Add Point) that will add a second point and transform these to Lines using the separate end coordinates numeric X,Y,{Z} values.

 

Coincidentally, it is also not necessary in PostGIS/ST_MakeLine(). Using VertexCreator like this is aligned to the more usual application of ST_MakeLine as Eg.

ST_MakeLine(ST_MakePoint(x_start, y_start), ST_MakePoint(x_end, y_end))

ie. No need to make the Points into WKT strings if already have the X, Y coordinates as numerics.

I want to generate vertical lines with the same X, Y only difference in Z. I tried the above workflow, however, with the second vertex creator it rejects. Is it necessary to add a line builder after the two vertex creators? Or am I forgetting something else?