jgrss / geowombat

GeoWombat: Utilities for geospatial data
https://geowombat.readthedocs.io
MIT License
182 stars 10 forks source link

mosaic bounds #302

Open mmann1123 opened 3 months ago

mmann1123 commented 3 months ago

I noticed that when making a mosaic of multiple images the bounds seems only to update to the total bounds of the first two images (i think):

with gw.open(['./tiles/S2_SR_2021_Q01_south-0000000000-0000000000.tif', './tiles/S2_SR_2021_Q01_south-0000000000-0000016384.tif', './tiles/S2_SR_2021_Q01_south-0000016384-0000000000.tif', './tiles/S2_SR_2021_Q01_south-0000016384-0000016384.tif', './tiles/S2_SR_2021_Q01_south-0000032768-0000000000.tif', './tiles/S2_SR_2021_Q01_south-0000032768-0000016384.tif'], mosaic=True,overlap='max' ) as src:
    print(src)                  

only returned the mosaic of the first two images. This can be resolved by using config.update

from rasterio.coords import BoundingBox
import geopandas as gpd

bounds = BoundingBox(*gpd.read_file('./boundaries/south_adm2.geojson').total_bounds)

with gw.config.update(ref_bounds =bounds):
         with gw.open(a_quarter, mosaic=True,overlap='max' ) as src:
mmann1123 commented 3 months ago
from geowombat.backends.rasterio_ import get_file_bounds
files = ['./B12/B12_S2_SR_2020_Q01_south-0000000000-0000000000.tif', './B12/B12_S2_SR_2020_Q01_south-0000032768-0000000000.tif']
print(get_file_bounds(files,return_bounds=True,bounds_by='union'))
with gw.open(files, mosaic=True,overlap='max' ) as src:
    print(src.gw.bounds)  
(34.24844987011358, -17.126380891738677, 35.91850781482018, -13.480837805724835)
(34.24844987011358, -16.424437328727684, 35.918417983291775, -13.480837805724835)
jgrss commented 3 months ago

Is this using v2.1.19?

jgrss commented 3 months ago

Hi @mmann1123 I think is expected, no? The default is to use the intersection of the bounding boxes.

Intersection

import geowombat as gw
from geowombat.backends.rasterio_ import get_file_bounds

files = ['B11_S2_SR_2020_Q01_south-0000000000-0000000000.tif', 'B11_S2_SR_2020_Q01_south-0000032768-0000000000.tif']

print(get_file_bounds(files,return_bounds=True,bounds_by='union'))
with gw.open(files, mosaic=True, overlap='max') as src:
    print(src.gw.bounds) 

(34.24844987011358, -17.126380891738677, 35.91850781482018, -13.480837805724835)
(34.24844987011358, -16.424437328727684, 35.918417983291775, -13.480837805724835)

Union

print(get_file_bounds(files,return_bounds=True,bounds_by='union'))
with gw.open(files, mosaic=True, overlap='max', bounds_by='union') as src:
    print(src.gw.bounds) 

(34.24844987011358, -17.126380891738677, 35.91850781482018, -13.480837805724835)
(34.24844987011358, -17.126291060210267, 35.918417983291775, -13.480837805724835)
mmann1123 commented 3 months ago

hmm... for me bounds_by union would seems like a logical choice, but I guess I am typically using it to mosaic tiles for a a larger scene. Maybe we just need to note this in the tutorial?