import os, sys # the standard imports
BaseFolder = r'C:\Users\Dlan\Desktop\netCDF_TIFF' # change this to match your data
for FullPath, dirs, files in os.walk(BaseFolder): for ThisFile in files: # iterate the files fN,fE = os.path.splitext(ThisFile) # separate file name and extension if fE.lower() == 'LCCS-2018.nc': # this is a netCDF file, though other extensions might exist # you will need to provide these details or ascertain them from # the input NetCDF file name.
import os, sys # the standard imports
BaseFolder = r'C:\Users\Dlan\Desktop\netCDF_TIFF' # change this to match your data
for FullPath, dirs, files in os.walk(BaseFolder):
for ThisFile in files: # iterate the files
fN,fE = os.path.splitext(ThisFile) # separate file name and extension
if fE.lower() == 'LCCS-2018.nc':
# this is a netCDF file, though other extensions might exist
# you will need to provide these details or ascertain them from
# the input NetCDF file name.
Year = '2018'
Band = 'lccs_class'
OutputName = 'LCCS-2018'
GDAL_Command = 'gdalwarp -of Gtiff -co COMPRESS=LZW -co TILED=YES -ot Byte -te '\
'-180.0000000 -90.0000000 180.0000000 90.0000000 -tr 0.002777777777778 0.002777777777778 '\
'-t_srs EPSG:4326 NETCDF:{}YEAR.nc:{} {}.tif'.format( Year, Band, os.path.join(FullPath,OutputName))
os.system(GDAL_Command) # run the command
Format:
gdalwarp -of Gtiff -co COMPRESS=LZW -co TILED=YES -ot Byte -te -180.0000000 -90.0000000 180.0000000 90.0000000 -tr 0.002777777777778 0.002777777777778 -t_srs EPSG:4326 NETCDF:XXX-YEAR.nc:BandName OutputFilename.tifgdalwarp -of Gtiff -co COMPRESS=LZW -co TILED=YES -ot Byte -te -180.0000000 -90.0000000 180.0000000 90.0000000 -tr 0.002777777777778 0.002777777777778 -t_srs EPSG:4326 NETCDF:XXX-YEAR.nc:BandName OutputFilename.tif
Example code:
gdalwarp -of Gtiff -co COMPRESS=LZW -co TILED=YES -ot Byte -te -180.0000000 -90.0000000 180.0000000 90.0000000 -tr 0.002777777777778 0.002777777777778 -t_srs EPSG:4326 NETCDF:LCCS-2018.nc:lccs_class LCCS-2018.tifgdalwarp -of Gtiff -co COMPRESS=LZW -co TILED=YES -ot Byte -te -180.0000000 -90.0000000 180.0000000 90.0000000 -tr 0.002777777777778 0.002777777777778 -t_srs EPSG:4326 NETCDF:LCCS-2018.nc:lccs_class LCCS-2018.tif