2

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.

2

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.