Skip to main content
Solved

Is there a way to use a counter as an increment as outlined below? Thanks

  • October 28, 2020
  • 10 replies
  • 339 views

patmhid
Contributor
Forum|alt.badge.img

I have a data set with multiple repeated values such as this

ADA

ADA

ADA

Benton

Canyon

Canyon

Dearborn

Dearborn

Dearborn

Dearborn

 

and I want to increment a count every time the preceding value is different than the next value.

so my 'count' would be like

1 - ADA

1  ADA

1 - ADA

2 - Benton

3 - Canyon 

3 - Canyon

4 - Dearborn

4 - Dearborn

4 - Dearborn

4 - Dearborn

Best answer by bwn

@patmhid​ We don't have anything out of the bx. If you can order your features by the grouping attribute, then you can use the Adjacent Feature option in AttributeCreator to create group counts. I've attached an example workspace.

Similarly, that's the Solution I use in my Workspaces: Sorter + AttributeCreator

AttributeCreator

Enable Adjacent Feature Attributes: On

Prior Features: 1

Conditional Value: If @Value(GroupAttribute)=@Value(feature[-1].GroupAttribute) Then @Value(feature[-1].GroupID) Else @Value(feature[-1].GroupID)+1

 

The only thing I found was that at least in 2018.1, the FME Workspace Editor wants you to create the GroupID Attribute with a separate, preceding AttributeCreator first that initialises it to a default Dummy Value, otherwise an AttributeCreator that simultaneously tries to use Adjacent Feature Handling and create a new Attribute that doesn't yet exist in the Schema and is calculated using an Adjacent Feature Value will report itself as an "Invalid Transformer" in the workspace, even though it WILL run fine when executing the workflow!

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.

10 replies

virtualcitymatt
Celebrity
Forum|alt.badge.img+47
  • Celebrity
  • 2000 replies
  • October 28, 2020

You could use an Aggregator to merge on that attribite​ (add all other attributes into a list) the a normal counter. After that use a list explode to get back to the original.

Alternatively you could use a sampler to get the first feature for each of the attributes you want to count and then count the features, you can then use a FeatureJoiner to ​join the count attribute back to the rest of the data.

I'm not sure if either of these are the best option, but they will work.


Forum|alt.badge.img+2
  • 1891 replies
  • October 28, 2020

@patmhid​ We don't have anything out of the bx. If you can order your features by the grouping attribute, then you can use the Adjacent Feature option in AttributeCreator to create group counts. I've attached an example workspace.


bwn
Evangelist
Forum|alt.badge.img+26
  • Evangelist
  • 562 replies
  • Best Answer
  • October 29, 2020

@patmhid​ We don't have anything out of the bx. If you can order your features by the grouping attribute, then you can use the Adjacent Feature option in AttributeCreator to create group counts. I've attached an example workspace.

Similarly, that's the Solution I use in my Workspaces: Sorter + AttributeCreator

AttributeCreator

Enable Adjacent Feature Attributes: On

Prior Features: 1

Conditional Value: If @Value(GroupAttribute)=@Value(feature[-1].GroupAttribute) Then @Value(feature[-1].GroupID) Else @Value(feature[-1].GroupID)+1

 

The only thing I found was that at least in 2018.1, the FME Workspace Editor wants you to create the GroupID Attribute with a separate, preceding AttributeCreator first that initialises it to a default Dummy Value, otherwise an AttributeCreator that simultaneously tries to use Adjacent Feature Handling and create a new Attribute that doesn't yet exist in the Schema and is calculated using an Adjacent Feature Value will report itself as an "Invalid Transformer" in the workspace, even though it WILL run fine when executing the workflow!


ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • October 29, 2020

@patmhid​ We don't have anything out of the bx. If you can order your features by the grouping attribute, then you can use the Adjacent Feature option in AttributeCreator to create group counts.  I've attached an example workspace. 

I thought after yesterday's webinar you'd be recommending the InlineQuerier @Mark Stoakes​ :-)

