Original link: Python GDAL installation and simple to use
gdal Installation
way: in the URL https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal download whl file corresponds to the version of python, pip install whl the full path to the installation file (windows mode) on the command line.
Second way:
command line conda / pip search gdal view the version, select the appropriate version (my 2.2.4), if not, use a.
Command line conda / pip install gdal = version, plus note the version number, or may be installed on older versions (windows / linux are available).
Other: centos compile, configure gdal
Test
gdal for treating raster data packet, ogr vector data for processing.
The following program is a simple application process gdal grid.
. 1 from OSGeo Import GDAL 2 Import numpy AS NP . 3 np.set_printoptions (threshold = np.inf) # so that a large number of print data is not displayed in place of all the symbol ... . 4 . 5 DataSet gdal.Open = ( " E: / RS_data / caijian1214 /caijian.tif " ) . 6 . 7 Print (dataset.GetDescription ()) # data description . 8 . 9 Print (dataset.RasterCount) # number of bands 10 . 11 cols = dataset.RasterXSize # image length 12 is rows = (dataset.RasterYSize) # image width 13 14 xoffset = cols / 2 15 yoffset rows = / 2 16 . 17 Band dataset.GetRasterBand = (. 3) # take the third band 18 is R & lt band.ReadAsArray = (xoffset, yoffset, 1000,1000) # from the center position data , 1000 1000 rows of data taken . 19 20 is Band = dataset.GetRasterBand (2 ) 21 is G = band.ReadAsArray (xoffset, yoffset, 1000,1000 ) 22 is 23 is Band dataset.GetRasterBand = (. 1 ) 24 B = band.ReadAsArray (xoffset , yoffset, 1000,1000 ) 25 26 is Import CV2 27 Import matplotlib.pyplot PLT AS 28 29 30 IMG2 = cv2.merge ([R & lt, G, B]) 31 is plt.imshow (IMG2) 32 plt.xticks ([]), plt.yticks ([]) # does not display the coordinate axis 33 is plt.show ()