contextily icon indicating copy to clipboard operation
contextily copied to clipboard

Mistake in matching basemap through contextily

Open EugeneGIS opened this issue 2 years ago • 2 comments

Hello everyone, Greeting for Switzerland.

Recently, I am focusing on visualizing some datasets of Switzerland through 'contextily' package in python. For the geo coordinate in meter, I decided to use the 'EPSG:3857' as the CRS. However, I met a mistake during the basemap time.

Exactly, as the following code, I have finished the preliminary visualization about the dataset that I used. seaborn.jointplot(x = "Longitude", y = "Latitude", data = CH_points, s = 2.0); The result is here, it works well. image

And then, I consider using the function 'contextily.add_basemap()' to make kde-plot looks better, at least in Switzerland.

# Set up figure and axis
f, ax = plt.subplots(1, figsize=(10, 10))
seaborn.kdeplot(
    CH_points_3857["X"],
    CH_points_3857["Y"],
    n_levels=50,
    shade=True,
    alpha=0.55,
    cmap="viridis_r",
)
# Add basemap
contextily.add_basemap(
    ax, crs = CH_points_3857.crs.to_string(), source=contextily.providers.OpenStreetMap.CH
)
# Remove axes
ax.set_axis_off()

The result is here. As you see, it can load the basemap, not bad, right? But the basemap now is in France, not in Switzerland. image

I have tried to search the similar questions, infos, and solutions via Google, StackOverflow, but no idea...

So Looking forward to your comments and solutions. Have a nice day. :)

EugeneGIS avatar Feb 23 '23 15:02 EugeneGIS

mmm... Would you be comfortable sharing a sample of your data? Or a synthetic version that replicates its characteristics? Happy to take a quick look. My sense is it has to do with the CRS set in CH_points_3857, which I can't check.

darribas avatar Feb 27 '23 10:02 darribas

@darribas Hello, Dani. Thanks for your reply. Here is the link to the dataset, a shapefile with more than 15000 points. https://drive.google.com/file/d/1c85ofyiHKDxjyV5m9LgvWNWL_E9fiifb/view?usp=sharing

EugeneGIS avatar Feb 27 '23 10:02 EugeneGIS