Question

Using Date and Time Workspace run as FGDB name in Writer

  • 27 March 2017
  • 5 replies
  • 19 views

Badge +7

Scenario: I read 1 or more CSV files, process them and write data out to a File Geodatabase (FGDB) point layer. Currently I'm fanning out on fme_basename of the CSV file. However my overall workflow might be more efficient if I write out to a single FGDB per run, regardless of how many input CSVs there are. In order to avoid overwriting an existing FGDB that may not have been cleaned up by a previous run, I thought of using the Date/Time the Workspace was run as the FGDB name. But how to do this? DateTimeNow as Fanout Expression results in many FGDBs! TimeStamping the first feature then applying that value to every subsequent feature seems over the top, as does using a WorkspaceRunner to set the output file name.


5 replies

Badge

Hi @tim_wood

The difference between CSV and FGDB is that the first one - for a fanout - multiple files are generated within the directory you linked to the writer.

For a FGDB, you 'link' the writer to a File geodatabase and not to a directory. Every 'filename' will result in a new layer within the FGDB and not in a new FGDB. If you want to use the datetime in the FGDB, you should link the 'directory to write to' to a parameter having the datetime included.

This question might help you: https://knowledge.safe.com/questions/41684/set-writer-output-folder-from-attribute-value.html?childToView=41685#answer-41685

Badge +7

Hi @tim_wood

The difference between CSV and FGDB is that the first one - for a fanout - multiple files are generated within the directory you linked to the writer.

For a FGDB, you 'link' the writer to a File geodatabase and not to a directory. Every 'filename' will result in a new layer within the FGDB and not in a new FGDB. If you want to use the datetime in the FGDB, you should link the 'directory to write to' to a parameter having the datetime included.

This question might help you: https://knowledge.safe.com/questions/41684/set-writer-output-folder-from-attribute-value.html?childToView=41685#answer-41685

If you set a Fanout Expression on the Writer in the Navigator pane, you get separate FGDBs (at least I do!). If you use an attribute value or expression in the Feature Class or Table Name of the Writer's Feature Type Parameters window, then you'll get separate layers/tables within the same FGDB.

 

So if I read in A.csv, B.csv, C.csv and expose fme_basename, and set a Fanout Expression of @Value(fme_basename) on my FGDB Writer in the Navigator pane, I will get A.gdb, B.gdb, C.gdb.

 

That's been the case for me in FME 2016.1 and FME 2017.0.

 

Userlevel 1
Badge +10

You could use a parameter? From memory the default value of a date/time parameter is the current time. Then set the feature class to the parameter value

Userlevel 4

I often use a Python scripted private parameter for this. Example:

from datetime import datetime
current_date = datetime.now().strftime('%Y%m%d')
return 'myFGDB_%s.gdb' % current_date 

Which will return something that you can use for the fanout, e.g. 

myFGDB_20170327.gdb
Badge +7

You could use a parameter? From memory the default value of a date/time parameter is the current time. Then set the feature class to the parameter value

Sounds a good idea but I can't get it to work. FME 2017.0 shows a calendar picker for the default value so I assume this would hard-code it to whatever I pick. If I don't set one, and set the destination FGDB name to X:\\Path\\Folder\\$(FGDBName) I get "missing close-brace, Translation Failed".

 

 

Reply