TransWikia.com

Google Earth Engine: Calculate milliseconds since epoch from datetime of uploaded shapefile?

Geographic Information Systems Asked by Adamfrancissmith100 on May 22, 2021

I want to get the milliseconds since epoch of thousands of points, each with different timestamps. Here is what I believe I need to do, but my Google Earth Engine knowledge is limited and I can’t find a good way to do this:

  1. Upload a shapefile with a column containing date/time (DONE)

  2. Set the time/date string as a Date column (using .set()) and convert it to a Date object with ee.Date())

  3. Calculate the "time" column using .millis() on the column created in step 2

My best effort so far has been this:

var times = points.set('timestamp', ee.Date(points.select('timestamp')).millis());

where:
(timestamp = the "date/time" column, formatted as dd/MM/YYYY HH:mm:ss)
(points = name of uploaded shapefile table, the FeatureCollection)

The console error says:
FeatureCollection (Error)
Date: Cannot interpret as a Date.

One Answer

You haven't provided a complete example to test against, but it sounds like the problem is that you're trying to process features in a collection but as written your code is operating on the collection itself. Earth Engine does not support working with feature properties in “array programming” fashion where an entire column is manipulated as a value; you must always map over the collection to modify a property for each feature in the collection. Thus, instead of

var times = points.set('timestamp', ee.Date(points.select('timestamp')).millis());

you operate on each feature like

var times = points.map(function (feature) {
  return feature.set('timestamp', ee.Date(feature.get('timestamp')).millis());
});

Note that within the mapping function I have replaced points with feature (the individual feature) and .select() (filter properties on an entire collection) with .get() (retrieve the actual value of a property on the feature).

Correct answer by Kevin Reid on May 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP