[GDAL] Install GDAL on Windows and HDF4 support

1.下载gdal 2.1.0
http://download.osgeo.org/gdal/2.1.0/gdal210.zip

2.下载第三方支持包并解压
hdf4:
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64/hdf4-4.2.11-0.tar.bz2
proj.4:
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64/proj.4-4.9.1-0.tar.bz2
geos:
http://download.osgeo.org/geos/geos-3.6.1.tar.bz2

(编译geos)
双击E:\geos-3.6.1\autogen.bat
打开VS build tool x64,(下载http://landinghub.visualstudio.com/visual-cpp-build-tools)
cd E:\geos-3.6.1
e:
nmake /f makefile.vc

3.修改gdal配置E:\gdal-2.1.0\nmake.opt
1)修改vs版本号
!IFNDEF MSVC_VER
#assume msvc VS2008.
MSVC_VER=1900
!ENDIF

2)修改HDF4路径
# Uncomment the following and update to enable NCSA HDF Release 4 support.
HDF4_PLUGIN = NO
HDF4_DIR = E:\hdf4-4.2.11-0\Library
HDF4_LIB = $(HDF4_DIR)\lib\hdf.lib $(HDF4_DIR)\lib\mfhdf.lib

3)修改PROJ.4路径
# PROJ.4 stuff
# Uncomment the following lines to link PROJ.4 library statically. Otherwise
# it will be linked dynamically during runtime.
#PROJ_FLAGS = -DPROJ_STATIC
PROJ_INCLUDE = -IE:\proj.4-4.9.1-0\Library\lib
lPROJ_LIBRARY = E:\proj.4-4.9.1-0\Library\lib\proj_i.lib

(修改geos路径)
# Uncomment for GEOS support (GEOS >= 3.1.0 required)
GEOS_DIR=E:\geos-3.6.1
GEOS_CFLAGS = -I$(GEOS_DIR)\capi -I$(GEOS_DIR)\source\headers -DHAVE_GEOS
GEOS_LIB = $(GEOS_DIR)\src\geos_c_i.lib

4.编译gdal
1)打开VS build tool x64,
cd E:\gdal-2.1.0
e:
nmake /f makefile.vc
nmake /f makefile.vc install

2)拷贝E:\hdf4-4.2.11-0\Library\bin和E:\proj.4-4.9.1-0\Library\bin下文件到C:\warmerda\bld\bin下

5.使用gdal
cd C:\warmerda\bld\bin
c:
gdalinfo –version
gdalinfo [filename]

6.转坐标
1)转地理坐标使用EPSG表:
set GDAL_DATA=C:\warmerda\bld\data
gdalwarp -geoloc -t_srs EPSG:4326 HDF4_EOS:EOS_SWATH:”e:\MOD04_3K.A2016001.0150.006.2016008004050.hdf”:mod04:Optical_Depth_Land_And_Ocean e:\test2.tif
2)转投影坐标使用PROJ.4参数
e.g.中国区转为兰伯特等角投影
gdalwarp -t_srs ‘+proj=lcc +lat_1=25.00 +lat_2=47.00 +lat_0=34.533333 +lon_0=108.916667 +x_0=0 +y_0=0 +a=6378137.0 +b=6356752.3 +ellps=WGS84 +datum=WGS84 +units=m +no_defs’ -overwrite e:\test2.tif e:\test3.tif

**针对MODIS影像,先转地理坐标,后转投影
**投影查询http://spatialreference.org/,可查EPSG和proj4参数

1 thought on “[GDAL] Install GDAL on Windows and HDF4 support

  1. I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it for you? Plz reply as I’m looking to construct my own blog and would like to know where u got this from. appreciate it

Leave a Reply

Your email address will not be published. Required fields are marked *