Question

How to create lines from points?

  • 13 September 2018
  • 6 replies
  • 156 views

Badge

So, I have two files.

File 1 contains 1 point and file 2 contains 10 points. Basically, for every point in file 2, connect it to file 1 and I will end up with 10 points.

I can do this in Python easily but not sure how to do it in FME yet. I am using FME 2016 btw.

Thanks in advance!


6 replies

Badge +2

Hi @trungn1993

Here is one suggestion that would get you the desired result using transformers in FME:

  1. Assign an ID value to all points with a set value of 1
  2. Add a CoordinateExtractor to File 2 to get the X and Y values
  3. Add a FeatureMerger with File1 as the Supplier and File2 as the Requestor. In the Parameter Editor Set the Join on to the ID attribute you created and set the Feature merge type to Attributes and Geometry. - Since all the points have the same ID this will add the x and y attribute from each point in File 2 to the same point in File 1.
  4. Add a Vertex Creator, leave the Mode as Add Point and this will draw a line from the input point (file 1) to each of the x and y attributes extracted from file 2.

The output will be 10 lines each with the same point at one end:

Red = File 1

Blue = File 2

Black = VertexCreator Output

Badge

Hi @trungn1993

Here is one suggestion that would get you the desired result using transformers in FME:

  1. Assign an ID value to all points with a set value of 1
  2. Add a CoordinateExtractor to File 2 to get the X and Y values
  3. Add a FeatureMerger with File1 as the Supplier and File2 as the Requestor. In the Parameter Editor Set the Join on to the ID attribute you created and set the Feature merge type to Attributes and Geometry. - Since all the points have the same ID this will add the x and y attribute from each point in File 2 to the same point in File 1.
  4. Add a Vertex Creator, leave the Mode as Add Point and this will draw a line from the input point (file 1) to each of the x and y attributes extracted from file 2.

The output will be 10 lines each with the same point at one end:

Red = File 1

Blue = File 2

Black = VertexCreator Output

Awesome. Just exactly what I needed!

Thanks so much @hollyatsafe!

Userlevel 4
Badge +13

@trungn1993 Or you could use the FromToBuilder

Badge

Hi @trungn1993

Here is one suggestion that would get you the desired result using transformers in FME:

  1. Assign an ID value to all points with a set value of 1
  2. Add a CoordinateExtractor to File 2 to get the X and Y values
  3. Add a FeatureMerger with File1 as the Supplier and File2 as the Requestor. In the Parameter Editor Set the Join on to the ID attribute you created and set the Feature merge type to Attributes and Geometry. - Since all the points have the same ID this will add the x and y attribute from each point in File 2 to the same point in File 1.
  4. Add a Vertex Creator, leave the Mode as Add Point and this will draw a line from the input point (file 1) to each of the x and y attributes extracted from file 2.

The output will be 10 lines each with the same point at one end:

Red = File 1

Blue = File 2

Black = VertexCreator Output

I have another follow up question @hollyatsafe!

What if the first file has 2 points (ID = 1 and 2) and the second file has 10 points (5 of them have ID =1 and the rest has ID = 2). Then how would you make sure that points from the second file connect with the right point from the first file using the ID?

Thanks!

Badge +2

I have another follow up question @hollyatsafe!

What if the first file has 2 points (ID = 1 and 2) and the second file has 10 points (5 of them have ID =1 and the rest has ID = 2). Then how would you make sure that points from the second file connect with the right point from the first file using the ID?

Thanks!

Hi @trungn1993,

 

The FeatureMerger will only pair those with the same ID between file 1 and 2, so as long as the corrects points have the correct ID you shouldn't need to make any changes to this workflow.

 

However if the 10 points are not already assigned some unique value that you can use to match them with those in file 1 it might be difficult to sort the 10 points to ensure they are assigned the correct ID.

 

If you are able to share your files or some wider context I might be able to provide some more guidance here.

 

Badge +3

@trungn1993

You do not need to create the (identical) id's first.

that is old school, like fme pre fme 2016 I think.

Yo can just enter for 1 both sides, or any other value, as long as they are the same.

That gives you a unconditional merge.

Reply