使用GDAL将NetCDF文件转换为GeoTIFF?


10

我有一个NetCDF文件,其中包含英国下雨天数的数据。我想将其转换为GeoTIFF,但无法正确获取GDAL地理参考。请参阅下面来自gdalinfo的转储。

我想要一个显示“ raindays_tmean_abs”变量的TIFF乐队。“ lat”和“ lon”变量似乎具有合理的最小/最大值,可以将数据放到整个英国,但是当我使用gdal_translate进行转换时,它最终出现在非洲西海岸。

关于第一个尺寸不是“时间或垂直”尺寸的警告。我读到gdal期望数据按一定顺序排列,所以也许这就是问题所在,但是我不知道如何修改它。

如何转换/重新投影此数据?

gdalinfo NETCDF:RainDays1_1961-1990_LTA_25km.nc

Warning 1: dimension #0 (meaning_period) is not a Time or Vertical dimension.
Driver: netCDF/Network Common Data Format
Files: RainDays1_1961-1990_LTA_25km.nc
       RainDays1_1961-1990_LTA_25km.nc.aux.xml
Size is 39, 52
Coordinate System is `'
Origin = (-17.650008352179277,11.329999312758446)
Pixel Size = (0.219999614514803,-0.219999998807907)
Metadata:
  axis_0#units=
  meaning_period#comment=Meaning periods are all months (12) beginning January, all seasons (4) beginning Winter (DJF) and Annual (1)
  meaning_period#long_name=meaning_period
  meaning_period#units=
  NC_GLOBAL#Conventions=CF-1.0
  NETCDF_DIM_EXTRA={meaning_period}
  NETCDF_DIM_meaning_period_DEF={17,6}
  NETCDF_DIM_meaning_period_VALUES={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}
  raindays_tmean_abs#comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
  raindays_tmean_abs#coordinates=lon lat
  raindays_tmean_abs#long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
  raindays_tmean_abs#missing_value=1e+020
  raindays_tmean_abs#name=rain_days
  raindays_tmean_abs#title=rain_days
  raindays_tmean_abs#units=days
  rlat#axis=Y
  rlat#bounds=bounds_rlat
  rlat#long_name=latitude in rotated pole grid
  rlat#standard_name=grid_latitude
  rlat#units=degrees
  rlon#axis=X
  rlon#bounds=bounds_rlon
  rlon#long_name=longitude in rotated pole grid
  rlon#modulo=360
  rlon#standard_name=grid_longitude
  rlon#topology=circular
  rlon#units=degrees
Subdatasets:
  SUBDATASET_1_NAME=NETCDF:"RainDays1_1961-1990_LTA_25km.nc":bounds_rlat
  SUBDATASET_1_DESC=[52x2] bounds_rlat (64-bit floating-point)
  SUBDATASET_2_NAME=NETCDF:"RainDays1_1961-1990_LTA_25km.nc":bounds_rlon
  SUBDATASET_2_DESC=[39x2] bounds_rlon (64-bit floating-point)
  SUBDATASET_3_NAME=NETCDF:"RainDays1_1961-1990_LTA_25km.nc":lat
  SUBDATASET_3_DESC=[52x39] latitude (32-bit floating-point)
  SUBDATASET_4_NAME=NETCDF:"RainDays1_1961-1990_LTA_25km.nc":lon
  SUBDATASET_4_DESC=[52x39] longitude (32-bit floating-point)
  SUBDATASET_5_NAME=NETCDF:"RainDays1_1961-1990_LTA_25km.nc":raindays_tmean_abs
  SUBDATASET_5_DESC=[17x52x39] raindays_tmean_abs (32-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"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9108"]],AUTHORITY["EPSG","4326"]]
  X_BAND=1
  X_DATASET=NETCDF:"RainDays1_1961-1990_LTA_25km.nc":lon
  Y_BAND=1
  Y_DATASET=NETCDF:"RainDays1_1961-1990_LTA_25km.nc":lat
Corner Coordinates:
Upper Left  ( -17.6500084,  11.3299993) 
Lower Left  ( -17.6500084,  -0.1100006) 
Upper Right (  -9.0700234,  11.3299993) 
Lower Right (  -9.0700234,  -0.1100006) 
Center      ( -13.3600159,   5.6099993) 
Band 1 Block=39x1 Type=Float32, ColorInterp=Undefined
  Min=10.658 Max=22.949 
  Minimum=10.658, Maximum=22.949, Mean=15.625, StdDev=3.151
  NoData Value=1.0000000200408773e+020
  Metadata:
    comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
    coordinates=lon lat
    long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
    missing_value=1e+020
    name=rain_days
    NETCDF_DIM_meaning_period=0
    NETCDF_VARNAME=raindays_tmean_abs
    STATISTICS_MAXIMUM=22.949373245239
    STATISTICS_MEAN=15.624619410087
    STATISTICS_MINIMUM=10.657625198364
    STATISTICS_STDDEV=3.1508820627895
    title=rain_days
    units=days
Band 2 Block=39x1 Type=Float32, ColorInterp=Undefined
  Min=7.893 Max=17.172 
  Minimum=7.893, Maximum=17.172, Mean=11.591, StdDev=2.282
  NoData Value=1.0000000200408773e+020
  Metadata:
    comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
    coordinates=lon lat
    long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
    missing_value=1e+020
    name=rain_days
    NETCDF_DIM_meaning_period=1
    NETCDF_VARNAME=raindays_tmean_abs
    STATISTICS_MAXIMUM=17.172254562378
    STATISTICS_MEAN=11.591275386767
    STATISTICS_MINIMUM=7.8926663398743
    STATISTICS_STDDEV=2.28225356537
    title=rain_days
    units=days
Band 3 Block=39x1 Type=Float32, ColorInterp=Undefined
  Min=9.700 Max=21.762 
  Minimum=9.700, Maximum=21.762, Mean=13.882, StdDev=2.988
  NoData Value=1.0000000200408773e+020
  Metadata:
    comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
    coordinates=lon lat
    long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
    missing_value=1e+020
    name=rain_days
    NETCDF_DIM_meaning_period=2
    NETCDF_VARNAME=raindays_tmean_abs
    STATISTICS_MAXIMUM=21.761842727661
    STATISTICS_MEAN=13.88236379732
    STATISTICS_MINIMUM=9.7001943588257
    STATISTICS_STDDEV=2.9875935432638
    title=rain_days
    units=days
Band 4 Block=39x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1.0000000200408773e+020
  Metadata:
    comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
    coordinates=lon lat
    long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
    missing_value=1e+020
    name=rain_days
    NETCDF_DIM_meaning_period=3
    NETCDF_VARNAME=raindays_tmean_abs
    title=rain_days
    units=days
Band 5 Block=39x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1.0000000200408773e+020
  Metadata:
    comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
    coordinates=lon lat
    long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
    missing_value=1e+020
    name=rain_days
    NETCDF_DIM_meaning_period=4
    NETCDF_VARNAME=raindays_tmean_abs
    title=rain_days
    units=days
Band 6 Block=39x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1.0000000200408773e+020
  Metadata:
    comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
    coordinates=lon lat
    long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
    missing_value=1e+020
    name=rain_days
    NETCDF_DIM_meaning_period=5
    NETCDF_VARNAME=raindays_tmean_abs
    title=rain_days
    units=days
Band 7 Block=39x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1.0000000200408773e+020
  Metadata:
    comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
    coordinates=lon lat
    long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
    missing_value=1e+020
    name=rain_days
    NETCDF_DIM_meaning_period=6
    NETCDF_VARNAME=raindays_tmean_abs
    title=rain_days
    units=days
Band 8 Block=39x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1.0000000200408773e+020
  Metadata:
    comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
    coordinates=lon lat
    long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
    missing_value=1e+020
    name=rain_days
    NETCDF_DIM_meaning_period=7
    NETCDF_VARNAME=raindays_tmean_abs
    title=rain_days
    units=days
Band 9 Block=39x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1.0000000200408773e+020
  Metadata:
    comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
    coordinates=lon lat
    long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
    missing_value=1e+020
    name=rain_days
    NETCDF_DIM_meaning_period=8
    NETCDF_VARNAME=raindays_tmean_abs
    title=rain_days
    units=days
Band 10 Block=39x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1.0000000200408773e+020
  Metadata:
    comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
    coordinates=lon lat
    long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
    missing_value=1e+020
    name=rain_days
    NETCDF_DIM_meaning_period=9
    NETCDF_VARNAME=raindays_tmean_abs
    title=rain_days
    units=days
Band 11 Block=39x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1.0000000200408773e+020
  Metadata:
    comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
    coordinates=lon lat
    long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
    missing_value=1e+020
    name=rain_days
    NETCDF_DIM_meaning_period=10
    NETCDF_VARNAME=raindays_tmean_abs
    title=rain_days
    units=days
Band 12 Block=39x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1.0000000200408773e+020
  Metadata:
    comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
    coordinates=lon lat
    long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
    missing_value=1e+020
    name=rain_days
    NETCDF_DIM_meaning_period=11
    NETCDF_VARNAME=raindays_tmean_abs
    title=rain_days
    units=days
Band 13 Block=39x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1.0000000200408773e+020
  Metadata:
    comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
    coordinates=lon lat
    long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
    missing_value=1e+020
    name=rain_days
    NETCDF_DIM_meaning_period=12
    NETCDF_VARNAME=raindays_tmean_abs
    title=rain_days
    units=days
Band 14 Block=39x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1.0000000200408773e+020
  Metadata:
    comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
    coordinates=lon lat
    long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
    missing_value=1e+020
    name=rain_days
    NETCDF_DIM_meaning_period=13
    NETCDF_VARNAME=raindays_tmean_abs
    title=rain_days
    units=days
Band 15 Block=39x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1.0000000200408773e+020
  Metadata:
    comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
    coordinates=lon lat
    long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
    missing_value=1e+020
    name=rain_days
    NETCDF_DIM_meaning_period=14
    NETCDF_VARNAME=raindays_tmean_abs
    title=rain_days
    units=days
Band 16 Block=39x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1.0000000200408773e+020
  Metadata:
    comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
    coordinates=lon lat
    long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
    missing_value=1e+020
    name=rain_days
    NETCDF_DIM_meaning_period=15
    NETCDF_VARNAME=raindays_tmean_abs
    title=rain_days
    units=days
Band 17 Block=39x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1.0000000200408773e+020
  Metadata:
    comment=Converted from UKCP09 monthly data to climatologies and then averaged to 25km rotated pole grid.
    coordinates=lon lat
    long_name=Number of days per meaning period having a rainfall >= 1 mm (days)
    missing_value=1e+020
    name=rain_days
    NETCDF_DIM_meaning_period=16
    NETCDF_VARNAME=raindays_tmean_abs
    title=rain_days
    units=days

gdalinfo NETCDF:RainDays1_1961-1990_LTA_25km.nc:lon

Driver: netCDF/Network Common Data Format
Files: RainDays1_1961-1990_LTA_25km.nc
       RainDays1_1961-1990_LTA_25km.nc.aux.xml
Size is 39, 52
Coordinate System is `'
Origin = (-17.650008352179277,11.329999312758446)
Pixel Size = (0.219999614514803,-0.219999998807907)
Metadata:
  axis_0#units=
  lon#long_name=longitude
  lon#missing_value=1e+020
  lon#name=lon
  lon#standard_name=longitude
  lon#units=degrees_east
  meaning_period#comment=Meaning periods are all months (12) beginning January, all seasons (4) beginning Winter (DJF) and Annual (1)
  meaning_period#long_name=meaning_period
  meaning_period#units=
  NC_GLOBAL#Conventions=CF-1.0
  rlat#axis=Y
  rlat#bounds=bounds_rlat
  rlat#long_name=latitude in rotated pole grid
  rlat#standard_name=grid_latitude
  rlat#units=degrees
  rlon#axis=X
  rlon#bounds=bounds_rlon
  rlon#long_name=longitude in rotated pole grid
  rlon#modulo=360
  rlon#standard_name=grid_longitude
  rlon#topology=circular
  rlon#units=degrees
