2016-05-19 12 views
0

ArcGISシェイプファイルに結合したいテーブルがあります。私の問題は、テーブルに2つのIDフィールド(「プラン番号」と「契約番号」)があり、シェイプファイルに1つのIDフィールド(「名前」)があることです。私はシェープファイルの "名前"を "計画番号"または "契約番号"に結合したいと思います。dbfテーブルの2つのフィールドの1つをArcGISシェイプファイルフィールドに結合する - Python

背景として、シェイプファイルは、ArcGISで手動でポリゴンを描画することによって作成されます。これらのポリゴンはさまざまなプロジェクトを表しています。識別子「名前」は、プロジェクトの初期計画番号またはプロジェクトの予算後に存在する契約番号のいずれかです。プランニング番号は、予算がない場合に存在し、契約番号は後になります。ポリゴンが作成され、「Name」フィールドには、プロジェクトが到達したステージ(計画番号または契約番号のいずれか)が入力されます。したがって、シェイプファイルフィールド "名前"には、計画番号または契約番号のいずれかが含まれます。 ------------契約-----フェーズ

PLN:並行

は、我々は計画数と契約番号の両方を表す2つのフィールドを持つすべてのプロジェクトの複雑なデータベースを持っています------------全長----- NTP --------- SC -------------備考

1415-003 ----- WD-2506 ----事前計画---- 45 ---------- 1/1/1900 ---- 1/20/1900 -----テスト

私のコードを作成するために、データベースにリンクする簡単なxmlテーブルを作成しました。このxmlテーブルには、PLN(計画番号)フィールドと契約(契約番号)フィールドがあります。私のコードでは、このXMLをdbfに変換しました。私は今、 "PLN"または "契約"にShapefile "Name"を結合する方法を見つけようとしています。

以下のコードを参照してください。

#Convert xlsx to table: 
import xlrd 

in_excel= r'W:\\Engineering\\ENGINEER\\LAMP (062012)\\Database\\VisualDatabase\\Planning_Out\\JoinTest.xlsx' 
out_table= r'W:\\Engineering\\ENGINEER\\LAMP (062012)\\Database\\VisualDatabase\\Planning_Out\\JoinTest.gdb' 


# Perform the conversion 
join_table= arcpy.ExcelToTable_conversion(in_excel, out_table) 

print join_table 

# Join 
# Set the local parameters 
inFeatures = r'W:\\Engineering\\ENGINEER\\LAMP (062012)\\Database\\VisualDatabase\\Planning_Out\\CDDprojects.shp' 
joinField = 
joinTable = join_table 
fieldList = ["PLN", "Contract", "Phase", "Length", "NTP", "SC", "Notes] 

を私はjoinFieldに入力する内容がわからないですし、他のコードがある場合、私は含めるべきです。

リビジョン1: Iはイーサンのコードを使用するが、エラーメッセージを受信した時にエラーが読み出し

with master_table.open(): 
    with minimal_table.open(): 
     minimal_index = dbf.create_index(minimal_table, lambda record: record.name) 

Traceback (most recent call last): 
    File "W:\Engineering\ENGINEER\LAMP (062012)\Database\VisualDatabase\LAMP.py", line 53, in <module> 
    with master_table.open(): 
AttributeError: 'Result' object has no attribute 'open' 

REVISION 2: を私は私ので、おそらく初心者レベル午前かなり単純なものが欠けている。私はDBFをインポートしようとすると、私は自分のコードの後に​​エラーが発生します:

Traceback (most recent call last): 
    File "W:\Engineering\ENGINEER\LAMP (062012)\Database\VisualDatabase\LAMP.py", line 50, in <module> 
    import dbf 
ImportError: No module named dbf 

を私はDBFモジュールをダウンロードしますが、セットアップを実行するときに、私はこのエラーが表示されます。

Warning (from warnings module): 
    File "C:\Python27\ArcGIS10.3\lib\distutils\dist.py", line 267 
    warnings.warn(msg) 
UserWarning: Unknown distribution option: 'install_requires' 

私は」私はdbfをインストールするに間違って何をしているのかわからない。

改訂3: dbfモジュールをインストールし、arcpyに正常にインポートされました。しかし、私はまだ同じエラーメッセージを受信して​​います:

Traceback (most recent call last): 
    File "W:\Engineering\ENGINEER\LAMP (062012)\Database\VisualDatabase\LAMP.py", line 56, in <module> 
    with master_table.open(): 
AttributeError: 'Result' object has no attribute 'open' 

私のコードは次のとおりです。私はここにDBFモジュールを使用しています

#Convert xlsx to table: 
import xlrd 

in_excel= r'W:\\Engineering\\ENGINEER\\LAMP (062012)\\Database\\VisualDatabase\\Planning_Out\\JoinTest.xlsx' 
out_table= r'W:\\Engineering\\ENGINEER\\LAMP (062012)\\Database\\VisualDatabase\\Planning_Out\\JoinTest.gdb' 

# Perform the conversion 
join_table= arcpy.ExcelToTable_conversion(in_excel, out_table) 

import enum 
import dbf 

# table with all projects at all stages 
master_table = join_table 
# table with single project and most up-to-date stage 
minimal_table = r'W:\\Engineering\\ENGINEER\\LAMP (062012)\\Database\\VisualDatabase\\Planning_Out\\CDDprojects.dbf' 

with master_table.open(): (LINE 56 which the AttributeError calls) 
    with minimal_table.open(): 
     minimal_index = dbf.create_index(minimal_table, lambda record: record.name) 

# cycle through master, updating minimal if necessary 
     for master in master_table: 
# look for PLN # first 
      found = minimal_index.search(master.PLN) 
      if not found: 
       # if record doesn't exist with PLN #, try CONTRACT # 
       found = minimal_index.search(master.Contract) 

https://pypi.python.org/pypi/dbf

感謝を。

+0

'AttributeError'が'「結果」object'参照している - そのような事は私の 'dbf'パッケージではありませんが - 代わりに私の使用している他のいくつかの' dbf'があります? –

+0

あなたは正しいです。しかし、 "import dbf"コマンドに問題があります。改訂された質問をご覧ください。 –

+0

@Ethan dbfをインポートした後、私はまだ 'Result'オブジェクトを参照するのと同じAttributeErrorを受け取ります。私はdbfテーブルに私のExcelシートを変換するためにxlrdをインポート... xlrdはdbfモジュールと競合する可能性がありますか? –

答えて

0

私はarcpyで作業していませんでしたが(私はあなたが何をしようとしているのか分かりません)、my dbf moduleを使用して、これをマスターテーブルからシェイプテーブルのdbfファイル:

import dbf 

# table with all projects at all stages 
master_table = dbf.Table(complex_table) 
# table with single project and most up-to-date stage 
minimal_table = dbf.Table(single_project_table) 

with master_table.open(): 
    with minimal_table.open(): 
     minimal_index = dbf.create_index(minimal_table, lambda record: record.name) 

     # cycle through master, updating minimal if necessary 
     for master in master_table: 
      # look for PLN # first 
      found = minimal_index.search(master.pln) 
      if not found: 
       # if record doesn't exist with PLN #, try CONTRACT # 
       found = minimal_index.search(master.contract) 
       if not found: 
        # not there at all, add it 
        minimal_table.append(master.contract or master.pln, master.phase, master.length, ...) 
        break 

      # have a match, update it 
      found.name = master.contract or master.pln 
      # plus any other updates you need 
      # ... 
      # and then write the record 
      dbf.write(found) 
+0

Thanks Ethan。改訂された質問をエラーメッセージと共に見てください。 –

関連する問題