Search code examples
projectionnetcdf4rasteriopyproj

Reproject geo data and save to NetCDF4


I need to reproject geodetic point data from Gauß-Krüger coord system with discrete data values into a UTM coord system and finally write that data into a netCDF raster file. I was recommended to use python to do this. I tried with PyProj4 which transforms the coordinates but returns (n*m) x (n*m) coordinates from n x m input coordinates which would require an extra resampling as with this much data cannot be continued.

Rasterio provides reprojection and resampling algorithms but seems to be unable to write the netCDF4 format (according to https://rasterio.readthedocs.io/en/latest/api/rasterio.drivers.html#module-rasterio.drivers)

I'm unsure if I'm on the right track and what to do now:

  • use PyProj4 for the projection and then use the rasterio resampling algorithm to sample the point data into a raster and then write the xy-raster values into a netcdf file using the netCDF4 file writer or
  • use the rasterio projection and the resampling algorithm to project the input point data, resample it and then write the xy-raster values into a netcdf file using the netCDF4 file writer

I guess the second way is the way to go? Or is there other and easier ways to achieve this?


Solution

  • I think that you are looking for rioxarray. Here is an example reprojecting a netCDF file: https://corteva.github.io/rioxarray/stable/examples/reproject.html