爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 11377|回复: 2

[经验总结] 關於python GDAL 的 gdal_translate 和 gdalwarp

[复制链接]

新浪微博达人勋

发表于 2021-6-30 16:24:03 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本帖最后由 dragonphy 于 2021-6-30 16:55 编辑

分享一個一直以來轉換數據的好幫手,歡迎各位大佬補充和糾正!
1.      如何安裝?
由於 GDAL 似乎與 Spyder 相衝突,因此需專門為 GDAL 創造子環境:
condacreate --name gdal_test_working -c conda-forge python=xxx gdal
$ condaactivate gdal_test_working
(gdal_test_working) $

2.      萬能的數據格式轉換工具 ─ gdal_translate (https://gdal.org/programs/gdal_translate.html#gdal-translate)
Example 1 將 GeoTiff 轉換成 HDF5:
(gdal_test_working)$ gdal_translate -of HDF4Image 路徑/源文件.tif 路徑/新文件.hdf
$ 路徑/h4h5tools/bin/h4toh5convert 路徑/新文件.hdf 路徑/目標文件.h5
[說明]:這裡需另外安裝h4h5tools

Example 2轉換時只複製源數據的一部分 (裁剪數據):
(gdal_test_working)$ gdal_translate -of netCDF -ot UInt16 -projwin 94.45 29.7255 94.95 29.275-projwin_srs ‘+proj=longlat +datum=WGS84 +no_defs’ 路徑/源文件.tif 路徑/目標文件.nc
[說明]:-prowin 是以絕對座標表達 (xlow yhigh xhigh ylow),坐標系投影可用-prowin_srs指定。另外,用網格相對位置表達 -srcwin (xoff yoff xsize ysize) 前兩項是距左上角的偏移量,後兩項是選取矩形的寬度和高度以網格數為單位。-ot UInt16表示輸出數據類型為無正負符號2字節的整數。
3.      轉換數據的投影、坐標系等的實用工具 ─ gdalwarp (https://gdal.org/programs/gdalwarp.html)
Example3 等經緯度插值成等距的數據 (lonlat to UTM):
(gdal_test_working)$ gdalwarp -t_srs ‘+proj=utm +zone=46 +datum=WGS84 +units=m +no_defs’ -tr 30 30 -r bilinear 路徑/源文件.tif 路徑/目標文件.tif
[說明]:
a)  -t_srs 是目標轉換的空間參考。 proj4語法說明 (https://proj.org/usage/projections.html) >>>  +proj 投影名稱 (=longlat or utm) +zone UTM分區 (如果是南半球需多寫 +south);+units 以公尺(m)為單位;+datum 大地水準面名稱 (=WGS84);+ellps 橢球坐標系名稱。你也可以去查 EPSG,例如以上例子的UTM zone 46N 也可表達為 EPSG:32646,EPSG不需要引號。
b)  -r bilinear 表示插值採用雙線性、-tr 30 30 表示水平分辨率為30 m。



GDAL支持的數據格式 (任何兩者之間皆可轉換,-of 填寫目標格式的簡稱):
  VRT: Virtual Raster
  GTiff: GeoTIFF
  NITF: National Imagery Transmission Format
  HFA: Erdas Imagine Images (.img)
  ELAS: ELAS
  AAIGrid: Arc/Info ASCII Grid
  DTED: DTED Elevation Raster
  PNG: Portable Network Graphics
  JPEG: JPEG JFIF
  MEM: In Memory Raster
  GIF: Graphics Interchange Format (.gif)
  FITS: Flexible Image Transport System
  XPM: X11 PixMap Format
  BMP: MS Windows Device Independent Bitmap
  PCIDSK: PCIDSK Database File
  PCRaster: PCRaster Raster File
  ILWIS: ILWIS Raster Map
  SGI: SGI Image File Format 1.0
  SRTMHGT: SRTMHGT File Format
  Leveller: Leveller heightfield
  Terragen: Terragen heightfield
  GMT: GMT NetCDF Grid Format
  netCDF: Network Common Data Format
  HDF4Image: HDF4 Dataset
  ISIS3: USGS Astrogeology ISIS cube (Version3)
  ISIS2: USGS Astrogeology ISIS cube (Version2)
  PDS4: NASA Planetary Data System 4
  ERS: ERMapper .ers Labelled
  JP2OpenJPEG: JPEG-2000 driver based onOpenJPEG library
  FIT: FIT Image
  GRIB: GRIdded Binary (.grb, .grb2)
  RMF: Raster Matrix Format
  WMS: OGC Web Map Service
  RST: Idrisi Raster A.1
  INGR: Intergraph Raster
  GSAG: Golden Software ASCII Grid (.grd)
  GSBG: Golden Software Binary Grid (.grd)
  GS7BG: Golden Software 7 Binary Grid (.grd)
  R: R Object Data Store
  KMLSUPEROVERLAY: Kml Super Overlay
  PDF: Geospatial PDF
  Rasterlite: Rasterlite
  MBTiles: MBTiles
  CALS: CALS (Type 1)
  WMTS: OGC Web Map Tile Service
  MRF: Meta Raster Format
  TileDB: TileDB
  PNM: Portable Pixmap Format (netpbm)
  PAux: PCI .aux Labelled
  MFF: Vexcel MFF Raster
  MFF2: Vexcel MFF2 (HKV) Raster
  BT: VTP .bt (Binary Terrain) 1.3 Format
  LAN: Erdas .LAN/.GIS
  IDA: Image Data and Analysis
  LCP: FARSITE v.4 Landscape File (.lcp)
  GTX: NOAA Vertical Datum .GTX
  NTv2: NTv2 Datum Grid Shift
  CTable2: CTable2 Datum Grid Shift
  KRO: KOLOR Raw
  ROI_PAC: ROI_PAC raster
  RRASTER: R Raster
  BYN: Natural Resources Canada's Geoid
  ARG: Azavea Raster Grid format
  USGSDEM: USGS Optional ASCII DEM (and CDED)
  KEA: KEA Image Format (.kea)
  BAG: Bathymetry Attributed Grid
  NWT_GRD: Northwood Numeric Grid Format.grd/.tab
  ADRG: ARC Digitized Raster Graphics
  BLX: Magellan topo (.blx)
  PostGISRaster: PostGIS Raster driver
  SAGA: SAGA GIS Binary Grid (.sdat, .sg-grd-z)
  XYZ: ASCII Gridded XYZ
  HF2: HF2/HFZ heightfield raster
  ZMap: ZMap Plus Grid
  SIGDEM: Scaled Integer Gridded DEM .sigdem
  GPKG: GeoPackage
  NGW: NextGIS Web
ENVI: ENVI .hdr Labelled (header file .hdr and binary file .bil, .flt or .bin)
  EHdr: ESRI .hdr Labelled
  ISCE: ISCE raster

密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2021-7-11 14:30:49 | 显示全部楼层
MSBFIRST means Most Significant Byte First, and is also known as being "big-endian". Other terms are "Motorola-order" and occasionally "network order".
LSBFIRST is Least Significant Byte First, also known as "little-endian". It is also known as Intel-order.
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2023-4-5 18:36:47 | 显示全部楼层
请问在投影转换的时候,没有语法错误,按照要求写,但是无法生成新的tiff文件是为什么呢
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表