This page demonstrates Python tips and tricks that I use in my everyday programming as an atmospheric science graduate student.
-Brian Blaylock

Monday, May 20, 2019

Add an ArcGIS Map Service Image to a Cartopy axes.

I am a very slow Cartopy adopter. I learned Basemap years ago and am very comfortable with it and continue to hold tight to what I know. However, as I dabble more with Cartopy, I can see how it is superior.

For the last two years, one of my many reasons for sticking with Basemap despite almsot everyone telling me to stop, that the ease of adding arcGIS images as a map background. In Basemap, it is a simple m.arcgisimage(service='World_Shaded_Relief'). It took me a long time and many attempts to figure out how to do this in Cartopy. It does take a few extra steps, but it is possible, and even without the ease of use, I am now believe Cartopy does this better than Basemap.

In Basemap, you are limited to adding arcGIS images to cylindrical projection, but in Cartopy you can add these images to any projection. Incredible!

See the full notebook here, https://github.com/blaylockbk/pyBKB_v3/blob/master/BB_maps/cartopy_arcgisimage.ipynb.


Additional Resources:

NOTE: When you set the extent with ax.set_extent, the images are fine until you cross the prime meridian, then the images are distorted as if there aren't enough tiles. The only way I've been able to prevent this is to keep the image in the same projection as the tiles, a.k.a. the Mercator projection (see the second stack overflow answer linked above).

import cartopy.io.img_tiles as cimgt

fig=plt.figure(figsize=(10,5))
ax = fig.add_subplot(1,1,1, projection=ccrs.PlateCarree())
ax.coastlines()

url = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Shaded_Relief/MapServer/tile/{z}/{y}/{x}.jpg'

image = cimgt.GoogleTiles(url=url)

ax.add_image(image, 1)




No comments:

Post a Comment

Note: Only a member of this blog may post a comment.