Loading Common Maps¶
Simple Example¶
Import MapScaler and load a map of the US Counties:
import mapscaler as ms
loader = ms.MapLoader()
df = loader.fetch_counties()['df']
That’s it! You now have a map of the counties.
import matplotlib.pyplot as plt
import geoplot as gplt
#Reduce to the lower 48 for an easier demonstration
df = df[df.STATE_FIPS != '02'] # remove AK
df = df[df.STATE_FIPS != '15'] # remove HI
df = df[df.STATE_FIPS != '72'] # remove PR
gplt.polyplot(
df,
projection=gplt.crs.AlbersEqualArea(),
figsize=(15,8),
)
plt.suptitle('Contiguous United States', fontsize=20, ha='center')
plt.show()
Documentation¶
-
class
mapscaler.
MapLoader
¶ Bases:
object
Quickly load common maps of the US as GeoPandas Dataframes.
Note
In most cases, the least detailed map options are used for performance. All MapLoader methods return a
sources
item with links to find maps with higher detail, if available.-
fetch_counties
(state_fips=None)¶ Load a map of the US counties.
Parameters: state_fips (str) – Optional - State FIPS code as a string. Default is None
which loads all states.Returns: dict
with 2 keys:df is a GeoPandas DataFrame, including a column of shape objects.
sources is a dict of links to the original map source.
Return type: dict
-
fetch_states
()¶ Load a map of the US states, including Puerto Rico.
Returns: dict
with 2 keys:df is a GeoPandas DataFrame, including a column of shape objects.
sources is a dict of links to the original map source.
Return type: dict
-