I'm creating a box that covers the the area of a GeoPandas GeoDataFrame, so that I can use it as an inverted map to later cover up unwanted spill-over data.
import geopandas as gpd
import geoplot as gplt
from shapely.geometry import box
denmark = world[world.name == 'Denmark']
denmark_box = gpd.GeoDataFrame(
[box(*denmark.total_bounds)],
columns = ['geometry'],
geometry='geometry',
crs = denmark.crs)
denmark_cover = gpd.tools.overlay(denmark, w3, how="symmetric_difference")
fig, ax = plt.subplots(figsize=(20,20))
ax.set_aspect('equal')
# shp is some other data
# that plots a bit over the country borders
shp.plot(ax=ax, column='sum', edgecolor='none', cmap='hot', alpha=1, legend=True)
denmark.plot(ax=ax, color="none", edgecolor='white', facecolor="None")
denmark_cover.plot(ax=ax, edgecolor='white', alpha=1)
I need to make the box about 5% bigger to cover all unwanted data.
What is a good aproach to make a shapely box bigger?
buffer
method: shapely.readthedocs.io/en/latest/manual.html#object.buffer By playing with thecap_style
orjoin_style
arguments, you should be able to make a buffer around that box that still results in a square box (and not with rounded corners, which will be the default)