Maps on Plotly (python) : how to get a good resolution for satellite maps of Europe?

Viewed 30

I want to create a satellite map like these : https://plotly.com/python/mapbox-layers/

I tried to reproduce this code with my data (from France) :

import pandas as pd
us_cities = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/us-cities-top-1k.csv")

import plotly.express as px

fig = px.scatter_mapbox(us_cities, lat="lat", lon="lon", hover_name="City", hover_data=["State", "Population"],
                        color_discrete_sequence=["fuchsia"], zoom=3, height=300)
fig.update_layout(
    mapbox_style="white-bg",
    mapbox_layers=[
        {
            "below": 'traces',
            "sourcetype": "raster",
            "sourceattribution": "United States Geological Survey",
            "source": [
                "https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/tile/{z}/{y}/{x}"
            ]
        }
      ])
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

but I can't zoom as I would like to.

How could I choose the basemap in order to get a good resolution for the area of my data ? Do you know a bank of basemaps where I can choose one centered on France ?

1 Answers
  • take a look at https://github.com/roblabs/xyz-raster-sources for alternatives
  • have used French cities data to build example, using https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x} allows for zoom to building level in France
import pandas as pd

df = pd.read_csv(
    "https://gist.githubusercontent.com/curran/13d30e855d48cdd6f22acdf0afe27286/raw/0635f14817ec634833bb904a47594cc2f5f9dbf8/worldcities_clean.csv"
).loc[lambda d: d["country"].eq("France")]

import plotly.express as px

fig = px.scatter_mapbox(
    df,
    lat="lat",
    lon="lng",
    hover_name="city",
    hover_data=["population"],
    color_discrete_sequence=["fuchsia"],
    zoom=3,
    height=300,
)
# s = "https://gis.apfo.usda.gov/arcgis/rest/services/NAIP/USDA_CONUS_PRIME/ImageServer/tile/{z}/{y}/{x}"
# s = "https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/tile/{z}/{y}/{x}"
s = "https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"

fig.update_layout(
    mapbox_style="white-bg",
    mapbox_layers=[
        {
            "below": "traces",
            "sourcetype": "raster",
            "sourceattribution": "United States Geological Survey",
            "source": [s],
        }
    ],
)
fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
fig.show()

Related