There may be other solutions, but it's fairly easy to accomplish using a PythonCaller, something like:
1class FeatureCreator(object): def __init__(self): pass def input(self,feature): f = open("input_file.txt", "r") chunk = 100 while True: data = f.read(chunk) if not data: break newFeature = fmeobjects.FMEFeature() newFeature.setAttribute('chunk' data) self.pyoutput(newFeature) def close(self): pass
Will return one feature with an attribute chunk for each chunk of 100 bytes in the file input_file.txt
i would attempt this with first getting the file into an attribute with AttributeFileReader then making a list from the record layout with AttributeSplitter.
david_r wrote:
There may be other solutions, but it's fairly easy to accomplish using a PythonCaller, something like:
1class FeatureCreator(object): def __init__(self): pass def input(self,feature): f = open("input_file.txt", "r") chunk = 100 while True: data = f.read(chunk) if not data: break newFeature = fmeobjects.FMEFeature() newFeature.setAttribute('chunk' data) self.pyoutput(newFeature) def close(self): pass
Will return one feature with an attribute chunk for each chunk of 100 bytes in the file input_file.txt
Here i was avoiding mentioning Python and David has no qualms! The struct module is a candidate too ;-)
bruceharold wrote:
Here i was avoiding mentioning Python and David has no qualms! The struct module is a candidate too ;-)
It's late Friday, my qualms have officially left the building ;-)
bruceharold wrote:
i would attempt this with first getting the file into an attribute with AttributeFileReader then making a list from the record layout with AttributeSplitter.
This is a good solution, given that the input file isn't very (very) large.
Thanks both for your suggestions. This was partly exploratory to see if FME could be used for this particular job. I'll try make sure I come back and post which solution was used and accept the relevant answer.