Skip to main content

I built a simple workflow that converts a DWG to KML. I'd like to write the KML file back to the same location I read it from. For example, dwg from path C:\\Users\\admin\\Downloads\\test.dwg, writes to C:\\Users\\admin\\Downloads\\test.kml

 

It's simple to manually select the Reader file and Writer location dynamically using User Parameters, but I want to only have to select the Reader file and automatically set the Writer location/file name. Doing it this way would save a step if possible.

Hi @osdev​ ,

Excellent question. I typically do this by exposing the fme_dataset feature attribute in the reader feature type, then use a FilenamePartExtractor to get the path from that attribute, filename, etc. and a FeatureWriter (though you can do it in a regular writer as well). 

FilenameartExtractorYou can then set the dataset using the attributes from the FilenamePartExtractor in the FeatureWriter: 

@Value(_dirpath)\@Value(_rootname).kml

 


Hi @osdev​ ,

Excellent question. I typically do this by exposing the fme_dataset feature attribute in the reader feature type, then use a FilenamePartExtractor to get the path from that attribute, filename, etc. and a FeatureWriter (though you can do it in a regular writer as well). 

FilenameartExtractorYou can then set the dataset using the attributes from the FilenamePartExtractor in the FeatureWriter: 

@Value(_dirpath)\@Value(_rootname).kml

 

Works like a charm! Thanks @chrisatsafe​ 


Hi @osdev​ ,

Excellent question. I typically do this by exposing the fme_dataset feature attribute in the reader feature type, then use a FilenamePartExtractor to get the path from that attribute, filename, etc. and a FeatureWriter (though you can do it in a regular writer as well). 

FilenameartExtractorYou can then set the dataset using the attributes from the FilenamePartExtractor in the FeatureWriter: 

@Value(_dirpath)\@Value(_rootname).kml

 

Hi Chris, would it be possible to do something similar but where the outputs are written to another directory with a mirrored folder structure? I.e. by replacing the name of a root folder, say 'admin' to 'output' in jbeeksy's example. Currently trying to do it by creating a new 'outpath' attribute in the AttributeManager with the ReplaceString method but note sure how I can apply this to the writer.


Hi Chris, would it be possible to do something similar but where the outputs are written to another directory with a mirrored folder structure? I.e. by replacing the name of a root folder, say 'admin' to 'output' in jbeeksy's example. Currently trying to do it by creating a new 'outpath' attribute in the AttributeManager with the ReplaceString method but note sure how I can apply this to the writer.

Hi @anguswarfield​ ,

Two ways to do this, 1) would be to add a second writer (or FeatureWriter) with the modified path or 2) use a FileCopyWriter after the FeatureWriter to copy the main folder (and all subfolders) to the desired location. I would probably go with the latter.

Connecting to the FeatureWriter's summary port will provide you with an attribute containing the path to the written dataset (_dataset) which you can then use in the FileCopy Writer.

Let me know if that helps!


Hi Chris, would it be possible to do something similar but where the outputs are written to another directory with a mirrored folder structure? I.e. by replacing the name of a root folder, say 'admin' to 'output' in jbeeksy's example. Currently trying to do it by creating a new 'outpath' attribute in the AttributeManager with the ReplaceString method but note sure how I can apply this to the writer.

Hi Chris, I appreciate your reply but not quite sure how to execute it unfortunately.

Essentially, I'm trying to read in a file from its path in a csv, reformat the path and reproject the files so they are saved with the same filenames and nested folder structure/hierarchy in a new location. I have 1000's of files to reproject so need as much automation and optimization as possible. I've heard this can be achieved using Fanout settings and have also tried to implement your suggestions, but having no luck 😞 Here's a screenshot of my workbench so far if that provides any insight? Appreciate your help, Angus

 

Workbench


Hi Chris, would it be possible to do something similar but where the outputs are written to another directory with a mirrored folder structure? I.e. by replacing the name of a root folder, say 'admin' to 'output' in jbeeksy's example. Currently trying to do it by creating a new 'outpath' attribute in the AttributeManager with the ReplaceString method but note sure how I can apply this to the writer.

@anguswarfield​ ,

Sounds like there are two ways to approach your use case. 1) FeatureWriter and a FileCopy Writer OR 2) use 2 writers which use the same fanout but are pointed to different directories.

In order for 1 to work, you need to create an attribute which contains the start of the subdirectory structure you want to follow (I'm doing this in a StringSearcher). Then merge the initiator attributes in the FeatureReader to make these available as attributes to drive the fanout later on in the workspace. Once you have defined the fanout, use an AttributeManager to set the filecopy_desk_filename and filecopy_source_dataset attributes. In the FileCopy Writer, be sure to copy the source folder and subfolders:

imageSource: imageOutput:

imageIn this example, I'm reading in all of the contents from the CSV folder, then writing them to CSV in DirectoryOne using a fanout to create the subdirectories (not changing filenames). Then I'm copying the same folder structure of DirectoryOne into DirectoryTwo.

See attached as it should help clear things up.


Reply