Solved

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

  • 23 October 2021
  • 3 replies
  • 33 views

Badge

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?

icon

Best answer by virtualcitymatt 23 October 2021, 20:30

View original

3 replies

Userlevel 4
Badge +26

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

Badge

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.

Userlevel 4
Badge +26

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