Skip to main content
Question

Writing to Multiple Text Files


So I have a point shapefile of orthophoto locations with approx. 250 features in it with attributes. I also have a .txt file to use as a template. What I basically need to do is for each feature in the shapefile, I need to extract the attributes, do a find/replace in the template, and write out to a text file. Essentially it's just creating text files with metadata of each orthophoto in it, so I should end up with approximately 250 text files when finished.

I'm not sure how to get FME to go through one feature at a time and write out to a .txt. Does anybody have any idea how to do this?

5 replies

ebygomm
Influencer
Forum|alt.badge.img+32
  • Influencer
  • June 20, 2017

You should be able to use the various attributes to build text_line_data attribute and then fanout the text file on a unique feature id to write to separate text files


mygis
Supporter
Forum|alt.badge.img+13
  • Supporter
  • June 21, 2017

Hi @flip ,

 

In order to use your template, you need to use the stringconcatenator transformer, click on switch to advanced. copy your template and paste it in the string expression, then you just have to fill up the gaps with the FME Feature attributes from your workspace or any other Published parameters. once you have done that you just need to fanout out your data based on a certain attribute value.

 

Just a note, when writing in a text file, the text_line_data is one single feature saved in the the text file. If you want to have several records in your text file, I would suggest that you save it as a csv perhaps, otherwise you will be overwriting the text_line_data and the result will be only the last feature.

 

 

I hope this helps.

Lyes.


jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • June 21, 2017

To be more dynamic you can read the template textfile with Read whole file at once set to yes. That will give you one feature with the contents of the textfile stored as an attribute text_line_data. Connect the reader to a FeatureReader pointing to the shapefile with merge attributes set to yes.

 

 

You will now end up with all the features in your shapefile containing the template text, which you can manipulate as desired and then send to a text file writer with a dataset fanout.

Forum|alt.badge.img

Hi @flip

with that many features (each becomes an output text file) you might struggle with the CSV Writer number of open files limitation. Each file the Writer opens for writing is closed only at the end of translation. If you face this limitation, you can create a child workspace and run it from your main workspace using WorkspaceRunner. The child workspace will need to get the source features one by one (i.e. one per translation) and write the output text file for the received feature (which means only one destination text file will be open per translation).


takashi
Influencer
  • June 21, 2017
lenaatsafe wrote:

Hi @flip

with that many features (each becomes an output text file) you might struggle with the CSV Writer number of open files limitation. Each file the Writer opens for writing is closed only at the end of translation. If you face this limitation, you can create a child workspace and run it from your main workspace using WorkspaceRunner. The child workspace will need to get the source features one by one (i.e. one per translation) and write the output text file for the received feature (which means only one destination text file will be open per translation).

Hi @LenaAtSafe, I would try using the Data File writer with feature type fanout setting in this case. Does the Data File writer also have the "number of open files" limitation?

 


Reply


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