1

I have a project in QGIS that I need to add a raster file to (.nc). The projection is EPSG:4326, but its boundaries are 0 to 360. How can I center the raster over the Atlantic ocean (180). Or, change the project projection to be centered over the Pacific ocean? See image:

I have many rasters like this, so would need to change several files.

Text

1 Answer 1

0

Solved this issue with some Python using rioxarray package. The code will open the .nc file with the raster, then convert extent from (0,360) to (-180,180).

import rioxarray
import xarray as xr

input_fp = 'file.nc'
output_fp = 'corrected_file.tif'

rds = rioxarray.open_rasterio(input_fp)

print("Available data variables:", rds.data_vars)
raster_variable_name = 'var_name'

rds_var = rds[raster_variable_name]
rds_var = rds_var.assign_coords(x=(((rds_var.x + 180) % 360) - 180)).sortby('x')
rds_var.rio.to_raster(output_fp)

print(f"GeoTIFF saved as {output_fp}")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.