Reputation: 304
I have a map that I want to project onto a sphere, I use cartopy as suggested in another thread. I program in Jupyter.
My code is:
import os
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
os.chdir(os.getenv("HOME"))
os.chdir("Downloads/")
img = plt.imread("europamap1.jpg")
plt.figure(figsize=(3, 3))
ax = plt.axes(projection=ccrs.Orthographic(-10, 45))
ax.gridlines(color="black", linestyle="dotted")
ax.imshow(img, origin="upper", extent=(-180, 180, -90, 90),
transform=ccrs.PlateCarree()) # Important
plt.show()
What I get is a white filled circle enter image description here
I don't know why I cannot see any gridlines nor the image! I tried to plot.show(img) and the image is loaded! I basically just copied and pasted from this thread
Upvotes: 3
Views: 1344
Reputation: 1293
The image file you are loading with plt.imread
is not a geospatial raster format, which are commonly GeoTIFF files that end with the .tiff
extension.
The problem is that your image lacks a coordinate reference system (CRS) to align with cartopy
. For example print(img.crs)
most likely does not print a CRS.
To project your data you will need to find a GeoTIFF file and align the CRS with the projection that cartopy
uses - ccrs.PlateCarree()
, for example.
Some test satellite imagery can be found here: https://gisgeography.com/usgs-earth-explorer-download-free-landsat-imagery/.
For reading and writing raster data, see rasterio
: https://rasterio.readthedocs.io/en/latest/.
Here is an example using a GeoTIFF from the source linked in the comments. https://photojournal.jpl.nasa.gov/tiff/PIA03526.tif:.
import matplotlib.pyplot as plt
import rasterio
from rasterio import plot
src = rasterio.open(r"../tests/data/PIA03526.tif")
plot.show(src)
Upvotes: 1