Question

Calculate the time difference between two features in a non-spatial dataset

  • 21 August 2014
  • 3 replies
  • 15 views

Hi all,

 

 

I have a dataset (from MS Access) that has fields as follows:

 

 

Site Name       Sample Date/Time     

 

A                        08/16/2014 08:00

 

A                        08/17/2014 14:00

 

A                        08/25/2014 12:30

 

B                       07/04/2014 11:00

 

B                       08/04/2014 11:00

 

B                       09/04/2014 11:00

 

 

I want to be able to calculate the time in days, hours or minutes between each feature and the preceeding one (i.e. how long between each sample at each site) where the site name is the same.  The output would then look like this...

 

 

Site Name       Sample Date/Time    TimeSinceLast (hours)

 

A                        08/16/2014 08:00       -

 

A                        08/17/2014 14:00       30

 

A                        08/25/2014 12:30       190.5

 

B                       07/04/2014 11:00        -

 

B                       08/04/2014 11:00        744

 

B                       09/04/2014 11:00        744

 

 

Any ideas greatly appreciated.  I'm very new to FME, just done the Basic Desktop Webinar.

 

 

Thanks, Alice

3 replies

Userlevel 4
Hi,

 

 

you can use an AttributeCreator to get a reference to a preceeding feature's sample date:

 

 

 

 

Then format both the current and the preceeding sample date into the number of seconds since epoch:

 

 

 

 

Finally, calculate the difference between the two values and convert seconds to hours:

 

 

 

 

David
Userlevel 4
Badge +13
Or just download the DateDifferenceCalculator from the FME Store.
Userlevel 2
Badge +17
Hi,

 

 

In addition to David's suggestion, you can use Conditional Value setting in the AttributeCreator to differentiate sequences of each Site. That is, only if the Site Name is equal to the previous feature's Site Name, assign feature[-1].SampleDateTime to PrevSampleDateTime.

 

 

 

And then, calculate the time difference if the PrevDateTime is not empty.

 

 

Takashi

Reply