Question

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

  • 8 December 2020
  • 7 replies
  • 98 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. 


7 replies

Badge +2

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

Userlevel 4
Badge +36

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

Badge +3

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.

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!

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 

Badge

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? 

Badge

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? 

Reply