栅格格式转换
作者:阿振
修改时间:2018-05-17
声明:本文为博主原创文章,转载请注明原文出处
查看GDAL支持的栅格数据格式
我们可以在终端中使用gdal --formats
命令查看安装的GDAL库支持的栅格数据格式
Supported Formats:
VRT -raster- (rw+v): Virtual Raster
DERIVED -raster- (ro): Derived datasets using VRT pixel functions
GTiff -raster- (rw+vs): GeoTIFF
NITF -raster- (rw+vs): National Imagery Transmission Format
RPFTOC -raster- (rovs): Raster Product Format TOC format
ECRGTOC -raster- (rovs): ECRG TOC format
HFA -raster- (rw+v): Erdas Imagine Images (.img)
SAR_CEOS -raster- (rov): CEOS SAR Image
CEOS -raster- (rov): CEOS Image
JAXAPALSAR -raster- (rov): JAXA PALSAR Product Reader (Level 1.1/1.5)
GFF -raster- (rov): Ground-based SAR Applications Testbed File Format (.gff)
ELAS -raster- (rw+v): ELAS
AIG -raster- (rov): Arc/Info Binary Grid
AAIGrid -raster- (rwv): Arc/Info ASCII Grid
GRASSASCIIGrid -raster- (rov): GRASS ASCII Grid
SDTS -raster- (rov): SDTS Raster
DTED -raster- (rwv): DTED Elevation Raster
PNG -raster- (rwv): Portable Network Graphics
JPEG -raster- (rwv): JPEG JFIF
MEM -raster- (rw+): In Memory Raster
JDEM -raster- (rov): Japanese DEM (.mem)
GIF -raster- (rwv): Graphics Interchange Format (.gif)
BIGGIF -raster- (rov): Graphics Interchange Format (.gif)
ESAT -raster- (rov): Envisat Image Format
BSB -raster- (rov): Maptech BSB Nautical Charts
XPM -raster- (rwv): X11 PixMap Format
BMP -raster- (rw+v): MS Windows Device Independent Bitmap
DIMAP -raster- (rov): SPOT DIMAP
AirSAR -raster- (rov): AirSAR Polarimetric Image
RS2 -raster- (ros): RadarSat 2 XML Product
SAFE -raster- (rov): Sentinel-1 SAR SAFE Product
PCIDSK -raster,vector- (rw+v): PCIDSK Database File
PCRaster -raster- (rw+): PCRaster Raster File
ILWIS -raster- (rw+v): ILWIS Raster Map
SGI -raster- (rw+): SGI Image File Format 1.0
SRTMHGT -raster- (rwv): SRTMHGT File Format
Leveller -raster- (rw+): Leveller heightfield
Terragen -raster- (rw+): Terragen heightfield
GMT -raster- (rw): GMT NetCDF Grid Format
netCDF -raster,vector- (rw+s): Network Common Data Format
HDF4 -raster- (ros): Hierarchical Data Format Release 4
HDF4Image -raster- (rw+): HDF4 Dataset
ISIS3 -raster- (rw+v): USGS Astrogeology ISIS cube (Version 3)
ISIS2 -raster- (rw+v): USGS Astrogeology ISIS cube (Version 2)
PDS -raster- (rov): NASA Planetary Data System
VICAR -raster- (rov): MIPL VICAR file
TIL -raster- (rov): EarthWatch .TIL
ERS -raster- (rw+v): ERMapper .ers Labelled
JP2OpenJPEG -raster,vector- (rwv): JPEG-2000 driver based on OpenJPEG library
L1B -raster- (rovs): NOAA Polar Orbiter Level 1b Data Set
FIT -raster- (rwv): FIT Image
GRIB -raster- (rov): GRIdded Binary (.grb)
RMF -raster- (rw+v): Raster Matrix Format
WCS -raster- (rovs): OGC Web Coverage Service
WMS -raster- (rwvs): OGC Web Map Service
MSGN -raster- (ro): EUMETSAT Archive native (.nat)
RST -raster- (rw+v): Idrisi Raster A.1
INGR -raster- (rw+v): Intergraph Raster
GSAG -raster- (rwv): Golden Software ASCII Grid (.grd)
GSBG -raster- (rw+v): Golden Software Binary Grid (.grd)
GS7BG -raster- (rw+v): Golden Software 7 Binary Grid (.grd)
COSAR -raster- (rov): COSAR Annotated Binary Matrix (TerraSAR-X)
TSX -raster- (rov): TerraSAR-X Product
COASP -raster- (ro): DRDC COASP SAR Processor Raster
R -raster- (rwv): R Object Data Store
MAP -raster- (rov): OziExplorer .MAP
KMLSUPEROVERLAY -raster- (rwv): Kml Super Overlay
PDF -raster,vector- (rw+vs): Geospatial PDF
Rasterlite -raster- (rws): Rasterlite
MBTiles -raster- (rw+v): MBTiles
PLMOSAIC -raster- (ro): Planet Labs Mosaics API
CALS -raster- (rw): CALS (Type 1)
WMTS -raster- (rwv): OGC Web Mab Tile Service
SENTINEL2 -raster- (rovs): Sentinel 2
MRF -raster- (rw+v): Meta Raster Format
PNM -raster- (rw+v): Portable Pixmap Format (netpbm)
DOQ1 -raster- (rov): USGS DOQ (Old Style)
DOQ2 -raster- (rov): USGS DOQ (New Style)
GenBin -raster- (rov): Generic Binary (.hdr Labelled)
PAux -raster- (rw+): PCI .aux Labelled
MFF -raster- (rw+v): Vexcel MFF Raster
MFF2 -raster- (rw+): Vexcel MFF2 (HKV) Raster
FujiBAS -raster- (ro): Fuji BAS Scanner Image
GSC -raster- (rov): GSC Geogrid
FAST -raster- (rov): EOSAT FAST Format
BT -raster- (rw+v): VTP .bt (Binary Terrain) 1.3 Format
LAN -raster- (rw+v): Erdas .LAN/.GIS
CPG -raster- (ro): Convair PolGASP
IDA -raster- (rw+v): Image Data and Analysis
NDF -raster- (rov): NLAPS Data Format
EIR -raster- (rov): Erdas Imagine Raw
DIPEx -raster- (rov): DIPEx
LCP -raster- (rwv): FARSITE v.4 Landscape File (.lcp)
GTX -raster- (rw+v): NOAA Vertical Datum .GTX
LOSLAS -raster- (rov): NADCON .los/.las Datum Grid Shift
NTv2 -raster- (rw+vs): NTv2 Datum Grid Shift
CTable2 -raster- (rw+v): CTable2 Datum Grid Shift
ACE2 -raster- (rov): ACE2
SNODAS -raster- (rov): Snow Data Assimilation System
KRO -raster- (rw+v): KOLOR Raw
ROI_PAC -raster- (rw+v): ROI_PAC raster
RRASTER -raster- (rov): R Raster
ENVI -raster- (rw+v): ENVI .hdr Labelled
EHdr -raster- (rw+v): ESRI .hdr Labelled
ISCE -raster- (rw+v): ISCE raster
ARG -raster- (rwv): Azavea Raster Grid format
RIK -raster- (rov): Swedish Grid RIK (.rik)
USGSDEM -raster- (rwv): USGS Optional ASCII DEM (and CDED)
GXF -raster- (ro): GeoSoft Grid Exchange Format
DODS -raster- (ro): DAP 3.x servers
KEA -raster- (rw+): KEA Image Format (.kea)
BAG -raster- (ro): Bathymetry Attributed Grid
HDF5 -raster- (ros): Hierarchical Data Format Release 5
HDF5Image -raster- (ro): HDF5 Dataset
NWT_GRD -raster- (rw+v): Northwood Numeric Grid Format .grd/.tab
NWT_GRC -raster- (rov): Northwood Classified Grid Format .grc/.tab
ADRG -raster- (rw+vs): ARC Digitized Raster Graphics
SRP -raster- (rovs): Standard Raster Product (ASRP/USRP)
BLX -raster- (rwv): Magellan topo (.blx)
PostGISRaster -raster- (rws): PostGIS Raster driver
SAGA -raster- (rw+v): SAGA GIS Binary Grid (.sdat)
XYZ -raster- (rwv): ASCII Gridded XYZ
HF2 -raster- (rwv): HF2/HFZ heightfield raster
OZI -raster- (rov): OziExplorer Image File
CTG -raster- (rov): USGS LULC Composite Theme Grid
E00GRID -raster- (rov): Arc/Info Export E00 GRID
ZMap -raster- (rwv): ZMap Plus Grid
NGSGEOID -raster- (rov): NOAA NGS Geoid Height Grids
IRIS -raster- (rov): IRIS data (.PPI, .CAPPi etc)
PRF -raster- (rov): Racurs PHOTOMOD PRF
GPKG -raster,vector- (rw+vs): GeoPackage
CAD -raster,vector- (rovs): AutoCAD Driver
PLSCENES -raster,vector- (ro): Planet Labs Scenes API
HTTP -raster,vector-
使用命令行工具进行栅格格式转换
GDAL库不但提供了C/C++编程语言的API接口,还提供了很多实用的命令行工具,帮助我们完成一些日常的数据处理工作。
我们以将GeoTIFF格式转为IMAGE格式为例,说明如何使用命令行工具进行栅格格式转换:
gdal_translate -of HFA example.tif example.img
其中,of
选项指示了输出数据格式,HFA
代表的是Erdas Imagine Images ,example.tif
是输入数据路径,example.img
是输出数据路径
详细参数参考:gdal_translate
使用Python代码进行栅格格式转换
下面介绍两种进行转换的方式:
- GDAL 2.1版本之后提供了,从代码中调用命令行的API接口,所以我们可以在Python代码中直接调用
Translate()
函数进行转换
from osgeo import gdal
ds = gdal.Open('example.tif')
ds = gdal.Translate('example.img', ds, format='HFA')
ds = None
Translate()
函数的第一个参数是输出数据路径,第二参数是输入数据路径或者输入数据的Dataset对象,后面都是可选参数,具体Translate()
函数的参数可以参见:GDAL/OGR Python API
- 使用
CreateCopy()
方法进行数据的复制及格式转换
from osgeo import gdal
# 打开数据文件
src_ds = gdal.Open('example.tif')
# 获得数据驱动对象
driver = gdal.GetDriverByName('HFA')
# 进行数据格式转换
dst_ds = driver.CreateCopy('example.img', src_ds)
# 关闭数据集对象
dst_ds = None
src_ds = None