sundar_ima February 2016

Matplotlib basemap reading shapefile is very slow

I am trying to plot a simple 'merc' map with boundary from shape file. The total size of the shape file ne_10m_admin_0_countries_lakes.shp is just 8mb. The simple mslp surface plot from GFS data took about more than 28 sec which I think is too much. After investigation I found that it is the reading of shape file consuming around 10 sec. A simple code to demonstrate the issue is shown below:-

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap


south = 0
north = 5
west = 70
east = 85

m = Basemap(projection='merc', llcrnrlat=south, urcrnrlat=north,
        llcrnrlon=west, urcrnrlon=east, resolution='c')
m.readshapefile('data/gis-data/world_countries/'
    'ne_10m_admin_0_countries_lakes', 'ne_10m_admin_0_countries_lakes', linewidth=0.7)

plt.savefig('map.png')

To show the problem I am facing, I have run the above code with and without commenting the path to shape file. Here is time the script took after reading from shape file:-

$ time python test.py 
real    0m18.234s
user    0m17.832s
sys 0m1.020s

Here is the result without reading from shape file:-

$ time python test.py 
real    0m2.506s
user    0m2.360s
sys 0m0.324s

Is there any way to read the shape file quickly? Is there any solution/trick for this issue?

Answers


Andreas Müller February 2016

I would put this question into Geographic Information Systems too, there are some people to help you. If basemap is slow, did you try cartopy, i saw this on the matplotlib site, see http://matplotlib.org/1.4.1/mpl_toolkits/index.html

Post Status

Asked in February 2016
Viewed 3,332 times
Voted 10
Answered 1 times

Search




Leave an answer