How to create map projections

Import all of the usual things, as done in the earlier sections. Import Basemap from mpl, as shown here:

from mpl_toolkits.basemap import Basemap
Basemap does not come with Matplotlib by default, so we need to do a pip install of basemap, or, if you're using Anaconda, install it using the inbuilt toolkit.

The simplest map projection we get is the one where we translate latitude and longitude into x and y coordinates, and also when we create a basemap object with no projection keyword argument. Each of the following arguments represents a different parameter: llcrnrlat shows the minimum latitude, urcrnrlat shows the maximum latitude, llcrnrlon shows the minimum longitude, urcrnrlon shows the maximum longitude, and lat_ts shows where to center the map:

# Creating the most basic projection
m = Basemap (llcrnrlat=-80, urcrnrlat=80, llcrnrlon=-180,
urcrnrlon=180, lat_ts=0)
setup_map(m)
plt.show()

The preceding arguments explain the limits and center of the map. We will take a look at the setup_map method, as shown in the following code:

def setup_map(m):
m.drawcoastlines()
m.fillcontinents(color='coral',lake_color='aqua')
# draw parallels and meridians.
m.drawparallels(np.arange(-90.,120.,30.))
m.drawmeridians(np.arange(0.,420.,60.))
m.drawmapboundary(fill_color='aqua')
for y in np.linspace(m.ymax/22,19*m.ymax/22,9):
for x in np.linspace(m.xmax/22,19*m.xmax/22,12):
lon, lat = m(x,y,inverse=True)
m.tissot(lon+5,lat+5,1.5,100,facecolor='k',zorder=10,alpha=0.5)

As seen in the preceding snippet, there are two methods to draw parallels and meridians, which are the latitude and longitude lines. We also see the tissot method from the output. Tissots are little circles drawn on the map to show how well that map projection distorts or doesn't distort these circles. In a perfectly accurate projection, all of the circles would be the same regular size. The following output shows our basic map projection:

In the preceding output, we see that the circles, even though they should be circular and equal to each other in area, increase in size as they go north, and the shapes get deformed. They become more elliptical. This means that the preceding map is not conformal, which means it doesn't preserve shape and angle; nor is it equal in area.

Consider the following formal map:

The preceding output shows a map that preserves the accurate shape of the landmasses. The circles stay circular, but don't stay the same size. This is the so-called Mercator projection. One of its biggest features is the increase in the area towards the poles.

With the following code, we extend the minimum and maximum latitude all the way up to 89:

# Mercator projection
m = Basemap(projection='merc', llcrnrlat=-89, urcrnrlat=89,
llcrnrlon=-180, urcrnrlon=180,lat_ts=0)
setup_map(m)
plt.show()

We can see how the circle metrics close to the poles become arbitrarily large, as shown here:

One of the things that the Mercator projection does, due to not being an equal area map, is exaggerate the sizes of features near the poles. A Mercator projection map makes countries like Antarctica and Greenland seems massive, when, in reality, they don't actually cover much area at all. Equally, North America seems to cover far more area than Africa, but in reality, the United States would comfortably fit within Africa, leaving around two thirds of the area of Africa still empty.

Hence, while dealing with presenting data where surface areas are important, Mercator is a poor choice. If, however, shape or angle is all that you care about, then Mercator is perfectly adequate.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset