How about using variables to store the geometry after every point is added
How about using variables to store the geometry after every point is added
Let me know if you want that workspace. The CoordinateExtractor is getting index 1 of the line, the new point to be added to the line.
Hi,
I'm not specially keen on using Python in FME, but this is definitely something to consider when looking for performance.
Here is the capture (can't figure out how to resize sorry ) of a workspace operating directly from the input points.
It takes 3 seconds to process 10000 points on my laptop, and preserves input point attributes.
The first point is also output as a point, but you can easily filter it out.
Here is the Python code, which is pretty simple :
import fme
import fmeobjects
class LineMotionBuilder(object):
def __init__(self):
# Initialize with Null Line
self.line = fmeobjects.FMELine()
def input(self, feature):
# append current point to existing line
self.line.appendPoint(feature.getGeometry())
# set feature's geometry to current line
feature.setGeometry(self.line)
# output current feature with updated geometry
self.pyoutput(feature)
def close(self):
pass
def process_group(self):
pass
And the workspace is attached.
You might want to improve it by including group processing, should you want to process multiple series of points (I suspect resetting self.line to Null when changing group should do the trick).
Regards,
Fred
Hi,
I'm not specially keen on using Python in FME, but this is definitely something to consider when looking for performance.
Here is the capture (can't figure out how to resize sorry ) of a workspace operating directly from the input points.
It takes 3 seconds to process 10000 points on my laptop, and preserves input point attributes.
The first point is also output as a point, but you can easily filter it out.
Here is the Python code, which is pretty simple :
import fme
import fmeobjects
class LineMotionBuilder(object):
def __init__(self):
# Initialize with Null Line
self.line = fmeobjects.FMELine()
def input(self, feature):
# append current point to existing line
self.line.appendPoint(feature.getGeometry())
# set feature's geometry to current line
feature.setGeometry(self.line)
# output current feature with updated geometry
self.pyoutput(feature)
def close(self):
pass
def process_group(self):
pass
And the workspace is attached.
You might want to improve it by including group processing, should you want to process multiple series of points (I suspect resetting self.line to Null when changing group should do the trick).
Regards,
Fred
To be honest, I've been aware of being able to call python before, during, and after workbenches but I can count on one hand the times I've actually done it. This is nearly exactly what I was looking for, and I've made a few adjustments to adapt it to my needs.
I'm reading multiple GPS tracks (tag_id) and I've also summarized movement and aggregated these to cumulative movement over the course of a day (frame_id).
Thanks so much for taking a look and offering a suggestion!
# edit 1: sorted incoming features by timestamp
# edit 2: implemented GroupBy on the PythonCaller using a tag_id and frame_id identifying individual GPS tag trackers (identify separate tracks)
# edit 3: moved python line appending logic to the process_group function so features are read as a group
# edit 4: converted features to lines to I used appendLine()
# edit 5: set the pyoutput as the last feature in the list to represent the maximum longest cumulative line for that frame
class LineMotionBuilder(object):
def __init__(self):
# Initialize with Null Line
self.line = fmeobjects.FMELine()
self.feature_list = 4]
def input(self, feature):
# append feature to list
self.feature_list.append(feature)
def close(self):
pass
def process_group(self):
for feature in self.feature_list:
# append current point to existing line
self.line.appendLine(feature.getGeometry())
# set feature's geometry to current line
feature.setGeometry(self.line)
# output the last feature for the unique playback day
self.pyoutput(self.feature_listt-1])
self.feature_list = e]
self.line = fmeobjects.FMELine()
As a custom transformer:
Thanks so much for offering your suggestion! I checked it out but ultimately opted for the python implementation purely because I could wrap my head around it and adapt it a little easier 😄. Sometimes FME processing one-feature-at-a-time and trying to craft transformers to circumvent that can be tricky.