So I was using Google Earth Engine and working through some of the example code in their repo. I am using Python 3.6. Looks like Google will not support the mapping functionality in Python 3 through their ee.mapclient()
anymore. I was wondering if anyone has found a suitable workaround? Let me outline the problem.
I tried to load the ee.mapclient
to plot a map.
import ee
import ee.mapclient
ee.Initialize()
But I got an error:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-13-6d4860410653> in <module>()
1 import ee
----> 2 import ee.mapclient
3 ee.Initialize()
/media/krishnab/lakshmi/anaconda3/envs/pMining/lib/python3.6/site-packages/ee/mapclient.py in <module>()
29
30 import collections
---> 31 import cStringIO
32 import functools
33 import math
ModuleNotFoundError: No module named 'cStringIO'
The cStringIO
problem is easy enough to resolve as per:
python 3.4.0 email package install: ImportError: No module named 'cStringIO'
So I went to post an issue on the Google Earth Engine Repo, but found a preexisting issue:
https://github.com/google/earthengine-api/issues/16
In the issue the developers acknowledge the problem, but indicate that they will not fix it due to limitations with the underlying Tk
package.
Here is a quote from the issue:
We have not been actively maintaining the mapclient object, because it depends on Tk, a graphical user interface toolkit, which behaves differently on different machines. Could you describe your use case that requires mapclient? We may be able to suggest an alternative approach.
The google developers offered to submit a workaround, but so far no workaround has been posted.
Hence, I was wondering if anyone else had found a suitable workaround in Python3.6 for this problem?
By way of a genuine code example, I can offer the code below from the Google examples repo:
import datetime
import ee
import ee.mapclient
ee.Initialize()
ee.mapclient.centerMap(-95.738, 18.453, 9)
# Filter the LE7 collection to a single date.
collection = (ee.ImageCollection('LE7_L1T')
.filterDate(datetime.datetime(2002, 11, 8),
datetime.datetime(2002, 11, 9)))
image = collection.mosaic().select('B3', 'B2', 'B1')
# Display the image normally.
ee.mapclient.addToMap(image, {'gain': '1.6, 1.4, 1.1'}, 'Land')
# Add and stretch the water. Once where the elevation is masked,
# and again where the elevation is zero.
elev = ee.Image('srtm90_v4')
mask1 = elev.mask().eq(0).And(image.mask())
mask2 = elev.eq(0).And(image.mask())
ee.mapclient.addToMap(
image.mask(mask1), {'gain': 6.0, 'bias': -200}, 'Water: Masked')
ee.mapclient.addToMap(
image.mask(mask2), {'gain': 6.0, 'bias': -200}, 'Water: Elev 0')