Skip to main content
Solved

How to group multi line (text file) into individual features?


I received a text file that has descriptions about features as follows:

ADD FUSE 9911 {

PHASES =1;

PORT_A = <123>;

PORT_B = <234>;

ATTRIBUTE[county] = "SEATTLE";

ATTRIBUTE[street] = "MAIN ST";

ATTRIBUTE[facility_id] = "1324";

ATTRIBUTE[feeder_id_1] = "FD1";

ATTRIBUTE[feeder_id_2] = "Null"; }

;

ADD 1p_conductor 125623 {

...

};

Now, how to create individual features out of these?

1. I tried Aggregator:

groupby - text_line_data

Separator character: };

2. Tried to loop text_line_data and break whenever "};" is encountered. But both didn't work.

Is there a simple way to do this?

Best answer by erik_jan

Read the text file into one attribute.

Use the AttributeSplitter and split on }; to create a list.

Use the ListExploder to generate objects per list item.

That will generate the different features.

Next you want to split each feature again on ; to get the different attributes in a list.

View original
Did this help you find an answer to your question?

10 replies

erik_jan
Contributor
Forum|alt.badge.img+17
  • Contributor
  • Best Answer
  • March 4, 2016

Read the text file into one attribute.

Use the AttributeSplitter and split on }; to create a list.

Use the ListExploder to generate objects per list item.

That will generate the different features.

Next you want to split each feature again on ; to get the different attributes in a list.


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • March 7, 2016

@vindastra

That will ignore the first itemname..

Use a txtreader read by row.

Ue a variableretriever and searchers

The not matched will give (in order). the attributes and value rows.

Test for not empty rows and rows witt "neither ";" nor "}" (newlines/carriagereturns etc.) and then searchers again.

Then..well.. here is example..


mark2atsafe
Safer
Forum|alt.badge.img+43

Forum|alt.badge.img+5

What's the best transformation to make a value pair (attribute name=attribute value) stored in a list element _attribute(1) into a feature attribute name and attribute value. e.g. see screenshot. So a feature with _attribute(3) with value "iso=0" will have a new attribute named "iso" and a value of "0". 2016-03-31-07-21-57-fme-data-inspector.png


Forum|alt.badge.img+5

I tried the KeyValueAttributeCreator but it seems by Key,Value pair delimiter which is a LF or \\n is not being read.


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • March 31, 2016
geospatiallover wrote:

What's the best transformation to make a value pair (attribute name=attribute value) stored in a list element _attribute(1) into a feature attribute name and attribute value. e.g. see screenshot. So a feature with _attribute(3) with value "iso=0" will have a new attribute named "iso" and a value of "0". 2016-03-31-07-21-57-fme-data-inspector.png

Hi @geospatiallover, I think a quick way is to remove "<any string>=" from the values, then rename the list elements. e.g.


Forum|alt.badge.img+5

@takashi....thanks. I started with a renamer after my splitter and got lost with putting an expression on the output value. Thanks for your help once again. Strings have always been my weakness in FME.


Forum|alt.badge.img+5

Just a thought, what if the attribute name keeps changing? This is metadata for UAV collected JPEGs and once another camera is used then the attribute schema will change. Any suggestions @takashi? I sure hope Safe would have a JPEGExif writer soon. Not a lot of voters yet on this idea.


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • March 31, 2016
geospatiallover wrote:

Just a thought, what if the attribute name keeps changing? This is metadata for UAV collected JPEGs and once another camera is used then the attribute schema will change. Any suggestions @takashi? I sure hope Safe would have a JPEGExif writer soon. Not a lot of voters yet on this idea.

You can use the KeyValueAttributeCreator after you have concatenated the list elements with a specific delimiter string. e.g. using the ListConcatenator.


Forum|alt.badge.img+5
takashi wrote:

You can use the KeyValueAttributeCreator after you have concatenated the list elements with a specific delimiter string. e.g. using the ListConcatenator.

Thanks again!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings