Skip to content

Instantly share code, notes, and snippets.

View jistiak's full-sized avatar

J. Istiak jistiak

  • Germany
View GitHub Profile
@jistiak
jistiak / extract_aoi.py
Created February 1, 2023 16:32
Extract AoI from large images using polygon shapefiles
import geopandas as gpd
import rioxarray as rxr
from shapely.geometry import Polygon
aoi = gpd.read_file("/PATH/TO/.shp")
image = rxr.open_rasterio("/PATH/TO/.tif")
xmin, ymin, xmax, ymax = image.rio.bounds()
im_poly = Polygon([(xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)])
intersection = aoi.intersection(im_poly)