Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line width scaling with map size #74

Open
C4K3 opened this issue Dec 30, 2024 · 0 comments
Open

Line width scaling with map size #74

C4K3 opened this issue Dec 30, 2024 · 0 comments

Comments

@C4K3
Copy link
Contributor

C4K3 commented Dec 30, 2024

The width of lines is given as a fixed value of matplotlib "points" which means the width of a line stays the same regardless of the map size. In small maps the lines end up smaller and in large maps the lines end up so big you can't see anything.

I thought it would be nice to allow configuring the width of lines in meters. I'm not sure if doing so is in scope for this project or not, whether it would break things for people. If there would be an interest in having all the width configuration be in meters I'd be happy to open a PR to implement that, but otherwise I'd like to just leave the solution I wrote in case it's useful for anybody else.

This ended up generating reasonably looking small and large maps. When generating very large (radius >10km) maps it works when saving to svg, but the resolution ends up being too small when exporting to jpg or png without increasing the dpi.

from shapely import Point
from geopandas import GeoDataFrame

(
    xmin,
    ymin,
    xmax,
    ymax,
) = aoi.bounds
ymid = (ymin + ymax) / 2
# Width of the figure in matplotlib "points"
width_points = plot.fig.get_size_inches()[0] * 72

left_point = Point(xmin, ymid)
right_point = Point(xmax, ymid)
gdf = GeoDataFrame(geometry=[left_point, right_point], crs="EPSG:4326")
gdf = gdf.to_crs("EPSG:32633")
# This represents the (longitudal) distance (in meters) of the plot
# through the center of the plot.
#
# Should be equal to two times the radius.
width_meters = gdf.geometry.iloc[0].distance(gdf.geometry.iloc[1])

# The width in points of one meter (at the center of the plot)
meter_points = width_points / width_meters

for key in STREETS_WIDTH:
    STREETS_WIDTH[key] *= meter_points

and also modify plotting.py to multiply by meter_points (at

df_class["highway"].map(STREETS_WIDTH).fillna(1)
and )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant