Skip to main content
Solved

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

  • October 23, 2021
  • 3 replies
  • 201 views

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

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

View original
Did this help you find an answer to your question?

3 replies

virtualcitymatt
Celebrity
Forum|alt.badge.img+35
  • Celebrity
  • 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
  • October 24, 2021
virtualcitymatt wrote:

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+35
lance wrote:

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings