我一直在網上淘試圖找到一個Python的(SP?)的方式來處理這些數據..如何使用Python把一個.dbf成shape文件
我們每天都將收到數據的加載以.dbf格式(希望) - 然後我們需要將這些數據保存爲shape文件。
有沒有人有任何關於我的過程的鏈接或任何建議?
我一直在網上淘試圖找到一個Python的(SP?)的方式來處理這些數據..如何使用Python把一個.dbf成shape文件
我們每天都將收到數據的加載以.dbf格式(希望) - 然後我們需要將這些數據保存爲shape文件。
有沒有人有任何關於我的過程的鏈接或任何建議?
它一直在模型生成器!
# (generated by ArcGIS/ModelBuilder)
# Usage: DBF2SHAPEFILE <XY_Table> <Y_Field> <X_Field> <Output_Feature_Class>
# ---------------------------------------------------------------------------
# Import system modules
import sys, string, os, arcgisscripting, datetime
# Adds the creation date to all of the previous shapefiles in that folder
filename = 'D:/test.txt'
fileinfo = os.stat(filename)
creation_date = datetime.date.fromtimestamp(fileinfo.st_ctime)
os.rename(filename, filename + '-' + creation_date.strftime('%Y-%m-%d'))
# Create the Geoprocessor object
gp = arcgisscripting.create()
# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
# Script arguments...
XY_Table = sys.argv[1]
Y_Field = sys.argv[2]
X_Field = sys.argv[3]
Output_Feature_Class = sys.argv[4]
# Local variables...
Layer_Name_or_Table_View = ""
# Process: Make XY Event Layer...
gp.MakeXYEventLayer_management(XY_Table, X_Field, Y_Field, Layer_Name_or_Table_View, "")
# Process: Copy Features...
gp.CopyFeatures_management(Layer_Name_or_Table_View, Output_Feature_Class, "", "0", "0", "0")
關閉我的頭頂:
import os
import datetime
myfile = "test.txt"
creationdate = os.stat(myfile).st_ctime
timestamp = datetime.datetime.fromtimestamp(creationdate)
datestr = datetime.datetime.strftime(timestamp, "%Y%m%d")
os.rename(myfile, os.path.splitext(myfile)[0] + datestr + os.path.splitext(myfile)[1])
重命名test.txt
到test20110221.txt
。
要將文件的creation_date追加到名稱,需要使用os.stat()獲取創建日期,然後使用os.rename()重命名該文件。您可以使用date.strftime()格式化日期字符串。
import datetime, os
filename = 'original.ext'
fileinfo = os.stat(filename)
creation_date = datetime.date.fromtimestamp(fileinfo.st_ctime)
os.rename(filename, filename + '-' + creation_date.strftime('%Y-%m-%d'))
如果你想做到這一點,而不使用ArcGIS中,你可以使用OGR的Python綁定或ogr2ogr utility通過一個子進程。你可以通過一個windows批處理文件來使用該實用程序,如果你有很多事情要比每個文件都要調用arc進程要快得多...
如你所知,這不是改變擴展的問題,有一個特定的格式要求。
不知道這是否準確,但:「發佈的地圖不包含實際的地理數據,而是鏈接到中央遠程位置的數據集,這些位置可能由ArcMap服務器託管或通過Internet提供。」 (http://www.fileinfo.com/extension/pmf)所以它可能不是您實際需要更新的pmf文件。 – 2011-02-18 12:46:56
太托馬斯!感謝您指出這一點! – 2011-02-21 07:31:44
我已經編輯了我的帖子,現在是我的定義問題! – 2011-02-21 09:03:43