Brendan,

You need to warp the raster using the geolocation array formed by the lon and lat variable:

gdalwarp -overwrite -geoloc CORDEX_subarea_O3.nc out.tif

(possibly using -t_srs EPSG:XXXX to indicate a more relevant SRS than EPSG:4326)

> why is the GDAL netcdf driver not properly creating an affine?

It can only report an affine geotransform matrix when the lat and lon arrays are 1D, and have regular spacing. Here they are 2D and potentially express a "random" georeferencing, hence they are reported as a geolocation array.

Even

Le 12/07/2022 à 13:38, DeTracey, Brendan a écrit :
Hi,

I have been "gifted" a netcdf raster that I must vectorize. When I load the 
raster into QGIS the coordinates are not correct. I believe that QGIS uses GDAL drivers. 
I have included a download link to the file, a ncdump -h,  and gdalinfo output, all at 
the bottom of this message. The raster is on the CORDEX arctic grid 
[https://cordex.org/domains/region-11-arctic/], a rotated pole projection with the pole 
at 0.0E, 6.55N and a Top Left Corner of 337.12E, 33.88N. My raster is double the 
resolution described in the specification. The raster covers the arctic and is a binary 
mask for Baffin Bay. The raster includes the lat and lon, but not the rotated projection 
lat and lon.

What do I need to do to get QGIS to properly load the coordinates for this 
raster? (The raster is too coarse for my needs. My plan is to use QGIS to 
manually draw a shapefile of the raster boundaries.) Why is the GDAL netcdf 
driver not properly creating an affine? Is it because the raster spans the pole?

Thanks so much,
Brendan

https://file.io/3ITCNwX0fg3s : CORDEX_subarea_O3.nc : 1MB

$ ncdump -h CORDEX_subarea_O3.nc
netcdf CORDEX_subarea_O3 {
dimensions:
         x = 232 ;
         y = 266 ;
variables:
         double lon(y, x) ;
                 lon:standard_name = "longitude" ;
                 lon:long_name = "longitude" ;
                 lon:units = "degrees_east" ;
                 lon:_CoordinateAxisType = "Lon" ;
         double lat(y, x) ;
                 lat:standard_name = "latitude" ;
                 lat:long_name = "latitude" ;
                 lat:units = "degrees_north" ;
                 lat:_CoordinateAxisType = "Lat" ;
         double mmask(y, x) ;
                 mmask:coordinates = "lon lat" ;
                 mmask:_FillValue = -9.e+33 ;
                 mmask:missing_value = -9.e+33 ;

// global attributes:
                 :CDI = "Climate Data Interface version 1.6.8 
(http://mpimet.mpg.de/cdi)" ;
                 :Conventions = "CF-1.4" ;
                 :history = "Mon Apr 20 17:37:28 2020: cdo eqc,3 
All_subareas_CORDEX_final.nc CORDEX_subarea_O3.nc\n",
                         "Sat Apr 11 22:10:21 2020: cdo add jonn.nc jlnn.nc 
jann.nc\n",
                         "Sat Apr 11 21:55:59 2020: cdo sub latest_5.nc jln.nc 
jon.nc\n",
                         "Sat Apr 11 17:29:06 2020: cdo add jos.nc 
Land_subareas_new.nc All_subareas_CORDEX_reedited.nc\n",
                         "Sat Apr 11 17:22:45 2020: cdo sub 
All_subareas_CORDEX_edited.nc j.nc jos.nc\n",
                         "Tue Apr 07 15:58:18 2020: cdo add jon.nc 
EPA_Arctic_bioregions_CORDEX_land_masked_edited.nc All_subareas_CORDEX_edited.nc\n",
                         "Tue Apr 07 15:19:29 2020: cdo sub 
All_subareas_CORDEX_best.nc jl.nc jo.nc_\n",
                         "Tue Apr 07 00:58:57 2020: cdo 
remapnn,ARC-22_sample_grid.nc All_subareas_.25deg.nc j.nc\n",
                         "Tue Apr 07 00:48:41 2020: cdo add NAA_subareas_.25deg.nc 
EPA_Arctic_bioregions_.25degx-1.nc All_subareas_.25deg.nc\n",
                         "Tue Apr 07 00:48:01 2020: cdo mulc,-1 
EPA_Arctic_bioregions_.25deg.nc EPA_Arctic_bioregions_.25degx-1.nc\n",
                         "Mon Apr 06 17:20:07 2020: cdo add 
4xAlaskan_Tundra_mask_l2_.25deg.nc jNSCff.nc jNSCA.nc\n",
                         "Mon Apr  6 17:18:06 2020: 
/HOME/opt/package/nco/linux64/bin/ncap2 -s mask_array=int(mask_array) jNSCf.nc 
jNSCff.nc\n",
                         "Mon Apr  6 17:17:29 2020: 
/HOME/opt/package/nco/linux64/bin/ncap2 -s where(mask_array > 3.) mask_array = 3. 
jNSCfl.nc jNSCf.nc\n",
                         "Mon Apr  6 17:17:06 2020: 
/HOME/opt/package/nco/linux64/bin/ncap2 -s mask_array=float(mask_array) jNSC.nc 
jNSCfl.nc\n",
                         "Mon Apr 06 16:38:46 2020: cdo add 
3xArctic_Cordillera_mask_l2_.25deg.nc jNS.nc jNSC.nc\n",
                         "Mon Apr 06 16:36:11 2020: cdo add 
Southern_Arctic_mask_l2_.25deg.nc 2xNorthern_Arctic_mask_l2_.25deg.nc jNS.nc\n",
                         "Mon Apr 06 16:35:10 2020: cdo mulc,2 
Northern_Arctic_mask_l2_.25deg.nc 2xNorthern_Arctic_mask_l2_.25deg.nc" ;
                 :DOMAIN_number_total = 1 ;
                 :DOMAIN_number = 0 ;
                 :DOMAIN_dimensions_ids = 1, 2 ;
                 :DOMAIN_size_global = 568, 400 ;
                 :DOMAIN_size_local = 568, 400 ;
                 :DOMAIN_position_first = 1, 1 ;
                 :DOMAIN_position_last = 568, 400 ;
                 :DOMAIN_halo_size_start = 0, 0 ;
                 :DOMAIN_halo_size_end = 0, 0 ;
                 :DOMAIN_type = "BOX" ;
                 :history_of_appended_files = "Mon Oct  2 22:18:28 2017: Appended file 
mesh_zgr.nc had following \"history\" attribute:\n",
                         "Mon Oct  2 22:18:08 2017: ncks -A mesh_hgr.nc 
mesh_zgr.nc\n",
                         "" ;
                 :NCO = "\"4.5.2\"" ;
                 :CDO = "Climate Data Operators version 1.6.8rc2 
(http://mpimet.mpg.de/cdo)" ;
}


$ gdalinfo CORDEX_subarea_O3.nc
Warning 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid 
argument".
Driver: netCDF/Network Common Data Format
Files: CORDEX_subarea_O3.nc
        CORDEX_subarea_O3.nc.aux.xml
Size is 232, 266
Metadata:
   mmask#coordinates=lon lat
   mmask#missing_value=-9e+33
   mmask#_FillValue=-9e+33
   NC_GLOBAL#CDI=Climate Data Interface version 1.6.8 (http://mpimet.mpg.de/cdi)
   NC_GLOBAL#CDO=Climate Data Operators version 1.6.8rc2 
(http://mpimet.mpg.de/cdo)
   NC_GLOBAL#Conventions=CF-1.4
   NC_GLOBAL#DOMAIN_dimensions_ids={1,2}
   NC_GLOBAL#DOMAIN_halo_size_end={0,0}
   NC_GLOBAL#DOMAIN_halo_size_start={0,0}
   NC_GLOBAL#DOMAIN_number=0
   NC_GLOBAL#DOMAIN_number_total=1
   NC_GLOBAL#DOMAIN_position_first={1,1}
   NC_GLOBAL#DOMAIN_position_last={568,400}
   NC_GLOBAL#DOMAIN_size_global={568,400}
   NC_GLOBAL#DOMAIN_size_local={568,400}
   NC_GLOBAL#DOMAIN_type=BOX
   NC_GLOBAL#history=Mon Apr 20 17:37:28 2020: cdo eqc,3 
All_subareas_CORDEX_final.nc CORDEX_subarea_O3.nc
Sat Apr 11 22:10:21 2020: cdo add jonn.nc jlnn.nc jann.nc
Sat Apr 11 21:55:59 2020: cdo sub latest_5.nc jln.nc jon.nc
Sat Apr 11 17:29:06 2020: cdo add jos.nc Land_subareas_new.nc 
All_subareas_CORDEX_reedited.nc
Sat Apr 11 17:22:45 2020: cdo sub All_subareas_CORDEX_edited.nc j.nc jos.nc
Tue Apr 07 15:58:18 2020: cdo add jon.nc 
EPA_Arctic_bioregions_CORDEX_land_masked_edited.nc All_subareas_CORDEX_edited.nc
Tue Apr 07 15:19:29 2020: cdo sub All_subareas_CORDEX_best.nc jl.nc jo.nc_
Tue Apr 07 00:58:57 2020: cdo remapnn,ARC-22_sample_grid.nc 
All_subareas_.25deg.nc j.nc
Tue Apr 07 00:48:41 2020: cdo add NAA_subareas_.25deg.nc 
EPA_Arctic_bioregions_.25degx-1.nc All_subareas_.25deg.nc
Tue Apr 07 00:48:01 2020: cdo mulc,-1 EPA_Arctic_bioregions_.25deg.nc 
EPA_Arctic_bioregions_.25degx-1.nc
Mon Apr 06 17:20:07 2020: cdo add 4xAlaskan_Tundra_mask_l2_.25deg.nc jNSCff.nc 
jNSCA.nc
Mon Apr  6 17:18:06 2020: /HOME/opt/package/nco/linux64/bin/ncap2 -s 
mask_array=int(mask_array) jNSCf.nc jNSCff.nc
Mon Apr  6 17:17:29 2020: /HOME/opt/package/nco/linux64/bin/ncap2 -s 
where(mask_array > 3.) mask_array = 3. jNSCfl.nc jNSCf.nc
Mon Apr  6 17:17:06 2020: /HOME/opt/package/nco/linux64/bin/ncap2 -s 
mask_array=float(mask_array) jNSC.nc jNSCfl.nc
Mon Apr 06 16:38:46 2020: cdo add 3xArctic_Cordillera_mask_l2_.25deg.nc jNS.nc 
jNSC.nc
Mon Apr 06 16:36:11 2020: cdo add Southern_Arctic_mask_l2_.25deg.nc 
2xNorthern_Arctic_mask_l2_.25deg.nc jNS.nc
Mon Apr 06 16:35:10 2020: cdo mulc,2 Northern_Arctic_mask_l2_.25deg.nc 
2xNorthern_Arctic_mask_l2_.25deg.nc
   NC_GLOBAL#history_of_appended_files=Mon Oct  2 22:18:28 2017: Appended file 
mesh_zgr.nc had following "history" attribute:
Mon Oct  2 22:18:08 2017: ncks -A mesh_hgr.nc mesh_zgr.nc

   NC_GLOBAL#NCO="4.5.2"
Subdatasets:
   SUBDATASET_1_NAME=NETCDF:"CORDEX_subarea_O3.nc":lon
   SUBDATASET_1_DESC=[266x232] longitude (64-bit floating-point)
   SUBDATASET_2_NAME=NETCDF:"CORDEX_subarea_O3.nc":lat
   SUBDATASET_2_DESC=[266x232] latitude (64-bit floating-point)
   SUBDATASET_3_NAME=NETCDF:"CORDEX_subarea_O3.nc":mmask
   SUBDATASET_3_DESC=[266x232] mmask (64-bit floating-point)
Geolocation:
   LINE_OFFSET=0
   LINE_STEP=1
   PIXEL_OFFSET=0
   PIXEL_STEP=1
   SRS=GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 
84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
   X_BAND=1
   X_DATASET=NETCDF:"CORDEX_subarea_O3.nc":lon
   Y_BAND=1
   Y_DATASET=NETCDF:"CORDEX_subarea_O3.nc":lat
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,  266.0)
Upper Right (  232.0,    0.0)
Lower Right (  232.0,  266.0)
Center      (  116.0,  133.0)
Band 1 Block=232x1 Type=Float64, ColorInterp=Undefined
   Min=0.000 Max=1.000
   Minimum=0.000, Maximum=1.000, Mean=0.021, StdDev=0.144
   NoData Value=-9.00000000000000009e+33
   Metadata:
     coordinates=lon lat
     missing_value=-9e+33
     NETCDF_VARNAME=mmask
     STATISTICS_MAXIMUM=1
     STATISTICS_MEAN=0.021243842364532
     STATISTICS_MINIMUM=0
     STATISTICS_STDDEV=0.14419619109437
     _FillValue=-9e+33


------------------------------------------
Brendan DeTracey, VS 203/2-3
[email protected]

Ocean Monitoring and Observation Section | Section de surveillance et 
d'observation océanique /
Ocean Modelling and Analysis Section | Section d'analyse et de modélisation

Ocean and Ecosystem Sciences Division | Division des sciences de l'écosystème 
et de la mer
Fisheries and Oceans Canada | Pêches et Oceans Canada
Bedford Institute of Oceanography | Institut Océanographique de Bedford
P.O. Box 1006, 1 Challenger Dr. | C.P.1006, 1 Challenger Dr.
Dartmouth, N.S. Canada B2Y 4A2 | Dartmouth, N.-É., Canada B2Y 4A2
Telephone | Téléphone 902-426-9727
------------------------------------------
If you have received this communication by mistake, please notify the sender 
immediately and delete the communication without printing, copying or 
forwarding it. Thank you.
Si vous avez reçu cette communication par erreur, veuillez en aviser 
l'expéditeur immédiatement et la supprimer sans l'imprimer, la copier, ou la 
faire suivre. Merci.
------------------------------------------

_______________________________________________
gdal-dev mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

--
http://www.spatialys.com
My software is free, but my time generally not.

_______________________________________________
gdal-dev mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to