environmentaltools.graphics.osm_image
- environmentaltools.graphics.osm_image(lons, lats, style='satellite', epsg=None, title=None, ax=None, fname=None)[source]
Create OpenStreetMap background image for spatial visualization.
Generates a map with OpenStreetMap imagery (satellite or street map style) as background. Automatically handles coordinate transformations and scale calculations. Based on code by Mathew Lipson (m.lipson@unsw.edu.au).
- Parameters:
lons (list or np.ndarray) – Longitude or x-coordinate bounds [min, max]. Format depends on epsg parameter.
lats (list or np.ndarray) – Latitude or y-coordinate bounds [min, max]. Format depends on epsg parameter.
style (str, optional) – Map style - either “satellite” or “map”. Defaults to “satellite”.
epsg (int, optional) – EPSG code of input coordinates. Supported values: - 25829, 25830: UTM zones (automatically transforms to WGS84) - 4326, 4328: WGS84 geodetic (lon/lat) - None: Assumes WGS84 and calculates distance Defaults to None.
title (str, optional) – Plot title. Defaults to None.
ax (matplotlib.axes.Axes, optional) – Axes object with cartopy projection. Defaults to None.
fname (str, optional) – Filename to save the figure. Defaults to None.
- Returns:
The axes object with the map.
- Return type:
matplotlib.axes.Axes
Note
Be careful with scale and radius combinations. Large scale (>16) with large radius (>1000m) may violate OSM policies (https://operations.osmfoundation.org/policies/tiles/).
Scale guidelines: - 2: Worldwide or continental scales - 4-6: Countries and larger states - 6-10: Smaller states, regions, and cities - 10-12: City boundaries and zip codes - 14+: Roads, blocks, buildings