TransWikia.com

Output GeoTIFF file is wrongly rotated to 90 degrees/ -90 degrees using xarray and rioxarray with NotGeoreferencedWarning warning

Geographic Information Systems Asked by Shreya Gupta on August 30, 2021

I am using this file. I wrote this code.

import rioxarray
import xarray


xds = xarray.open_dataset("LIS_HIST_201401010000.d01 copy.nc")

floodFraction = xds.FloodedFrac_tavg.transpose('east_west','north_south')
floodFraction.rio.set_spatial_dims(x_dim="north_south", y_dim="east_west", inplace=True)
floodFraction.rio.write_crs("EPSG:4326", inplace=True)
floodFraction.rio.to_raster('floodFraction.tif')

After running this script, my terminal shows this

NotGeoreferencedWarning: The given matrix is equal to Affine.identity or its flipped counterpart. GDAL may ignore this matrix and save no geotransform without raising an error. This behavior is somewhat driver-specific.
  s = writer(path, mode, driver=driver,

The obtained tif file looks like this

enter image description here

One Answer

The problem with your dataset is that the lat/lon data is masked:

<xarray.DataArray 'lon' (north_south: 320, east_west: 300)>
array([[      nan,       nan,       nan, ...,       nan,       nan,       nan],
       [      nan,       nan,       nan, ...,       nan,       nan,       nan],
       [      nan,       nan,       nan, ...,       nan,       nan,       nan],
       ...,
       [68.04999 , 68.149994, 68.25    , ..., 97.75    , 97.850006, 97.95001 ],
       [68.04999 , 68.149994, 68.25    , ..., 97.75    , 97.850006, 97.95001 ],
       [68.04999 , 68.149994, 68.25    , ..., 97.75    , 97.850006, 97.95001 ]],

Due to this, the geotransform cannot be properly determined. I would recommend attempting to fill in the masked lat/lon data if you know what it is or can derive it before exporting to a raster.

Correct answer by snowman2 on August 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP