从上面的信息,我们可以看到这个GeoTIFF用的投影坐标系(Projected Coordinate Systems, PROJCS)是Albers_NAD83_L48,地理坐标系(Geographic Coordinate Systems, GEOGCS)是NAD83,通过查询https://epsg.io/5070 大概可以判断,这个坐标系适用于“Data analysis and small scale data presentation for contiguous lower 48 states”。
1 2 3 4 5 6
ustif.RasterCount band = ustif.GetRasterBand(1) one = ustif.GetRasterBand(1).ReadAsArray() two = ustif.GetRasterBand(2).ReadAsArray() three= ustif.GetRasterBand(3).ReadAsArray() print(str(one[0,0])+","+ str(two[0,0])+","+str(three[0,0]))
print(band.ComputeBandStats()) # get the minimum and maximum values from a band print(str(band.GetMinimum())+","+str(band.GetMaximum())) # band description print(band.GetDescription())
(138.5485612393038, 49.797830115235854)
0.0,248.0
当然了,要想最为直观地了解栅格数据,肯定是把它显示出来。我们可以用以下方法:
1 2 3 4 5 6 7
import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl
# create a numpy array with 60 rows of 80 columns x = np.linspace(0.01, 100, 4800) a_raster = (np.sin(x)+1) * 255 / 2 a_raster = a_raster.reshape(60,80)
# set the lower-left corner coord = (116.4074, 39.9042) # Lon and lat of Beijing # width and heigh w = 0.1 h = 0.1 name = 'newpk.tif'
# combine the data and properties d = gdal.GetDriverByName('GTiff') output=d.Create(name,a_raster.shape[1],a_raster.shape[0],1,gdal.GDT_UInt16) output.SetGeoTransform((coord[0],w,0,coord[1],0,h)) output.GetRasterBand(1).WriteArray(a_raster) outsr=osr.SpatialReference() outsr.ImportFromEPSG(4326) # WGS 84 output.SetProjection(outsr.ExportToWkt()) output.FlushCache()
# summarize the occurences of every value in the raster cursor.execute('select ST_ValueCount(rast, 1) from newpk;') result = cursor.fetchall() result[:5]
# the number of times a single value occurs cursor.execute('select ST_ValueCount(rast,1,True,129) from newpk;') cursor.fetchall()
[(11,)]
1 2 3 4
# return all the values in the raster data cursor.execute('select ST_DumpValues(rast,1) from newpk') result = cursor.fetchall() result[0][0][0][0]
129.0
1 2 3 4
# get the closet piexel value to taht point cursor.execute('select ST_NearestValue(rast, (select ST_SetSRID(' 'ST_MakePoint(118, 40), 4326))) from newpk;') cursor.fetchall()