marceloprates / prettymaps

A small set of Python functions to draw pretty maps from OpenStreetMap data. Based on osmnx, matplotlib and shapely libraries.
GNU Affero General Public License v3.0
11.12k stars 522 forks source link

Rectangular maps #105

Open etnbrd opened 1 year ago

etnbrd commented 1 year ago

This PR introduces a new parameter ratio to allow drawing rectangular maps.

figsize = tuple(35.1, 49.6)
fig, ax = plt.subplots(figsize=figsize)
plot(
  "Paris",
  ax=ax,
  radius=1000,
  ratio=figsize[0]/figsize[1],
  credit=False,
  layers=layers, # defined elsewhere
  style=style, # defined elsewhere
  preset=None, # needed to avoid overriding the default preset into the provided style and layers
)

image

The ratio part is pretty straightforward, it just updates the perimeter boundary creation to use the introduced ratio parameter.

However, some other parts of the code were written under the assumption that the ratio is 1, these parts needed to be updated as well. The background generation now uses pad and dilate:

In case of a ratio different of 1, using only pad, the margin added to the background are not homogeneous between vertical and horizontal sides. Whereas dilate adds the same amount of margin on all sides. The default value for pad is set at 1 in the code, but at 1.1 in the presets, to keep the existing behavior.

This PR also reintroduces the dilate parameter in the layers to allow printing some layers outside of others. In the example above, streets and water layers have a dilate value of 100.