EOA-team / eodal

Earth Observation Data Analysis Library
https://eodal.readthedocs.io/en/latest/
GNU General Public License v3.0
93 stars 15 forks source link

Bug: `RasterCollection.to_dataframe()` fails when `RasterCollection.is_bandstack()` is False #34

Closed lukasValentin closed 1 year ago

lukasValentin commented 1 year ago

In case a RasterCollection where is_bandstack() returns False (i.e., the bands in the RasterCollection have dfferent pixel sizes, geographic extents or reference systems), the RasterCollection.to_dataframe() method fails with a key error, e.g.

KeyError: ('B03', 'geometry')

This is because of an incorrect call of pandas.join that was never tested properly.

The solution is to use the work-around proposed by @atoparseks in case the is_bandstack() method returns False.

px_list =  [handler[b].to_dataframe() for b in handler.band_names]

gdf_rapeseed_pixels = reduce(lambda left, right:   
                     pd.merge(left , right,
                              on = ["geometry"]
                             ),
                    px_list)
lukasValentin commented 1 year ago

The changes have been integrated into RasterCollection.to_dataframe() and successfully tested using https://github.com/EOA-team/eodal_notebooks/blob/master/notebooks/Sentinel-2/sentinel2_field_parcel_extraction.ipynb by ignoring the spatial resampling of all bands so that RasterCollection.from_bandstack() was False