阅读:3065回复:5
GDAL库学习笔记GDAL库介绍
|
|
|
1楼#
发布于:2012-10-11 17:15
安装windows下的安装
nmake /f makefile.vc nmake /f makefile.vc install nmake /f makefile.vc devinstall 最后最后,还要去GDAL_HOME目录下的bin文件夹下把gdal13.dll (也有可能是gdal12.dll)copy到PY_INST_DIR路径下
link /dll /def:_gdal.def $(OBJ) ../gdal_i.lib /LIBPATH(PYDIR)/libs /out(PYGDAL_DLL)
if exist $(PYGDAL_DLL).manifest mt -manifest $(PYGDAL_DLL).manifest -outputresource:$(PYGDAL_DLL);2 不加这行,会出现一个“找不到MSVCR80.DLL”的错误,这个错误是由于VS.net2005强制进行manifest验证造成的。而且这个manifest的问题相当棘手,对发布也有极坏的影响。 另外,安装了QGIS,对编译也有一些影响,主要是proj库的冲突,导致一个找不到"d:/program.obj"文件的错误,如果你有静态编译过proj,那么你可以打开nmake.opt修改有关proj的设置,如果搞不定,就卸载QGIS,然后编译,编译后再安装QGIS.呵呵,还好QGIS的体积没有ArcGIS那么可怕. linux下的安装
./configure make su make install ldconfig 就ok(默认就已经支持python)。当然在第一步的时候需要看看是否依赖的库都安装了。如果缺少,就去安装一个。如果对configure的条件不理解,就用./configure --help看看具体情况。 安装其他驱动
从ftp://ftp.ncsa.uiuc.edu/HDF/HDF/HDF%5FCurrent/bin/windows/下载42r1-win.ZIP,解压。
HDF4_DIR = D:\warmerda\42r1-win\release #HDF4_LIB = /LIBPATH:$(HDF4_DIR)\lib hd421m.lib HDF4_LIB = $(HDF4_DIR)\dll\hd421m.lib $(HDF4_DIR)\dll\hm421m.lib . $(HDF4_DIR)\lib\hd421.lib $(HDF4_DIR)\lib\hm421.lib 用HDF4_LIB=/LIBPATH:这种形式似乎可以建立gdal的库,但是往下编译会出错。而且要把$(HDF4_DIR)\dll和$(HDF4_DIR)\lib拷贝到同一个目录下,不然会提示找不到库
然后编译吧!祝你好运。
编译成功后,要HDF4能运行,还需要两个库,一个是zlib,一个是szip,可以到下面两个链接去下载一个 把这两个库下载后解压,然后设置PATH系统变量,使得它们在默认状态下也可以被动态链接成功 。
|
|
|
2楼#
发布于:2012-10-11 17:16
下载
快速开始
>>> import gdal >>> dataset = gdal.Open("j:/gisdata/gtif/spot.tif") >>> dir(dataset) ['AddBand', 'AdviseRead', 'BuildOverviews', 'FlushCache', 'GetDescription', 'Get Driver', 'GetGCPCount', 'GetGCPProjection', 'GetGCPs', 'GetGeoTransform', 'GetMe tadata', 'GetProjection', 'GetProjectionRef', 'GetRasterBand', 'GetSubDatasets', 'RasterCount', 'RasterXSize', 'RasterYSize', 'ReadAsArray', 'ReadRaster', 'Refr eshBandInfo', 'SetDescription', 'SetGCPs', 'SetGeoTransform', 'SetMetadata', 'Se tProjection', 'WriteRaster', '__del__', '__doc__', '__init__', '__module__', '_b and', '_o'] >>>
>>> dataset.GetDescription() 'j:/gisdata/gtif/spot.tif' >>>
>>> dataset.RasterCount 1 >>> band = dataset.GetRasterBand(1) >>>
>>> dataset.RasterXSize 950 >>> dataset.RasterYSize 700 >>> 可以看出我们的图像大小是950*700。还是很小的一张图。
>>> help(dataset.ReadRaster) Help on method ReadRaster in module gdal: ReadRaster(self, xoff, yoff, xsize, ysize, buf_xsize=None, buf_ysize=None, buf_t ype=None, band_list=None) method of gdal.Dataset instance >>> help(dataset.ReadAsArray) Help on method ReadAsArray in module gdal: ReadAsArray(self, xoff=0, yoff=0, xsize=None, ysize=None) method of gdal.Dataset instance >>>
|
|
|
3楼#
发布于:2012-10-11 17:16
>>> dataset.ReadAsArray(230,270,10,10) array([[255, 255, 255, 232, 232, 255, 255, 255, 255, 222], [255, 255, 255, 255, 255, 255, 210, 110, 11, 122], [255, 255, 255, 255, 255, 255, 210, 255, 11, 243], [201, 255, 255, 255, 255, 200, 200, 110, 122, 243], [111, 211, 255, 201, 255, 255, 100, 11, 132, 243], [255, 100, 100, 100, 110, 100, 110, 111, 122, 243], [255, 255, 255, 255, 255, 255, 122, 222, 255, 255], [255, 255, 255, 255, 255, 255, 243, 243, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 255, 255, 255]],'b') >>> dataset.ReadRaster(230,270,10,10) '\xff\xff\xff\xe8\xe8\xff\xff\xff\xff\xde\xff\xff\xff\xff\xff\xff\xd2n\x0bz\xffxff\xff\xff\xff\xff\xd2\xff\x0b\xf3\xc9\xff\xff\xff\xff\xc8\xc8nz\xf3o\xd3\xff\x c9\xff\xffd\x0b\x84\xf3\xffdddndnoz\xf3\xff\xff\xff\xff\xff\xffz\xde\xff\xff\xff \xff\xff\xff\xff\xff\xf3\xf3\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff' >>>
>>> dir(band) ['AdviseRead', 'Checksum', 'ComputeBandStats', 'ComputeRasterMinMax', 'DataType' , 'Fill', 'FlushCache', 'GetDefaultHistogram', 'GetDescription', 'GetHistogram', 'GetMaximum', 'GetMetadata', 'GetMinimum', 'GetNoDataValue', 'GetOffset', 'GetO verview', 'GetOverviewCount', 'GetRasterColorInterpretation', 'GetRasterColorTab le', 'GetScale', 'GetStatistics', 'ReadAsArray', 'ReadRaster', 'SetDefaultHistog ram', 'SetDescription', 'SetMetadata', 'SetNoDataValue', 'SetRasterColorInterpre tation', 'SetRasterColorTable', 'WriteArray', 'WriteRaster', 'XSize', 'YSize', ' __doc__', '__init__', '__module__', '_o'] >>>
>>> band.XSize 950 >>> band.YSize 700 >>> band.DataType 1 >>>
>>> import gdalconst >>> dir(gdalconst) ['CE_Debug', 'CE_Failure', 'CE_Fatal', 'CE_None', 'CE_Warning', 'CPLES_Backslash Quotable', 'CPLES_CSV', 'CPLES_SQL', 'CPLES_URL', 'CPLES_XML', 'CPLE_AppDefined' , 'CPLE_AssertionFailed', 'CPLE_FileIO', 'CPLE_IllegalArg', 'CPLE_NoWriteAccess' , 'CPLE_None', 'CPLE_NotSupported', 'CPLE_OpenFailed', 'CPLE_OutOfMemory', 'CPLE _UserInterrupt', 'CXT_Attribute', 'CXT_Comment', 'CXT_Element', 'CXT_Literal', ' CXT_Text', 'DCAP_CREATE', 'DCAP_CREATECOPY', 'DMD_CREATIONDATATYPES', 'DMD_CREAT IONOPTIONLIST', 'DMD_EXTENSION', 'DMD_HELPTOPIC', 'DMD_LONGNAME', 'DMD_MIMETYPE' , 'GA_ReadOnly', 'GA_Update', 'GCI_AlphaBand', 'GCI_BlackBand', 'GCI_BlueBand', 'GCI_CyanBand', 'GCI_GrayIndex', 'GCI_GreenBand', 'GCI_HueBand', 'GCI_LightnessB and', 'GCI_MagentaBand', 'GCI_PaletteIndex', 'GCI_RedBand', 'GCI_SaturationBand' , 'GCI_Undefined', 'GCI_YellowBand', 'GDT_Byte', 'GDT_CFloat32', 'GDT_CFloat64', 'GDT_CInt16', 'GDT_CInt32', 'GDT_Float32', 'GDT_Float64', 'GDT_Int16', 'GDT_Int 32', 'GDT_TypeCount', 'GDT_UInt16', 'GDT_UInt32', 'GDT_Unknown', 'GF_Read', 'GF_ Write', 'GPI_CMYK', 'GPI_Gray', 'GPI_HLS', 'GPI_RGB', 'GRA_Bilinear', 'GRA_Cubic ', 'GRA_CubicSpline', 'GRA_NearestNeighbour', '__builtins__', '__doc__', '__file __', '__name__'] >>>
>>> band.GetNoDataValue() 65535.0 >>> band.GetMaximum() >>> band.GetMinimum() >>> band.ComputeRasterMinMax() (1.0, 255.0) >>>
|
|
|
4楼#
发布于:2012-10-11 17:17
>>> band.GetRasterColorInterpretation() 2 >>> gdalconst.GCI_PaletteIndex 2 >>> colormap = band.GetRasterColorTable() >>> dir(colormap) ['Clone', 'GetColorEntry', 'GetColorEntryAsRGB', 'GetCount', 'GetPaletteInterpre tation', 'SetColorEntry', '__del__', '__doc__', '__init__', '__module__', '__str __', '_o', 'own_o', 'serialize'] >>> colormap.GetCount() 256 >>> colormap.GetPaletteInterpretation() 1 >>> gdalconst.GPI_RGB 1 >>> for i in range(colormap.GetCount()): ... print colormap.GetColorEntry(i), ... (0, 0, 0, 255) (0, 0, 28, 255) (0, 0, 56, 255) (0, 0, 85, 255) (0, 0, 113, 255) (0, 0, 142, 255) (0, 0, 170, 255) (0, 0, 199, 255) (0, 0, 227, 255) (0, 0, 255, 255) (0, 28, 0, 255) (0, 28, 28, 255) (0, 28, 56, 255) (0, 28, 85, 255) (0, 28, 113, 255) (0, 28, 142, 255) (0, 28, 170, 255) (0, 28, 199, 255) (0, 28, 227, 255 ) (0, 28, 255, 255) (0, 56, 0, 255) (0, 56, 28, 255) (0, 56, 56, 255) (0, 56, 85 , 255) (0, 56, 113, 255) (0, 56, 142, 255) (0, 56, 170, 255) (0, 56, 199, 255) ( 0, 56, 227, 255) (0, 56, 255, 255) (0, 85, 0, 255) (0, 85, 28, 255) (0, 85, 56, 255) (0, 85, 85, 255) (0, 85, 113, 255) (0, 85, 142, 255) (0, 85, 170, 255) (0, 85, 199, 255) (0, 85, 227, 255) (0, 85, 255, 255) (0, 113, 0, 255) (0, 113, 28, 255) (0, 113, 56, 255) (0, 113, 85, 255) (0, 113, 113, 255) (0, 113, 142, 255) ( 0, 113, 170, 255) (0, 113, 199, 255) (0, 113, 227, 255) (0, 113, 255, 255) (0, 1 42, 0, 255) (0, 142, 28, 255) (0, 142, 56, 255) (0, 142, 85, 255) (0, 142, 113, 255) (0, 142, 142, 255) (0, 142, 170, 255) (0, 142, 199, 255) (0, 142, 227, 255) (0, 142, 255, 255) (0, 170, 0, 255) (0, 170, 28, 255) (0, 170, 56, 255) (0, 170 , 85, 255) (0, 170, 113, 255) (0, 170, 142, 255) (0, 170, 170, 255) (0, 170, 199 , 255) (0, 170, 227, 255) (0, 170, 255, 255) (0, 199, 0, 255) (0, 199, 28, 255) (0, 199, 56, 255) (0, 199, 85, 255) (0, 199, 113, 255) (0, 199, 142, 255) (0, 19 9, 170, 255) (0, 199, 199, 255) (0, 199, 227, 255) (0, 199, 255, 255) (0, 227, 0 , 255) (0, 227, 28, 255) (0, 227, 56, 255) (0, 227, 85, 255) (0, 227, 113, 255) (0, 227, 142, 255) (0, 227, 170, 255) (0, 227, 199, 255) (0, 227, 227, 255) (0, 227, 255, 255) (0, 255, 0, 255) (0, 255, 28, 255) (0, 255, 56, 255) (0, 255, 85, 255) (0, 255, 113, 255) (0, 255, 142, 255) (0, 255, 170, 255) (0, 255, 199, 255 ) (0, 255, 227, 255) (0, 255, 255, 255) (28, 0, 0, 255) (28, 0, 28, 255) (28, 0, 56, 255) (28, 0, 85, 255) (28, 0, 113, 255) (28, 0, 142, 255) (28, 0, 170, 255) (28, 0, 199, 255) (28, 0, 227, 255) (28, 0, 255, 255) (28, 28, 0, 255) (28, 28, 28, 255) (28, 28, 56, 255) (28, 28, 85, 255) (28, 28, 113, 255) (28, 28, 142, 2 55) (28, 28, 170, 255) (28, 28, 199, 255) (28, 28, 227, 255) (28, 28, 255, 255) (28, 56, 0, 255) (28, 56, 28, 255) (28, 56, 56, 255) (28, 56, 85, 255) (28, 56, 113, 255) (28, 56, 142, 255) (28, 56, 170, 255) (28, 56, 199, 255) (28, 56, 227, 255) (28, 56, 255, 255) (28, 85, 0, 255) (28, 85, 28, 255) (28, 85, 56, 255) (2 8, 85, 85, 255) (28, 85, 113, 255) (28, 85, 142, 255) (28, 85, 170, 255) (28, 85 , 199, 255) (28, 85, 227, 255) (28, 85, 255, 255) (28, 113, 0, 255) (28, 113, 28 , 255) (28, 113, 56, 255) (28, 113, 85, 255) (28, 113, 113, 255) (28, 113, 142, 255) (28, 113, 170, 255) (28, 113, 199, 255) (28, 113, 227, 255) (28, 113, 255, 255) (28, 142, 0, 255) (28, 142, 28, 255) (28, 142, 56, 255) (28, 142, 85, 255) (28, 142, 113, 255) (28, 142, 142, 255) (28, 142, 170, 255) (28, 142, 199, 255) (28, 142, 227, 255) (28, 142, 255, 255) (28, 170, 0, 255) (28, 170, 28, 255) (28 , 170, 56, 255) (28, 170, 85, 255) (28, 170, 113, 255) (28, 170, 142, 255) (28, 170, 170, 255) (28, 170, 199, 255) (28, 170, 227, 255) (28, 170, 255, 255) (28, 199, 0, 255) (28, 199, 28, 255) (28, 199, 56, 255) (28, 199, 85, 255) (28, 199, 113, 255) (28, 199, 142, 255) (28, 199, 170, 255) (28, 199, 199, 255) (28, 199, 227, 255) (28, 199, 255, 255) (28, 227, 0, 255) (28, 227, 28, 255) (28, 227, 56, 255) (28, 227, 85, 255) (28, 227, 113, 255) (28, 227, 142, 255) (28, 227, 170, 255) (28, 227, 199, 255) (28, 227, 227, 255) (28, 227, 255, 255) (28, 255, 0, 25 5) (28, 255, 28, 255) (28, 255, 56, 255) (28, 255, 85, 255) (28, 255, 113, 255) (28, 255, 142, 255) (28, 255, 170, 255) (28, 255, 199, 255) (28, 255, 227, 255) (28, 255, 255, 255) (56, 0, 0, 255) (56, 0, 28, 255) (56, 0, 56, 255) (56, 0, 85 , 255) (56, 0, 113, 255) (56, 0, 142, 255) (56, 0, 170, 255) (56, 0, 199, 255) ( 56, 0, 227, 255) (56, 0, 255, 255) (56, 28, 0, 255) (56, 28, 28, 255) (56, 28, 5 6, 255) (56, 28, 85, 255) (56, 28, 113, 255) (56, 28, 142, 255) (56, 28, 170, 25 5) (56, 28, 199, 255) (56, 28, 227, 255) (56, 28, 255, 255) (56, 56, 0, 255) (56 , 56, 28, 255) (56, 56, 56, 255) (56, 56, 85, 255) (56, 56, 113, 255) (56, 56, 1 42, 255) (56, 56, 170, 255) (56, 56, 199, 255) (56, 56, 227, 255) (56, 56, 255, 255) (56, 85, 0, 255) (56, 85, 28, 255) (56, 85, 56, 255) (56, 85, 85, 255) (56, 85, 113, 255) (56, 85, 142, 255) (56, 85, 170, 255) (56, 85, 199, 255) (56, 85, 227, 255) (56, 85, 255, 255) (56, 113, 0, 255) (56, 113, 28, 255) (56, 113, 56, 255) (56, 113, 85, 255) (56, 113, 113, 255) (56, 113, 142, 255) (56, 113, 170, 255) (56, 113, 199, 255) (56, 113, 227, 255) (56, 113, 255, 255) (56, 142, 0, 25 5) (56, 142, 28, 255) (56, 142, 56, 255) (56, 142, 85, 255) (56, 142, 113, 255) (56, 142, 142, 255) >>>
|
|
|
5楼#
发布于:2012-10-11 17:17
>>> help(band.ReadAsArray) Help on method ReadAsArray in module gdal: ReadAsArray(self, xoff=0, yoff=0, win_xsize=None, win_ysize=None, buf_xsize=None , buf_ysize=None, buf_obj=None) method of gdal.Band instance >>> help(band.ReadRaster) Help on method ReadRaster in module gdal: ReadRaster(self, xoff, yoff, xsize, ysize, buf_xsize=None, buf_ysize=None, buf_t ype=None) method of gdal.Band instance >>>
|
|
|