Best way to get a city map using Basemap?

I am trying to use Basemap to display a city map like San Francisco in python. I've 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 doesn't work and just shows blue where the card should be. So how can I get a map of San Francisco using python?

+3


source to share


1 answer


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



Also, this code will only draw the coastline as described in the documentation . To get a city map, you really need to download the relevant data using one of the available back-ends. For example, you can request data from an API service such as ArcGIS, etc. with the appropriate method .

+3


source







All Articles