Skip to main content

I have a series of text files that I am trying to create lines from. Each row in the text file has the number of vertices followed by the Y coordinates for all the vertices and then the x coordinates for all the vertices (see example below)

3,41.1380602942863,41.1378946727126,41.1378187626848,-111.856708809171,-111.857316620769,-111.857869454434

Does anyone know how I could break these up into an X,Y format to use something like the LineBuilder to create lines?

Thanks!

One possible way to get pairs of coordinates

Split into a list by the comma, count the length of the list, explode the list into parts, discard the first item in the list (the number of coordinates), create an x attribute if the element index is less than or equal to half the element count -1, create a y attribute if the element index is more than half of the element count -1, use a modulo counter to assign a coordinate index, aggregate together to get coordinate pairs

You could then create points and use a point connector make lines


Split, explode, filter, count, rename XY, and merge.

 

From there, use a VertexCreator and a LineBuilder to generate the lines.

 

 

 

 


In reality though, I'd probably use a pythoncaller to create the geometries, something like this

import fme
import fmeobjects

def processFeature(feature):
    #get value, split on comma to get list and remove first value, convert to floats
    mylist = vfloat(i) for i in feature.getAttribute('value').split(',')]
    #get num coordinates
    numcoords = int(mylistt0])
    #get first n items in list (excluding first)
    y = mylistt1:numcoords+1:]
    #get last n items in list
    x = mylistinumcoords+1::]
    #create list of tuples
    coords = list(zip(x,y))
    #set geometry
    feature.setGeometry(fmeobjects.FMELine(coords))

One possible way to get pairs of coordinates

Split into a list by the comma, count the length of the list, explode the list into parts, discard the first item in the list (the number of coordinates), create an x attribute if the element index is less than or equal to half the element count -1, create a y attribute if the element index is more than half of the element count -1, use a modulo counter to assign a coordinate index, aggregate together to get coordinate pairs

You could then create points and use a point connector make lines

x and y need to be the other way round of course, now I've noticed you say y coords first but same principle


One possible way to get pairs of coordinates

Split into a list by the comma, count the length of the list, explode the list into parts, discard the first item in the list (the number of coordinates), create an x attribute if the element index is less than or equal to half the element count -1, create a y attribute if the element index is more than half of the element count -1, use a modulo counter to assign a coordinate index, aggregate together to get coordinate pairs

You could then create points and use a point connector make lines

Thank you, your response helped a ton! I had multiple rows, so I made a few adjustments:

  1. Added a Counter before the List Exploder
  2. Used the Counter and the coordinate index (Modulo Counter) in the Aggregate group by parameter
  3. Added a Vertex Creator, Sorter (sort by _count and _element_index), and Line Builder (group by Counter)

     

     


Reply