Corner Coordinates:
Upper Left  ( -17.6500084,  11.3299993) 
Lower Left  ( -17.6500084,  -0.1100006) 
Upper Right (  -9.0700234,  11.3299993) 
Lower Right (  -9.0700234,  -0.1100006) 
Center      ( -13.3600159,   5.6099993) 
Band 1 Block=39x1 Type=Float32, ColorInterp=Undefined
  Min=-15.830 Max=3.672 
  Minimum=-15.830, Maximum=3.672, Mean=-5.246, StdDev=4.393
  NoData Value=1.0000000200408773e+020
  Metadata:
    long_name=longitude
    missing_value=1e+020
    name=lon
    NETCDF_VARNAME=lon
    standard_name=longitude
    STATISTICS_MAXIMUM=3.671746969223
    STATISTICS_MEAN=-5.2457962955782
    STATISTICS_MINIMUM=-15.830010414124
    STATISTICS_STDDEV=4.3927366732513
    units=degrees_east

gdalinfo NETCDF:RainDays1_1961-1990_LTA_25km.nc:lat

Driver: netCDF/Network Common Data Format
Files: RainDays1_1961-1990_LTA_25km.nc
       RainDays1_1961-1990_LTA_25km.nc.aux.xml
Size is 39, 52
Coordinate System is `'
Origin = (-17.650008352179277,11.329999312758446)
Pixel Size = (0.219999614514803,-0.219999998807907)
Metadata:
  axis_0#units=
  lat#long_name=latitude
  lat#missing_value=1e+020
  lat#name=lat
  lat#standard_name=latitude
  lat#units=degrees_north
  meaning_period#comment=Meaning periods are all months (12) beginning January, all seasons (4) beginning Winter (DJF) and Annual (1)
  meaning_period#long_name=meaning_period
  meaning_period#units=
  NC_GLOBAL#Conventions=CF-1.0
  rlat#axis=Y
  rlat#bounds=bounds_rlat
  rlat#long_name=latitude in rotated pole grid
  rlat#standard_name=grid_latitude
  rlat#units=degrees
  rlon#axis=X
  rlon#bounds=bounds_rlon
  rlon#long_name=longitude in rotated pole grid
  rlon#modulo=360
  rlon#standard_name=grid_longitude
  rlon#topology=circular
  rlon#units=degrees
Corner Coordinates:
Upper Left  ( -17.6500084,  11.3299993) 
Lower Left  ( -17.6500084,  -0.1100006) 
Upper Right (  -9.0700234,  11.3299993) 
Lower Right (  -9.0700234,  -0.1100006) 
Center      ( -13.3600159,   5.6099993) 
Band 1 Block=39x1 Type=Float32, ColorInterp=Undefined
  Min=47.594 Max=60.806 
  Minimum=47.594, Maximum=60.806, Mean=54.186, StdDev=3.229
  NoData Value=1.0000000200408773e+020
  Metadata:
    long_name=latitude
    missing_value=1e+020
    name=lat
    NETCDF_VARNAME=lat
    standard_name=latitude
    STATISTICS_MAXIMUM=60.805950164795
    STATISTICS_MEAN=54.185836173138
    STATISTICS_MINIMUM=47.594329833984
    STATISTICS_STDDEV=3.228754901642
    units=degrees_north

...很不幸,我还没有50个声誉,因此我会“回答”而不是发表评论;我对使用Windows cmd-line的gdal解决方案非常感兴趣!我正在使用R将gdal_translate命令移交给cmd行。到目前为止我尝试过的是:```data_source <-'D:/user1/01_data/input.nc'data_output <-'D:/user1/01_data/output.tif'system(command = paste('gdal_translate- GTiff -sds -a_srs epsg:4326',data_source,data_output))`''正常,但是我丢失了crs信息!有谁知道如何保存crs信息!?
ExploreR

Answers:



2

您是否尝试使用gdal_translate进行转换?

通常,它应该使用以下两种可能性之一来工作:

第一个解决方案:手动提取每个子数据集

gdal_translate -of VRT NETCDF:"RainDays1_1961-1990_LTA_25km.nc":raindays_tmean_abs output_RD.vrt 
gdal_translate -of VRT NETCDF:"RainDays1_1961-1990_LTA_25km.nc":lat output_lat.vrt 
gdal_translate -of VRT NETCDF:"RainDays1_1961-1990_LTA_25km.nc":lon output_lon.vrt

第二种解决方案:让Gdal自动提取子数据集

gdal_translate -of VRT -sds RainDays1_1961-1990_LTA_25km.nc output.vrt

第二种解决方案将所有子数据集提取到单独的文件中。

可能需要包括

-a_srs epsg:4326


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.