I’m trying to crop a Folium map to a specific area but I can’t get it to work. I made a rectangle on the map, and I want to save a png with just that area.
xlim = (df['longitude'].min(), df['longitude'].max())
ylim = (df['latitude'].min(), df['latitude'].max())
min_lon, max_lon = xlim
min_lat, max_lat = ylim
map = folium.Map(min_lat=min_lat, max_lat=max_lat, min_lon=min_lon, max_lon=max_lon,
zoom_control = False, control_scale=False, max_bounds=True)
folium.Rectangle(bounds=[[min_lat, min_lon], [max_lat, max_lon]], color='red', fill=False).add_to(map)
map.fit_bounds([[min_lat, min_lon], [max_lat, max_lon]])
map.save(...)
How can I save just the Rectangle object, cutting out everything arround it?
I tried using cv2 to use computer vision to find the red rectangle and crop it out, but it did not work for all maps since there are other red elements.
New contributor
joon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.