Skip to main content
Solved

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

  • March 4, 2016
  • 10 replies
  • 189 views

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.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

10 replies

erik_jan
Contributor
Forum|alt.badge.img+23
  • 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+59

geospatiallover
Participant
Forum|alt.badge.img+6

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


geospatiallover
Participant
Forum|alt.badge.img+6

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


takashi
Celebrity
  • March 31, 2016

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.


geospatiallover
Participant
Forum|alt.badge.img+6

@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.


geospatiallover
Participant
Forum|alt.badge.img+6

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
Celebrity
  • March 31, 2016

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.


geospatiallover
Participant
Forum|alt.badge.img+6

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

Thanks again!