Skip to content

Issue: geemap cartoee.get_map() ignores region parameter and results in low resolution when using ax.set_extent() #2730

Description

@chenbadan

When using cartoee.get_map() with a specified region parameter, the function still renders the entire global extent instead of the specified region. Additionally, when manually setting the extent with ax.set_extent(), the final output image has very low resolution, as the initial rendering is global and then cropped.

Code to Reproduce

import ee
import ee.mapclient
from matplotlib import pyplot as plt
from geemap import cartoee
import cartopy.crs as ccrs

# Initialize Earth Engine
ee.Initialize()

projection = ccrs.LambertConformal(
    central_longitude=105,
    central_latitude=40,
    standard_parallels=(25.0, 47.0)
)

ocean = (
    ee.ImageCollection("NASA/OCEANDATA/MODIS-Terra/L3SMI")
    .filter(ee.Filter.date("2018-01-01", "2018-03-01"))
    .median()
    .select(["sst"], ["SST"])
)

visualization = {"bands": "SST", "min": -2, "max": 30}
bbox = [70, 15, 140, 55]  # Expected region: East Asia

plt.rcParams['font.family'] = 'Times New Roman'
fig = plt.figure(figsize=(3.5, 3), dpi=300)

# Problem 1: `region=bbox` is ignored, global map is rendered
ax = cartoee.get_map(
    ocean,
    vis_params=visualization,
    cmap='plasma',
    proj=projection,
    region=bbox
)

# Problem 2: Using `ax.set_extent()` fixes the region but results in low resolution
# ax.set_extent([70, 140, 5, 55], crs=ccrs.PlateCarree())

plt.show()
Image Image

Environment Information

Image

Actual Behavior

  1. The region parameter is ignored, and the entire globe is rendered (as shown in the attached screenshot, where only a small portion of the global Lambert projection contains data).
  2. When ax.set_extent() is used to manually crop the plot, the final image resolution is drastically reduced because the initial rendering was global and then scaled down.

Possible Cause

It appears that the region parameter is not being properly passed to the underlying Earth Engine getThumbURL or image export logic, causing the function to default to the global extent of the projection. When ax.set_extent() is used, the matplotlib figure is cropped after the low-resolution global image has been rendered, leading to pixelation.

Suggested Fix

Ensure that the region parameter is correctly converted into the appropriate coordinate system for the given projection and used to clip the Earth Engine image before rendering, so that only the required area is fetched and rendered at full resolution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions