因此,我一直致力於通過Python將地理空間建模環境工具(以前稱爲Hawth's)與ArcGIS 10.1集成。下面是我使用的代碼,這很好用,可以創建一個代碼文本文件,然後通過Python調用GME來處理我正在使用的shape文件。至於我可以告訴大家,我已經能夠逐字模仿什麼的創造者國家將在Python工作(看他的文件位置:http://www.spatialecology.com/gme/images/SpatialEcologyGME.pdf)通過Python整合Hawth's Tools和ArcGIS 10.1是否成功?
代碼:
import arcpy, sys, os, subprocess
from arcpy import env
#Supply the following arguments:
#Workspace (full path)
#Catchment Polygons (full path)
#Raster Data (full path)
#Prefix for the output: 6 characters to denote the raster dataset.
#Thematic value: TRUE or FALSE
#An output txt file (full path -> eg. C:/Users/Alison/Desktop/file.txt)
########
#Each argument must be in double quotes, and they must be separated by a space.
#The polygon and raster datasets must be in same coordinate system.
env.workspace = sys.argv[1]
print env.workspace
inputPoly = sys.argv[2]
inputRast = sys.argv[3]
prefix = sys.argv[4]
thematic = sys.argv[5]
code = 'isectpolyrst(in="' + inputPoly + '", raster="' + inputRast + '", prefix="' + prefix + '", thematic="' + thematic +'");'
print code
newFile = sys.argv[6]
print newFile
newFileObj = open(newFile, 'w')
newFileObj.write(code)
newFileObj.close()
print newFile
os.system(r'C:\Program Files (x86)\SpatialEcology\GME\SEGME.exe')
print "subprocess.call(r'C:\Program Files (x86)\SpatialEcology\GME\SEGME.exe -c run(in=\\\"" + newFile + "\\\");');"
subprocess.call(r'C:\Program Files (x86)\SpatialEcology\GME\SEGME.exe -c run(in=\\\"" + newFile + "\\\");');
然而,在這個過程中正常工作,我只是最終撞上了另一堵牆......它打開了GME,但唉,它實際上並沒有做任何事情。它最終似乎並沒有運行創建的文本文件。 isectpolyrst工具的工作方式類似Tabulate Area,因此理論上所有的值都應該附加到多邊形數據中,但是通過Python它似乎沒有這樣做......(並且我使用GME,因爲Tabulate Area不能處理我的數據文件的大小和崩潰都在Arc中,但也作爲Python腳本)。
我想知道是否有人能成功地通過Python運行GME,以便在ArcPy腳本中使用,這樣任務就可以自動完成,而不必經過GME然後進入Arc。我的搜索暗示這對於那些試圖自動化這個過程的人來說是一個普遍的問題,但是我知道我只是在某處丟失了一個冒號,或者其他一些代碼。
感謝您的反饋!