Python装包 --笔记
一、Pyhton安装
1、python的依赖包位置
E:\Python\Lib\site-packages
2、pycharm装包
#每个项目会有自己的依赖包,新建项目后,扩展里面搜索就行
#装包有问题的,可以尝试自行下载这个包,然后将这个包存放到在对应项目下的依赖包所在位置
项目文件夹 》 venv 》 lib 》 site-packages 》 粘贴位置
3、使用demo
__author__ = 'SmallTiger'
from osgeo import gdal
def createEmptyTif(source,outFile):
dataSource = gdal.Open(source)
band = dataSource.GetRasterBand(1)
in_data = band.ReadAsArray(0, 0, dataSource.RasterXSize, dataSource.RasterYSize)
for i in range(len(in_data)):
for j in range(len(in_data[0])):
in_data[i][j] = 0
gtiffDriver = gdal.GetDriverByName('GTiff')
outPutImage = gtiffDriver.Create(outFile, \
band.XSize, band.YSize, 1, band.DataType)
outPutImage.SetProjection(dataSource.GetProjection())
outPutImage.SetGeoTransform(dataSource.GetGeoTransform())
outPutImage.GetRasterBand(1).WriteArray(in_data)
def retuArr(source):
dataSource = gdal.Open(source)
band = dataSource.GetRasterBand(1)
bandArray = band.ReadAsArray()
return bandArray
def calculate(source):
res1 = retuArr(sourPath + sourceName[0])
res2 = retuArr(sourPath + sourceName[1])
res3 = retuArr(sourPath + sourceName[2])
res4 = retuArr(sourPath + sourceName[3])
res5 = retuArr(sourPath + sourceName[4])
res6 = retuArr(sourPath + sourceName[5])
res7 = retuArr(sourPath + sourceName[6])
res8 = retuArr(sourPath + tempTif)
resArr = res1 + res2 + res3 + res4 + res5 + res6 + res7 + res8
dataSource = gdal.Open(source)
band = dataSource.GetRasterBand(1)
gtiffDriver = gdal.GetDriverByName('GTiff')
outPutImage = gtiffDriver.Create(sourPath + resTif, \
band.XSize, band.YSize, 1, band.DataType)
outPutImage.SetProjection(dataSource.GetProjection())
outPutImage.SetGeoTransform(dataSource.GetGeoTransform())
outPutImage.GetRasterBand(1).WriteArray(resArr)
if __name__ == "__main__":
sourPath = 'E:/ArcpyGIS/seconeTerm/result/source/'
sourceName = ['reclass_school1.tif','reclass_school2.tif','reclass_school3.tif',\
'reclass_school4.tif','reclass_enter1.tif','reclass_enter2.tif',\
'reclass_enter3.tif']
tempTif = 'temp.tif'
resTif = 'result.tif'
calculate(sourPath + sourceName[6])