Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to get a map of a city using Basemap?

I am trying to use Basemap to display a map of a city, for example San Francisco, in python. I have tried the following:

from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
# llcrnrlat,llcrnrlon,urcrnrlat,urcrnrlon
# are the lat/lon values of the lower left and upper right corners
# of the map.
# lat_ts is the latitude of true scale.
# resolution = 'c' means use crude resolution coastlines.
m = Basemap(projection='merc',llcrnrlat=37.79,urcrnrlat=37.81,\
        llcrnrlon=-122.42,urcrnrlon=-122.4,lat_ts=20,resolution='c')
m.drawcoastlines()
m.fillcontinents(color='coral',lake_color='aqua')
# draw parallels and meridians.
m.drawparallels(np.arange(-90.,91.,30.))
m.drawmeridians(np.arange(-180.,181.,60.))
m.drawmapboundary(fill_color='aqua')
plt.title("Mercator Projection")
plt.show()

However this does not work and just shows blue where the map is meant to be. So how can I get a map of San Francisco using python?

like image 631
fosho Avatar asked Sep 27 '22 10:09

fosho


People also ask

What can I use instead of basemap?

The Cartopy project will replace Basemap, but it hasn't yet implemented all of Basemap's features. All new software development should try to use Cartopy whenever possible, and existing software should start the process of switching over to use Cartopy.

Is basemap still available?

Basemap is deprecated in favor of the Cartopy project. See notes in Cartopy, New Management, and EoL Announcement for more details.


1 Answers

Your coordinates must be wrong: it shows blue because you are zooming on the ocean somewhere.

Besides, this code will only draw the coastline as explained in the documentation. To get the map of a city, you actually need to load the corresponding data using one of the available back-ends. For instance, you could query the data from a API service such as ArcGIS, etc, with the corresponding method.

like image 151
rth Avatar answered Sep 29 '22 23:09

rth