I am looking for a solution to my problem with rasterio. I want to download just a specific part of the image from AWS based on lat lon coordinates. Rasterio offers a great tool (window) although it proivdes just pixel values and not geographycal coordiantes (latlon).
Is there any solution for my problem?
Here is my code:
red = 's3://sentinel-s2-l2a/tiles/34/T/DS/2017/10/12/0/R10m/B04.jp2'
nir = 's3://sentinel-s2-l2a/tiles/34/T/DS/2017/10/12/0/R10m/B08.jp2'
bands=[red, nir]
def ndvi_calc(bands):
window = rasterio.windows.Window(100, 100, 100, 100) # How can I set here lat/lon values?
red_band=bands[0]
nir_band=bands[1]
with Session:
with rasterio.open(red) as red_band:
red=red_band.read(1, window=window)
with rasterio.open(nir) as nir_band:
nir=nir_band.read(1, window=window)
ndvi = (nir.astype(float) - red.astype(float)) / (nir+red)
Best Answer
You can write a wrapper that uses the dataset crs and transform to convert from geographical to array coordinates