Advertisement
Abhisek92

extract_bbox.py

Jun 16th, 2024
879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. import pyproj
  2. import rasterio as rio
  3. from pathlib import Path
  4. from shapely.geometry import box
  5. from shapely.ops import transform
  6.  
  7. target_crs = pyproj.crs.CRS.from_epsg(28992)
  8.  
  9. features = list()
  10. for fpath in Path("").glob("*.tif"):
  11.     with rio.open(fpath, 'r') as src:
  12.         proj = pyproj.Transformer.from_crs(src.crs, target_crs, always_xy=True).transform
  13.         bbox = transform(proj, box(*src.bounds))
  14.         features.append({"geometry": bbox, "source": fpath.stem})
  15.  
  16. gdf = gpd.GeoDataFrame(features, crs=target_crs)
  17. gdf.to_file("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement