首先,編譯Python版本的GDAL,具體編譯可以參考之前的部落格GDAL之Swig編譯裡面的內容,網址是:http://blog.csdn.net/liminlu0314/article/details/6945452。或者下載別人編譯好的版本。
然後將下載下來的檔案,全部複製到Python的安裝目錄下的 Lib\site-packages檔案夾中,即可,如:
然後,開啟Python,輸入:
import osgeo.gdal
斷行符號,如果提示錯誤,說明沒有安裝成功,如果沒有提示,說明安裝成功。一段測試代碼:
from osgeo import gdalfrom osgeo.gdalconst import *dataset=gdal.Open("F:\Work\Data\envi.img",GA_ReadOnly)dataset.GetDriver().ShortName#'ENVI' #映像格式dataset.GetProjectionRef()#'PROJCS["unnamed",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9108"]],AUTHORITY["EPSG","4269"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",30],PARAMETER["central_meridian",-84.16666666666667],PARAMETER["scale_factor",0.9999],PARAMETER["false_easting",2296587.926509186],PARAMETER["false_northing",0],UNIT["Foot (International)",0.3048]]' #映像投影資訊