Skip to main content

I have a dataset containing fields representing year and shape length and would like to know how to sum the shape length based on different ranges of years. For example, if I had years 2010- 2020 how would I get the following?

2010 = sum of shape length 2010

2011 = sum of shape length for 2010 and 2011

2012 = sum of shape length for 2010,2011, and 2012

and so on up to 2020.

 

For reference, please see the attached image of my data set. Install_year_dataset 

I've attempted to work this out using test filter using the "IN RANGE" operator but it seems to filter out the values for each consecutive year.

Would creating a new field using a combination of math functions and string functions within Text editor in attribute manager be a better method?

@akcaribou​ The TestFilter separates the data based on the order of your features, so if your year = 2010 is the first filter that won't be included in your next filer "year IN 2010, 2011". Most of the "Filter" transformers work in this way. You could separate the data by Year using the AttributeFilter and then attached several StatisticsCalculators to each output - but that wouldn't scale very well.

Probably a small Python script in PythonCaller is the way to go.


@akcaribou​ The TestFilter separates the data based on the order of your features, so if your year = 2010 is the first filter that won't be included in your next filer "year IN 2010, 2011". Most of the "Filter" transformers work in this way. You could separate the data by Year using the AttributeFilter and then attached several StatisticsCalculators to each output - but that wouldn't scale very well.

Probably a small Python script in PythonCaller is the way to go.

Thank you for the input! Breaking it out into individual StatisticsCalculators was what I was trying to avoid. I agree that it wouldn't scale well. I'll see if I can work it out with a python script.


@akcaribou​ I've created a little PythonCaller script to do this. It illustrates how to read several features, process them and then output several result features - little simpler example than the one in the PythonCaller tutorial. Hopefully my comments in the python are enough the describe the code (but please don't criticize the logic as I'm not a python coder!).

Workspace attached (FME 2021.2)


@akcaribou​ I've created a little PythonCaller script to do this. It illustrates how to read several features, process them and then output several result features - little simpler example than the one in the PythonCaller tutorial. Hopefully my comments in the python are enough the describe the code (but please don't criticize the logic as I'm not a python coder!).

Workspace attached (FME 2021.2)

Excellent! Thank you for putting this together. Yes, the comments within the code make sense. I'll need to adjust it for my fields and account for the data types but this will get me what I need based on the output in the example you provided.


Reply