TransWikia.com

get date from image using python API in Google Earth Engine

Geographic Information Systems Asked on May 15, 2021

I am trying to extract the date as a string from an image in google earth engine, but can’t seem to get it right. This is the code I have so far.

date = ee.Date(image.get('system:time_start'))

This returns an ee.date object in Python, but I can’t find the right way to access the object. Date.getInfo() returns an error.

Does anyone know how to do this?

2 Answers

It is possible the access the date in the following way:

import ee

ee.Initialize()

collection = ee.ImageCollection('LANDSAT/LC08/C01/T1')

date = ee.Date(collection.first().get('system:time_start'))

date_dict = date.getInfo()

print "The number of milliseconds since 1970-01-01T00:00:00Z.: ", date_dict['value']

print "Formatted date", date.format('Y-M-d').getInfo()

Just calling ".getInfo()" on the ee.Date object will give you the number of milliseconds since 1970-01-01 in a Python dictionary.

It is possible to format the date with the ".format" method.

Answered by Bert Coerver on May 15, 2021

ee.Date(image.get('system:time_start')).format("yyyy-MM-dd")

Answered by Javad Koohpayma on May 15, 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