select A.*, B.Rownum as Count from Table1 A,
(SELECT
    ROW_NUMBER () OVER ( 
        ORDER BY "Name"
    ) RowNum,
    "Name"
from
(select distinct("Name") from
Table1))B
where A."Name" = B."Name"

I've actually got a python based customer transformer that does the same thing that i really ought to get put on the hub

 


patmhid
Contributor
Forum|alt.badge.img
  • Author
  • Contributor
  • 3 replies
  • October 29, 2020

You could use an Aggregator to merge on that attribite​ (add all other attributes into a list) the a normal counter. After that use a list explode to get back to the original.

Alternatively you could use a sampler to get the first feature for each of the attributes you want to count and then count the features, you can then use a FeatureJoiner to ​join the count attribute back to the rest of the data.

I'm not sure if either of these are the best option, but they will work.

Thank you. I tried this and it worked, but I am going to try the Adjacent Feature option in AttributeCreator to see if that is closer to what I will need going forward.


patmhid
Contributor
Forum|alt.badge.img
  • Author
  • Contributor
  • 3 replies
  • October 29, 2020

@patmhid​ We don't have anything out of the bx. If you can order your features by the grouping attribute, then you can use the Adjacent Feature option in AttributeCreator to create group counts. I've attached an example workspace.

Thanks, this did works great.


patmhid
Contributor
Forum|alt.badge.img
  • Author
  • Contributor
  • 3 replies
  • October 29, 2020

Similarly, that's the Solution I use in my Workspaces: Sorter + AttributeCreator

AttributeCreator

Enable Adjacent Feature Attributes: On

Prior Features: 1

Conditional Value: If @Value(GroupAttribute)=@Value(feature[-1].GroupAttribute) Then @Value(feature[-1].GroupID) Else @Value(feature[-1].GroupID)+1

 

The only thing I found was that at least in 2018.1, the FME Workspace Editor wants you to create the GroupID Attribute with a separate, preceding AttributeCreator first that initialises it to a default Dummy Value, otherwise an AttributeCreator that simultaneously tries to use Adjacent Feature Handling and create a new Attribute that doesn't yet exist in the Schema and is calculated using an Adjacent Feature Value will report itself as an "Invalid Transformer" in the workspace, even though it WILL run fine when executing the workflow!

Thanks this is perfect!


Forum|alt.badge.img+2
  • 1891 replies
  • October 29, 2020

I thought after yesterday's webinar you'd be recommending the InlineQuerier @Mark Stoakes​ :-)

select A.*, B.Rownum as Count from Table1 A,
(SELECT
    ROW_NUMBER () OVER ( 
        ORDER BY "Name"
    ) RowNum,
    "Name"
from
(select distinct("Name") from
Table1))B
where A."Name" = B."Name"

I've actually got a python based customer transformer that does the same thing that i really ought to get put on the hub

 

@ebygomm​  Haha... well I was just about to suggest that when the webinar ended unexpectedly! 


bwn
Evangelist
Forum|alt.badge.img+26
  • Evangelist
  • 562 replies
  • October 30, 2020

I thought after yesterday's webinar you'd be recommending the InlineQuerier @Mark Stoakes​ :-)

select A.*, B.Rownum as Count from Table1 A,
(SELECT
    ROW_NUMBER () OVER ( 
        ORDER BY "Name"
    ) RowNum,
    "Name"
from
(select distinct("Name") from
Table1))B
where A."Name" = B."Name"

I've actually got a python based customer transformer that does the same thing that i really ought to get put on the hub

 

Small performance optimisation, particularly in SQLite based InlineQuerier.

Instead of:

  1. (select distinct("Name") from Table1)

Use

  1. (select "Name" from Table1 GROUP BY "Name")

 

Whilst they produce the same result, the query optimiser and the SQLite engine will generally execute faster with the query plan generated by GROUP BY.


Forum|alt.badge.img+2
  • 1891 replies
  • April 8, 2021

Group Counter. FME 2021.1 Counter has been upgraded to include a group count.

New Counter dialog:

dialogresults:

image