I have a pandas dataframe that contains bounding box information for tiled raster data in the following format.
left bottom right top
466583.40921 3135701.9763599997 466586.39673 3135704.9638799997
466583.40921 3135698.98884 466586.39673 3135701.9763599997
466583.40921 3135696.0013200007 466586.39673 3135698.98884
466583.40921 3135693.013800001 466586.39673 3135696.0013200007
Ultimately, I am looking to create a geopandas geodataframe that has a geometry
column with the bounding box information in the following format:
geometry
POLYGON ((466586.39673 3135701.97636, 466586.39673 3135704.96388, 466583.40921 3135704.96388, 466583.40921 3135701.97636, 466586.39673 3135701.97636))
POLYGON ((466586.39673 3135698.98884, 466586.39673 3135701.97636, 466583.40921 3135701.97636, 466583.40921 3135698.98884, 466586.39673 3135698.98884))
...and so on...
I am aware that I can create a POLYGON
object using the box method and referencing a single row:
box(df.left[1], df.bottom[1], df.right[1], df.top[1])
I have also tried hacking together a solution from a similar question:
b = [x for x in box(df.left, df.bottom, df.right, df.top)]
Which yields the following error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
How can I convert shapely bounding data as in the first dataframe to a geopandas geodataframe as in the second dataframe above?