Skip to main content

I have some data in text files that may contain both points and lines. Each line contains a code and either a sub-code or a coordinate set:

 05 1          2302     6826513.392   548235.740  257.374           
 05 31         2302     6826704.339   548284.671  275.511           
 09 91
 05 1          2302     6826513.392   548235.740  257.374           
 05 2          2302     6826518.762   548233.548  257.950           
 05 3          2302     6826525.326   548234.694  258.184           
 05 4          2302     6826532.691   548235.254  258.606           
 09 99

The first column is the first code, '05' is always followed by a coordinate, '09' is always followed by a sub-code: '09 91' defines start of a line, '09 99' defines end of a line. So the short example above contains two points and a polyline with four vertices.

 

Any suggestions on how I can turn this text file into two points and a polyline?

I have a python script that can handle the parsing, but I was wondering if there is a better way to do this in FME rather than plug the script into the pythoncaller.

Hi @havmoejbv​ ,

 

Hope the attached workbench will solve your purpose


Input file which I have used is attached for reference


Hi @havmoejbv​ ,

 

There are likely a few ways you can accomplish this, here's how I would approach it.

 

Typically text files with a standard delimiter can be read in with a CSV reader to help you format the raw text into a table that can be used. Since this text file doesn't use a standard delimiter to separate the values, you can need to use a StringReplacer (replace any occurrence of one or more whitespace characters with a pipe "|"), AttributeSplitter (create a list element for each value separated by a pipe), and an AttributeManager (create attributes and assign based on list index) to format the text into usable attributes similar to what the CSV reader does.

image(tested with the sample txt file you provided)

 

From there, you can use a VertexCreator to create the vertices for both the point and line feature(s). The approach I came up with uses adjacent feature handling in the AttributeManager to set the current value for col2 to 91 if the previous value for col2 is 91 as this allows us to leverage the advanced Group By option (change when Group Changes) in the LineBuilder.

image(tested with a sample text file that has 4 points and 2 lines)

 

Hope that helps.


Thanks to both @pratap​  and @chrisatsafe​ for taking the time to look at it. I am not yet on the 2023 version so the attached workbenches are incomplete when I open here, but from what I can understand the appoach is similar, using Adjacent Feature Attributes. I should be able to patch together something useful from this :)

 


Thanks to both @pratap​  and @chrisatsafe​ for taking the time to look at it. I am not yet on the 2023 version so the attached workbenches are incomplete when I open here, but from what I can understand the appoach is similar, using Adjacent Feature Attributes. I should be able to patch together something useful from this :)

 

@havmoejbv​ 

 

Downgraded to 2021 if required


@havmoejbv​ 

 

Downgraded to 2021 if required

Thanks again. This confirms what I guessed, and looks quite similar to what I made based on those guesses:

image


Reply