Hi there,
In a Nutshell
I want to clip S3 LST L2 dataarray to a polygon shapefile I created using QGIS
more details …
LST Data
From the initial S3-L2_LST product delivered from Sentinel-3 data, I built a dataset that looks as so (lat, lon and time have been assigned to coordinates, but not to dimensions - which appears to be ‘Frozen’):
Polygon Shapefile
- I generated one polygon,
- and saved it as a shp file (crs : EPSG:4326 - WGS: 84)
Data to shapefile cliping process
I tried to clip the LST DataArray displayed above to my customized polygon using hints I found here and there:
Test1 - Masking NetCDF time series data from shapefile using Python - Geographic Information Systems Stack Exchange
da = xarray.open_dataset(xr_filepath)
lst_da = da.LST
lst_da.rio.set_spatial_dims(x_dim="lon", y_dim="lat", inplace=True)
→ ERROR : x dimension (lon) not found. Data variable: LST
Test2 - python - Masking NetCDF data using shapefile (xarray & geopandas) - Geographic Information Systems Stack Exchange
geodf = geopandas.read_file(shp_filepath)
xds = rioxarray.open_rasterio(xr_filepath)
# WARNING -> NotGeoreferencedWarning: Dataset has no geotransform, gcps, or rpcs. The identity matrix be returned.
xds.rio.write_crs("epsg:4326", inplace=True)
clipped = xds.rio.clip(geodf.geometry.apply(mapping), geodf.crs)
→ ERROR : No data found in bounds. Data variable: LST
Test3 - python mask netcdf data using shapefile - Stack Overflow
I tried some customization but I clearly do not have a sufficient understanding of the initial code and field knowledge to make this code fits my use case specificities…
CONCLUSION : I couldn’t make it happen…
It might have to do with my LST data array Dimensions being differents from Coordinates (lat, lon), but my scarce experience in this field do not help me to be creative enough in terms of workarounds…
I’ve also encountered people talking about “subsetting” the raster/xarray instead of “cliping”, which might end up leading to the same objective for me :
Extract data from one initial dataset, relatively to one specific area
Would you have any hints, or clear procedure to follow using python script (I’m prototyping on Jupyter Lab at the moment…), it would be very much appreciated !
#clip #subset #shapefile #rasterio #geospatial #sentinel