Export matlab variable to be imported in QGis

2 visualizaciones (últimos 30 días)
Ricardo Duarte
Ricardo Duarte el 14 de Sept. de 2021
Respondida: Pratyush el 29 de Mayo de 2024
Dear all,
I need to export a 1000x1000 matrix containing sound pressure level of a specific region to be later imported at QGis.
I tried to do that using netCDF files, which is ok, however the coordinate system is not the same than in QGis (it is used the WGS84 coordinate system) and when I import the file there it is not in the correct location.
So, my question is, how can I export my variable maintaing the correct coordinate system/or change the coordinate system in matlab to correspond to the same coordinate system in QGIs.
Thank you in advance.

Respuestas (1)

Pratyush
Pratyush el 29 de Mayo de 2024
Hi Ricardo,
To export a 1000x1000 matrix (e.g., sound pressure level data) from MATLAB to a netCDF file compatible with QGIS's WGS84 coordinate system, follow these summarized steps:
1. Ensure your data, including latitude (`lat`) and longitude (`lon`), is ready and in WGS84 format.
2.Use 'nccreate' in MATLAB to generate the file and define dimensions for your data and coordinates.
nccreate('soundPressureData.nc', 'soundPressureLevel', 'Dimensions', {'lat', 1000, 'lon', 1000});
3. Use 'ncwrite' to add your matrix and coordinate data to the file.
4. Add attributes to your netCDF file to specify that your data uses the WGS84 system, using 'ncwriteatt' to set attributes like 'standard_name' and 'units' for latitude and longitude.
ncwriteatt('soundPressureData.nc', '/', 'Conventions', 'CF-1.6');
ncwriteatt('soundPressureData.nc', 'lat', 'standard_name', 'latitude');
ncwriteatt('soundPressureData.nc', 'lon', 'standard_name', 'longitude');
5. If QGIS does not recognize the CRS, you may need to manually set the layer's CRS to WGS84 (EPSG:4326) within QGIS using the "Define Projection" tool.
6. Load your netCDF file into QGIS. If the coordinate system is not automatically recognized, manually adjust it to WGS84.
This process ensures your MATLAB-exported netCDF file aligns correctly with QGIS's expected coordinate system, facilitating accurate geographical data representation.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by