Wednesday, June 8, 2016

Nice Python Basemap Background

When using python Basemap to plot maps, a nice background would be a big plus. But when using map.bluemarble(), map.etopo(), or map.shadedrelief(), we can not zoom in to a smaller region, since it will generate a blur image. The best way to create a high resolution background image (either topography, street map, etc.) is using arcgisimage method. See the documentation here. I will show the following examples to plot the nice map.
For using arcgisimage method, you need specify the epsg for different region, and choose the services from the following list (see different services here, also here):
  1. World_Physical_Map
  2. World_Shaded_Relief
  3. World_Topo_Map
  4. NatGeo_World_Map
  5. ESRI_Imagery_World_2D
  6. World_Street_Map
  7. World_Imagery
  8. ESRI_StreetMap_World_2D
  9. Ocean_Basemap
Which map background do you like? You can download the script as usually at Qingkai's Github.
In [1]:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
In [2]:
# let's first define a helper function to plot the map of Bay Area in US. 

def plot_map(service = 'World_Physical_Map', epsg = 4269, xpixels = 5000):
    # note, you need change the epsg for different region, 
    #US is 4269, and you can google the region you want
    plt.figure(figsize = (8, 8))
    m = Basemap(projection='mill',llcrnrlon=-123. ,llcrnrlat=37,
        urcrnrlon=-121 ,urcrnrlat=39, resolution = 'l', epsg = epsg)
    
    # xpixels controls the pixels in x direction, and if you leave ypixels
    # None, it will choose ypixels based on the aspect ratio
    m.arcgisimage(service=service, xpixels = xpixels, verbose= False)
    
    plt.show()

1 - World_Physical_Map

In [3]:
plot_map(service = 'World_Physical_Map', epsg = 4269)

2 - World_Shaded_Relief

In [4]:
plot_map(service='World_Shaded_Relief')

3 - World_Topo_Map

In [5]:
plot_map(service='World_Topo_Map')

4 - NatGeo_World_Map

In [6]:
plot_map(service='NatGeo_World_Map')

5 - ESRI_Imagery_World_2D

In [7]:
plot_map(service='ESRI_Imagery_World_2D')

6 - World_Street_Map

In [8]:
plot_map(service='World_Street_Map')

7 - World_Imagery

In [9]:
plot_map(service='World_Imagery')

8 - ESRI_StreetMap_World_2D

In [10]:
plot_map(service='ESRI_StreetMap_World_2D')

9 - Ocean_Basemap

In [11]:
plot_map(service='Ocean_Basemap')

4 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Five weeks ago my boyfriend broke up with me. It all started when i went to summer camp i was trying to contact him but it was not going through. So when I came back from camp I saw him with a young lady kissing in his bed room, I was frustrated and it gave me a sleepless night. I thought he will come back to apologies but he didn't come for almost three week i was really hurt but i thank Dr.Azuka for all he did i met Dr.Azuka during my search at the internet i decided to contact him on his email dr.azukasolutionhome@gmail.com he brought my boyfriend back to me just within 48 hours i am really happy. What’s app contact : +44 7520 636249‬

    ReplyDelete