鱼翅就虾米,python和ArcGIS VBA的交互编程
丽元问我python和ArcGIS VBA交互编程的感想,想了半天,也许将两个编程语言进行结合,真的就像是吃着鱼翅,就着虾米的感觉。很多人都觉得VBA很强大,我也这么料想,当然大家也可以google一下ArcGIS VBA,很多人留下了为啥Office的VBA能做那么好,而ArcGIS的VBA就做那么差强人意。。。有很多必要的功能,ArcGIS都是给隐藏了。如果要使用,需要定义新的module去declare,比如说最常用的openfiledialog,当我想当然的认为VBA会有相关的函数的时候,没相当这些都只好去declare “comdlg32.dll”。
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _ "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
当然了,尊尊就会反诘我说,“千万别把虾米不当海鲜”。话虽这么说,但确实这虾米当海鲜的事情总让人尴尬,比如说,记得去年4月份的时候去小粉桥一家馆子点了份干贝XXX汤,后来汤里根本没有干贝,惹得我最后和老板大动干戈,厨子提着菜刀和我解释,我二话没说,就掀起了桌子,这也是我下馆子最为彪悍的一次。
再说说正题,我做python和ArcGIS VBA交互主要是用 VBA 提供的Shell。同时把参数传递给需要调用的python函数。python获得了参数以后,就会进行处理,并且产生结果,但是这些结果是以临时文件保存在硬盘里的,需要捕获线程的id,在等待线程结束后,再调用结果。
Declare Function OpenProcess Lib "kernel32" _ (ByVal dwDesiredAccess As Long, _ ByVal bInheritHandle As Long, _ ByVal dwProcessId As Long) As Long Declare Function GetExitCodeProcess Lib "kernel32" _ (ByVal hProcess As Long, _ lpExitCode As Long) As Long Public Const Process_Query_Information = &H400 Public Const Still_Active = 259 taskId = Shell("dist/main -n " & Str(num + 1), vbNormalFocus) hProcess = OpenProcess(Process_Query_Information, False, taskId) Do GetExitCodeProcess hProcess, lngexitcode DoEvents Loop While lngexitcode = Still_Active
而在python中,关键是要能接受参数。
import optparse #options parser parser = optparse.OptionParser(usage= '%ca' ) parser.set_defaults(buffer = 100, verbose = False) parser.add_option('-n', '--number', dest = 'number', help = 'input numbers of the forcecasting year') (options, args) = parser.parse_args()
Related posts:
About this entry
You’re currently reading “鱼翅就虾米,python和ArcGIS VBA的交互编程,” an entry on Geoinformatics
- Published:
- 4.18.09 / 10下午
- Tags:
- Visual Basic
Ajax ArcGIS Dreams Flex Geography Geoinformatics GeoRSS GIS Google Hardware Harvard History Jquery Linux Love Map MapServer NASA OGC OpenGIS OSGeo PHP Politics PostGIS PostgreSQL Python R Social Network SVG Ubuntu Web WebGIS Wordpress 中国 历史地理 宋朝 开源 新儒学 生活 遥感
WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.














赵 博 (Bo Zhao),
参与或主持的项目
No comments
Jump to comment form | comments rss [?] | trackback uri [?]