Search code examples
matplotlibcartopyrasteriosatellite-imagecontextily

Plotting a Geodataframe over a satellite image


I've been trying several ways to plot a GeodataFrame over a satellite image and none seemed to work.

First I tried with contextily. I managed to make it work, but not with satellite data. It seems there is no google imagery, and Esri.WorldImagery returns a background of "Map data not available".

Then I tried to add a S2 image that i donwloaded directly to the plot, either using plt.imread or rioxaray.plot(), but none of them displayed a background image.

Can someone share a working example that plots a GDF over a satellite image?


Solution

  • you might want to give EOmaps a try!

    from eomaps import Maps
    import geopandas as gpd
    
    df = gpd.read_file(gpd.datasets.get_path("nybb"))
    
    
    m = Maps(crs=Maps.CRS.Mercator.GOOGLE)
    m.set_extent((-74.43, -73.39, 40.45, 40.98))
    
    m.add_gdf(df, column="BoroName", legend=True)
    m.add_wms.ESRI_ArcGIS.SERVICES.World_Imagery.add_layer.xyz_layer()
    

    enter image description here