Skip to main content
Solved

Set Feature Count to a Variable and later use it to conditionally terminate processing.

  • October 23, 2021
  • 3 replies
  • 257 views

lance
Contributor
Forum|alt.badge.img+5
  • Contributor
  • 14 replies

I would like to save the feature count from a reader and later use it as a conditional check before writing the data back to the database. For example if the reader feature count is 600, I would like to make sure there are 600 features after processing and before writing the feature back to the database.

 

I have experimented with trying to connect StatisticsCalculators to get the count, VariableSetters /Retrievers and the Terminator, but cannot get everything to work and it seams overly complicated for something so simple. Especially since I can see the feature count on each connection line. Any input or suggestions?

Best answer by virtualcitymatt

You can use a Counter followed by a Sampler to sample the last​ feature, this feature will hold the feature count, use this to set the variable. I guess the statistics calculator would also work.

You just need to repeat the same process before writing along with a tester to test the count against the variable.

You'll need to make sure the variable is set before any features reach the variable retriever. A FeatureHolder can help here.​

​Just be aware that VariableSetter/Retriever do not play well with partial runs and FeatureCaching

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

3 replies

virtualcitymatt
Celebrity
Forum|alt.badge.img+47
  • Celebrity
  • 2000 replies
  • Best Answer
  • October 23, 2021

You can use a Counter followed by a Sampler to sample the last​ feature, this feature will hold the feature count, use this to set the variable. I guess the statistics calculator would also work.

You just need to repeat the same process before writing along with a tester to test the count against the variable.

You'll need to make sure the variable is set before any features reach the variable retriever. A FeatureHolder can help here.​

​Just be aware that VariableSetter/Retriever do not play well with partial runs and FeatureCaching


lance
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • 14 replies
  • October 24, 2021

You can use a Counter followed by a Sampler to sample the last​ feature, this feature will hold the feature count, use this to set the variable. I guess the statistics calculator would also work.

You just need to repeat the same process before writing along with a tester to test the count against the variable.

You'll need to make sure the variable is set before any features reach the variable retriever. A FeatureHolder can help here.​

​Just be aware that VariableSetter/Retriever do not play well with partial runs and FeatureCaching

so what you are proposing is something along the lines of the following:

Screenshot 2021-10-24 101114I did find and use a FeatureCounter from the FME Hub that adds the total record count to each row. This is ran twice and two fields are added; startCount and endCount. The Tester looks at the first record and compares the two fields to confirm they are the same value. I also added a FeatureHolder to delay writing and allow for termination, if needed before writing.


virtualcitymatt
Celebrity
Forum|alt.badge.img+47
  • Celebrity
  • 2000 replies
  • October 24, 2021

so what you are proposing is something along the lines of the following:

Screenshot 2021-10-24 101114I did find and use a FeatureCounter from the FME Hub that adds the total record count to each row. This is ran twice and two fields are added; startCount and endCount. The Tester looks at the first record and compares the two fields to confirm they are the same value. I also added a FeatureHolder to delay writing and allow for termination, if needed before writing.

Yeah nice! In this set up you probably also don't need the FeatureHolder because the terminator *should* always be triggered first. But as a just in case it's nice to have. If you find the process to slow or is using too much memory you can look at removing it