GDAL 支持大量的栅格和矢量格式,但是一般情况下,大部分格式都是我们使用不到的。在 Linux 下编译 GDAL 时,可以使用以下命令进行裁剪:
./configure --prefix=/usr/local \ --with-threads \ --with-ogr \ --with-geos \ --without-libtool \ --with-libz=internal \ --with-libtiff=internal \ --with-geotiff=internal \ --without-gif \ --without-pg \ --without-grass \ --without-libgrass \ --without-cfitsio \ --without-pcraster \ --without-netcdf \ --without-png \ --without-jpeg \ --without-gif \ --without-ogdi \ --without-fme \ --without-hdf4 \ --without-hdf5 \ --without-jasper \ --without-ecw \ --without-kakadu \ --without-mrsid \ --without-jp2mrsid \ --without-bsb \ --without-grib \ --without-mysql \ --without-ingres \ --without-xerces \ --without-expat \ --without-odbc \ --without-curl \ --without-sqlite3 \ --without-dwgdirect \ --without-panorama \ --without-idb \ --without-sde \ --without-perl \ --without-php \ --without-ruby \ --without-python \ --without-ogpython \ --with-hide-internal-symbols
在 Windows 下使用 VS2010 编译时,在不改动源代码的情况下,需要裁剪的话就得编译相应的 Makefile.vc 和 nmake.opt。
1. nmake.opt
注释以下部分:
#BSB_SUPPORTED = 1
#ODBC_SUPPORTED = 1
2. /frmts/Makefile.vc
注释掉 EXTRAFLAGS = -DFRMT_xxx 一整段,只保留以下几个模块(如果下把这几个模块都去掉,就得修改 .h 和 .cpp 文件中的许多地方):
EXTRAFLAGS = -DFRMT_sdts -DFRMT_pcidsk -DFRMT_gtiff -DFRMT_hfa -DFRMT_raw -DFRMT_vrt -DFRMT_pds
3. /ogr/ogrsf_frmts/Makefile.vc
注释掉 DIRLIST = xxx 一整段 ,只保留(可以连shape都不保留,那样的话,干脆直接修改 nmake.opt 中的 INCLUDE_OGR_FRMTS = YES):
DIRLIST = shape
最后 nmake /f makefile.vc 就可以生成最小化的 GDAL/OGR 库了。