Skip to main content
 首页 » 编程设计

python之如何在 python 中从 vrt 文件创建栅格时间序列

2025年05月04日15unruledboy

我使用 gdal(光栅虚拟格式)将一堆 .tiff 文件转换为 .vrt

gdalbuildvrt -separate testvrt.vrt data/*.tif 

有没有办法从 .vrt 创建时间序列 NetCDF 文件!?

testvrt.vrt

<VRTDataset rasterXSize="8000" rasterYSize="8000"> 
  <SRS>PROJCS["Azimuthal_Equidistant",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Azimuthal_Equidistant"],PARAMETER["latitude_of_center",8.5],PARAMETER["longitude_of_center",21.5],PARAMETER["false_easting",5621452.01998],PARAMETER["false_northing",5990638.42298],UNIT["metre",1,AUTHORITY["EPSG","9001"]]]</SRS> 
  <GeoTransform>  6.0000000000000000e+06,  7.5000000000000000e+01,  0.0000000000000000e+00,  6.0000000000000000e+06,  0.0000000000000000e+00, -7.5000000000000000e+01</GeoTransform> 
  <VRTRasterBand dataType="Int16" band="1"> 
    <NoDataValue>-9.99900000000000E+03</NoDataValue> 
    <ComplexSource> 
      <SourceFilename relativeToVRT="1">data_sample/R20060111_075725___SIG0__ASAWS___M1VVD_TUW_SGRT15A00_AF075M_E060N054T6.tif</SourceFilename> 
      <SourceBand>1</SourceBand> 
      <SourceProperties RasterXSize="8000" RasterYSize="8000" DataType="Int16" BlockXSize="8000" BlockYSize="1" /> 
      <SrcRect xOff="0" yOff="0" xSize="8000" ySize="8000" /> 
      <DstRect xOff="0" yOff="0" xSize="8000" ySize="8000" /> 
      <NODATA>-9999</NODATA> 
    </ComplexSource> 
  </VRTRasterBand> 
  <VRTRasterBand dataType="Int16" band="2"> 
    <NoDataValue>-9.99900000000000E+03</NoDataValue> 
    <ComplexSource> 
      <SourceFilename relativeToVRT="1">data_sample/R20060114_080443___SIG0__ASAWS___M1VVD_TUW_SGRT15A00_AF075M_E060N054T6.tif</SourceFilename> 
      <SourceBand>1</SourceBand> 
      <SourceProperties RasterXSize="8000" RasterYSize="8000" DataType="Int16" BlockXSize="8000" BlockYSize="1" /> 
      <SrcRect xOff="0" yOff="0" xSize="8000" ySize="8000" /> 
      <DstRect xOff="0" yOff="0" xSize="8000" ySize="8000" /> 
      <NODATA>-9999</NODATA> 
    </ComplexSource> 
  </VRTRasterBand> 
... 

如何将 python 中的 vrt 文件转换为 NetCDF4 格式的栅格时间序列?

请您参考如下方法:

您可以像以前一样使用单独的波段转换为 vrt。还制作图像路径的文本文件,您可以从中检索时间。 然后将它们加载到您的代码中。

看看这个POST这是我发布的,以了解如何在 NetCDF 格式中编写它们。