Python实现多线程调用GDAL执行正射校正

摘要:
python实现多线程参考http://www.runoob.com/python/python-multithreading.html#!/usr/bin/envpython#coding:utf-8##Description:###Author:LC#Date:#try:fromosgeoimportgdalexceptImportError:importgdalimportQueueimpo

python实现多线程参考http://www.runoob.com/python/python-multithreading.html

#!/usr/bin/env python#coding:utf-8#
#Description:#
#
#Author: LC#Date: #
try:
    from osgeo importgdal
exceptImportError:
    importgdal

importQueue
importthreading
importtime
importos
importosr
importtarfile
importmath


exitFlag =0


# 自定义多线程类
classmyThread(threading.Thread): def __init__(self, threadID, name, queueLock, workQueue, outputdir, demfile): threading.Thread.__init__(self) self.threadID =threadID self.name =name self.queueLock =queueLock self.workQueue =workQueue self.outputdir =outputdir self.demfile =demfile defrun(self): print "Starting " +self.name GF4_Ortho(self.name, self.queueLock, self.workQueue, self.outputdir, self.demfile) print "Exiting " +self.name defGF4_Ortho(threadName, queueLock, workQueue, outputdir, demfile): while notexitFlag: queueLock.acquire() if notworkQueue.empty(): untarfile =workQueue.get() queueLock.release() print "%s processing %s" %(threadName, untarfile) #解压 t =tarfile.open(untarfile) outdir_ = outputdir + os.path.sep + ((os.path.basename(untarfile)).split(".tar"))[0] t.extractall(path =outdir_) #计算UTM区号 filename = ((os.path.basename(untarfile)).split('.tar'))[0] lon = float(((filename.split('_'))[2])[1:]) zone_ = int(math.ceil(lon / 6)) + 30zone = int("326" +str(zone_)) printzone #正射校正 filename_ = filename.split('_') filename_[1] = 'PMS'infile = outdir_ + os.path.sep + '_'.join(filename_) + '.tiff'outfile = outdir_ + os.path.sep + '_'.join(filename_) + '_Ortho.tiff' ifos.path.exists(infile): dataset =gdal.Open(infile) dstSRS =osr.SpatialReference() dstSRS.ImportFromEPSG(zone) ret = gdal.Warp(outfile, dataset, format="Gtiff", xRes=50, yRes=50, dstSRS=dstSRS, rpc=True, transformerOptions=demfile) delt, infile, outfile, dataset, ret else: queueLock.release() time.sleep(1) defmain(inputdir, outputdir, demfile, thread_number): #查找待处理压缩文件 names =os.listdir(inputdir) filenames =[] for name_ innames: filenames.append(inputdir + os.path.sep +name_) num =len(filenames) threadList =[] for i inrange(thread_number): threadList.append("Thread-" +str(i)) queueLock =threading.Lock() workQueue =Queue.Queue(num) threads =[] threadID = 1 #创建新线程 for tName inthreadList: thread =myThread(threadID, tName, queueLock, workQueue, outputdir, demfile) thread.start() threads.append(thread) threadID += 1 #填充队列 queueLock.acquire() for name infilenames: workQueue.put(name) queueLock.release() #等待队列清空 while notworkQueue.empty(): pass #通知线程是时候退出 exitFlag = 1 #等待所有线程完成 for t inthreads: t.join() print "Exiting Main Thread" if __name__ == "__main__": indir = "H:\GF-4\2016-05-22\"outdir = "G:\Temp\GF-4\"demfile = "C:\Program Files\Exelis\ENVI53data\GMTED2010.jp2"thread_num = 6 starttime =time.ctime() main(indir, outdir, demfile, thread_num) endtime =time.ctime() print "Start time:", starttime print "End time:", endtime

免责声明:文章转载自《Python实现多线程调用GDAL执行正射校正》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇利用select/poll监听多个设备详解【推荐】CentOS安装PHP5.6.4+扩展安装+安全配置+性能配置下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

django程序在windows服务器上发布

django程序在windows服务器上发布 参考文献:https://www.cnblogs.com/djangocn/p/10227006.html 1.安装 IIS 和 GCI 打开服务器管理器,选择添加角色和功能,选择要添加的服务器角色(WEB服务器IIS),然后安装 IIS安装成功之后,然后安装CGI,再次选择添加角色和功能,找到之前安装的...

笔试题多线程

1. 描述线程与进程的区别? 一个应用程序实例是一个进程,一个进程内包含一个或多个线程,线程是进程的一部分; 进程之间是相互独立的,他们有各自的私有内存空间和资源,进程内的线程可以共享其所属进程的所有资源; 2. 为什么GUI不支持跨线程访问控件?一般如何解决这个问题? 因为GUI应用程序引入了一个特殊的线程处理模型,为了保证UI控件的线程安全,这个线...

Python开发利器WingIDE破解方法

“工欲善其事,必先利其器。”刚开始接触Python的人大都用自带的LDLE,尽管它对于初学该语言非常有帮助,但许多开发人员更喜欢其它文本编辑器或集成开发环境。(IDEs)在此我不想展开阐述,Python 社区维护了一份Python 相关编辑器的清单, 涵盖了各种各样支持平台和软件许可协议。但是所给出的编辑器个人认为都不是很理想,一直想找一个类似于php的Z...

python之 paramiko模块 连接服务器

paramiko是一个基于SSH用于连接远程服务器并执行相关操作(SSHClient和SFTPClinet,即一个是远程连接,一个是上传下载服务),使用该模块可以对远程服务器进行命令或文件操作。 下载安装 pycrypto,由于 paramiko 模块内部依赖pycrypto,所以先下载安装pycrypto pip3 install pycrypto pi...

多线程之线程同步

Pulse(lockObj)表示释放当前被lock的lockObj,容许其它线程调用。(相当于临时挂起当前线程) Wait(lockObj)表示等待当前被其它线程占用的lockObj。 以下的代码将会交替运行两个线程: class TickTock { object lockOn = new object();...

android 录制

引用:http://www.jtben.com/document/919575 出自ATHZ-SEC1-WIKI   跳转到: 导航, 搜索 Android 事件录制脚本的生成 Software R&D Center-SW R&D Dept.-Sec.1HZSWTL2011008Prepared by: Andy3 LiuJan. 2...