Select to view content in your preferred language

Split table to JoinField_management problem

3539
1
03-19-2015 12:40 AM
JohannesBierer
Frequent Contributor
# Import arcpy module
import arcpy
arcpy.env.workspace = "R:\Karto\Bierer2014\FFH_MEKA\data.gdb"
# Local variables:
ALK_Flurstueck_Merge1 = r"R:\Daten\geo_daten\Basisgeometrien\Basisgeometrien_2014_03_21.gdb\data\ALK_Flurstueck_Merge1"
Meka = "R:\\Karto\\Bierer2014\\FFH_MEKA\\Meka.mdb\\Meka"
ALK_Flurstueck_Merge1_2 = "ALK_Flurstueck_Merge1"
Count_Lines = arcpy.GetCount_management(Meka)
print Count_Lines
MekaLyr = arcpy.MakeTableView_management(Meka) 
for i in range(0, 18000, 100):
    print i
    y = str(i + 99)
    print y
    z = str(i)
##    SelectCl = ( [ID] < ' + y + " AND [ID] > '" + z + ")
    arcpy.SelectLayerByAttribute_management(MekaLyr,"NEW_SELECTION", '( [ID] < ' + y + " AND [ID] > " + z + ")")
    
    # Process: Feld verbinden
    arcpy.JoinField_management(ALK_Flurstueck_Merge1, "FLSKZ", MekaLyr, "FLRSTKZ", "FLRSTKZ;ALLB-Nr;Antragsteller;'Name, Vorname Antragsteller';Strasse;PLZ;Ort;'Nutzungsfl ar';N-Code;Meka-Codes;Feld11;Feld12;Feld13;Feld14;Feld15;Feld16;Feld17;Feld18;Feld19")
    # Process: Features kopieren
    arcpy.CopyFeatures_management(ALK_Flurstueck_Merge1_2, "zwErgebnis_" + i, "", "0", "0", "0")

Unfortunately the join doesn't work in one, so I want to split the table and join then?

But I miss the option which offers the arcmap interface - keep only matching records?

With the script here python is working, but nothing happens?

0 Kudos
1 Reply
BlakeTerhune
MVP Frequent Contributor

I haven't tried using table join with a selection, but my guess would be that you need to create your table view from the selection instead of creating a selection from the table view. To make it easier, you could just use a where clause when creating the table view; then do the join.

Also, the way you call the joined table in CopyFeatures might be wrong. Try this instead:

arcpy.CopyFeatures_management(ALK_Flurstueck_Merge1, "zwErgebnis_" + i, "", "0", "0", "0")

EDIT:

Maybe try this and see what it does. I got rid of the fields you had listed in the join so it will bring back everything from Meka; not sure if that's what you want. I also got rid of the optional parameters on copy features. Did you intend to use the spatial grid parameters?

# Import arcpy module
import arcpy
arcpy.env.workspace = r"R:\Karto\Bierer2014\FFH_MEKA\data.gdb"
# Local variables:
ALK_Flurstueck_Merge1 = r"R:\Daten\geo_daten\Basisgeometrien\Basisgeometrien_2014_03_21.gdb\data\ALK_Flurstueck_Merge1"
Meka = r"R:\Karto\Bierer2014\FFH_MEKA\Meka.mdb\Meka"
Count_Lines = arcpy.GetCount_management(Meka)
print Count_Lines
for i in range(0, 18000, 100):
    print i
    y = i + 99
    print y
    z = i
    where_clause = "[ID] < {} AND [ID] > {}".format(y, z)
    MekaLyr = arcpy.MakeTableView_management(Meka, where_clause)
    # Process: Feld verbinden
    arcpy.JoinField_management(ALK_Flurstueck_Merge1, "FLSKZ", MekaLyr, "FLRSTKZ")
    # Process: Features kopieren
    zwErgebnis = "zwErgebnis_{}".format(i)
    arcpy.CopyFeatures_management(ALK_Flurstueck_Merge1, zwErgebnis)
0 Kudos