Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: plot featureCollections on static plots #312

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

12rambau
Copy link
Member

@12rambau 12rambau commented Oct 7, 2024

related to #303

Earthengine has been designed with a big focus on the interactive mapping of the code editor. None the less, people still need to perform presentation and report where a reproducible static image is much more meaningful than a screenshot of the Google interface. This issue is still very real even when using geemap. To simplify the interface I propose in this PR a plot() method for the FeatureCollection object.

Few technical choices:

  • I only support the object based implementation of matplotlib, i.e. you need to provide an ax. (can be modified in a follow-up PR)
  • I only support images and not imageCollection as I want to leave the user to filter and composite from GEE side
  • I only support named colormap for now (can be cahnged in a follow-up PR
  • It's currently a very thin wrapper around geopandas plotting capabilities let's make it evolves with user requests

demo:

Using the following code you can build a ee.FeatureCollection of all the hydroshed in the South americas:

import ee
import geetools

region = ee.Geometry.BBox(-80, -60, -20, 20);
fc = ee.FeatureCollection('WWF/HydroATLAS/v1/Basins/level04').filterBounds(region)

You can display the UP are property using very few lines of code

from matplotlib import pyplot as plt

fig, ax = plt.subplots()
fc.geetools.plot(ax=ax)

# you can then customize the figure as you would for any other matplotlib object
fig.colorbar(ax.collections[0], label="Upstream area (km²)")
ax.set_title("HydroATLAS basins of level4")
ax.set_xlabel("Longitude (°)")
ax.set_ylabel("Latitude (°)")

image

else you can display only the boundaries of the geometries:

from matplotlib import pyplot as plt

fig, ax = plt.subplots()
fc.geetools.plot(ax=ax, boundaries=True)

# you can then customize the figure as you would for any other matplotlib object
ax.set_title("Borders of the HydroATLAS basins of level4")
ax.set_xlabel("Longitude (°)")
ax.set_ylabel("Latitude (°)")

image

Copy link

codecov bot commented Oct 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.33%. Comparing base (820827c) to head (417df0f).
Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #312      +/-   ##
==========================================
+ Coverage   76.18%   76.33%   +0.14%     
==========================================
  Files          30       30              
  Lines        1579     1589      +10     
  Branches      193      194       +1     
==========================================
+ Hits         1203     1213      +10     
  Misses        356      356              
  Partials       20       20              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@12rambau 12rambau merged commit 0497ded into main Oct 8, 2024
12 checks passed
@12rambau 12rambau deleted the plot-feature-collection branch October 8, 2024 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant