js_snippet_to_py() produces duplicate imports
spatialthoughts opened this issue · 0 comments
spatialthoughts commented
The js_snippet_to_py()
function produces duplicate imports and a wrong name for the map widget.
For example
geometry = ee.Geometry.Point([77.60412933051538, 12.952912912328241])
s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED')
rgbVis = {'min': 0.0, 'max': 3000, 'bands': ['B4', 'B3', 'B2']}
filtered = s2.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30)) \
.filter(ee.Filter.date('2019-01-01', '2020-01-01')) \
.filter(ee.Filter.bounds(geometry))
medianComposite = filtered.median()
m.centerObject(geometry, 10)
m.addLayer(medianComposite, rgbVis, 'Median Composite')
Running the converter as follows
lines = geemap.js_snippet_to_py(
javascript_code, add_new_cell=False,
import_ee=True, import_geemap=True, show_map=True)
for line in lines:
print(line.rstrip())
This produces the following output
import ee
import geemap
m = geemap.Map()
import geemap
m = geemap.Map()
geometry = ee.Geometry.Point([77.60412933051538, 12.952912912328241])
s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED')
rgbVis = {'min': 0.0, 'max': 3000, 'bands': ['B4', 'B3', 'B2']}
filtered = s2.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30)) .filter(ee.Filter.date('2019-01-01', '2020-01-01')) .filter(ee.Filter.bounds(geometry))
medianComposite = filtered.median()
m.centerObject(geometry, 10)
m.addLayer(medianComposite, rgbVis, 'Median Composite')
Map
Fixes needed
- Remove the duplicated
import geemap
andm = geemap.Map()
statements - Replace the
Map
in the last line withm
.