Select to view content in your preferred language

AddJoin failed

3245
22
Jump to solution
06-30-2013 02:44 AM
ElaineKuo
Regular Contributor
System: Vista, ArcGIS 9.3

Hello,

I wrote a python code to AddJoin a grid shapefile (File A) to a bird range shapefile (File B).
They have a field in common (GID).

However, the error message is
ERROR 000732: Input Features: Dataset H:/temp_D/testt does not exist or is not supported
Failed to execute (MakeFeatureLayer).

Please kindly advise how to modify the code.
Thank you.
(The file location is
"H:/temp_D/testt/grid.shp"
"H:/temp_D/test/birdrange.shp")

#Import standard library modules import arcgisscripting import os  #Create the Geoprocessor object gp = arcgisscripting.create(9.3)  #Get a list of the featureclasses in the input folder source_fc = "H:/temp_D/testt" Entity = "H:/temp_D/test" outputfolder = "H:/temp_D"  gp.Toolbox = "Data Management"      # convert a featureclass to a layer  gp.MakeFeatureLayer_management (source_fc, "source_lyr")  # have Layers for AddJoin gp.AddJoin_management("source_lyr", "GID", Entity, "GID", "KEEP_ALL")  # convert a layer to a featureclass  gp.CopyFeatures_management ("source_lyr", source_fc) gp.FeatureClassToShapefile_conversion(source_fc, outputfolder)  # clear memory of layers gp.Delete("source_lyr")      gp.AddMessage(gp.GetMessages()) print gp.GetMessages()
Tags (2)
0 Kudos
22 Replies
ElaineKuo
Regular Contributor
Hello,

Thanks for the immediate response.
However, all ID_* fields remained after I ran the code. (no error message)
We need more try to figure out how to make the "delete multiple fields" work.:)

Elaine

The whole code is
################################################## ########################
##AddJoin feature layers to a feature layer
##Elaine Kuo
##01 July 2013
################################################## #######################

#Import standard library modules
import arcgisscripting
import os

#Create the Geoprocessor object
gp = arcgisscripting.create(9.3)
gp.QualifiedFieldNames = "UNQUALIFIED"

#Set the input workspace
workingfolder= "H:/temp_D/test"
gp.Workspace = workingfolder

#Set the output workspace
outputfolder= "H:/temp_D"
outWorkspace= outputfolder

source_fc = "H:/temp_D/testt/A_grid.shp"

#Get a list of the featureclasses in the input folder
fcs = gp.ListFeatureClasses()

gp.Toolbox = "Data Management"

# Make a FeatureClass layer    
gp.MakeFeatureLayer_management (source_fc, "source_lyr")

# A counter to separate the first time through the loop from all other times
counter = 0
# Loop through every item in the list that was just generated
for fc in fcs:
    if counter == 0:
        # set up first Layer for AddJoin
        gp.AddJoin_management("source_lyr", "GID", fc, "GID", "KEEP_ALL")
    else:
        # set up second and following Layers for AddJoin
        gp.AddJoin_management("source_lyr", "A_grid.GID", fc, "GID", "KEEP_ALL")
    counter += 1

# convert a layer to a featureclass 
out_name = gp.Describe("source_lyr").name
out_name = gp.ValidateTableName(out_name, outputfolder)
out_shape = outputfolder + "/" + out_name + ".shp"

gp.CopyFeatures_management ("source_lyr", out_shape)
    
# delete Field  (need to clean up with a lot more ID fields that the code you have below since now there are 50 GID values.)
fieldList = gp.ListFields(out_shape)
for field in fieldList:
    if field.name[1:3] == "ID_":
        gp.deletefield (out_shape, field.name)

# Don't bother removing 50 joins, just kill the layer
# clear memory of layers
gp.Delete("source_lyr")
    
gp.AddMessage(gp.GetMessages())
print gp.GetMessages()
0 Kudos
RichardFairhurst
MVP Honored Contributor
I found out that python substrings act differently than I thought.  So I changed this line in the code below and it should now work.

    if field.name[1:3] == "ID_":

to

    if field.name[1:4] == "ID_":

The first version I gave only got "ID" from the field name.  The correction will get "ID_".

################################################## ######################## ##AddJoin feature layers to a feature layer ##Elaine Kuo ##01 July 2013 ################################################## #######################  #Import standard library modules import arcgisscripting import os  #Create the Geoprocessor object gp = arcgisscripting.create(9.3) gp.QualifiedFieldNames = "UNQUALIFIED"  #Set the input workspace workingfolder= "H:/temp_D/test" gp.Workspace = workingfolder  #Set the output workspace outputfolder= "H:/temp_D" outWorkspace= outputfolder  source_fc = "H:/temp_D/testt/A_grid.shp"  #Get a list of the featureclasses in the input folder fcs = gp.ListFeatureClasses()  gp.Toolbox = "Data Management"  # Make a FeatureClass layer     gp.MakeFeatureLayer_management (source_fc, "source_lyr")  # A counter to separate the first time through the loop from all other times counter = 0 # Loop through every item in the list that was just generated for fc in fcs:     if counter == 0:         # set up first Layer for AddJoin         gp.AddJoin_management("source_lyr", "GID", fc, "GID", "KEEP_ALL")     else:         # set up second and following Layers for AddJoin         gp.AddJoin_management("source_lyr", "A_grid.GID", fc, "GID", "KEEP_ALL")     counter += 1  # convert a layer to a featureclass  out_name = gp.Describe("source_lyr").name out_name = gp.ValidateTableName(out_name, outputfolder) out_shape = outputfolder + "/" + out_name + ".shp"  gp.CopyFeatures_management ("source_lyr", out_shape)      # delete Field  (need to clean up with a lot more ID fields that the code you have below since now there are 50 GID values.) fieldList = gp.ListFields(out_shape) for field in fieldList:     if field.name[1:4] == "ID_":         gp.deletefield (out_shape, field.name)  # Don't bother removing 50 joins, just kill the layer # clear memory of layers gp.Delete("source_lyr")      gp.AddMessage(gp.GetMessages()) print gp.GetMessages()
ElaineKuo
Regular Contributor
Thank you very much.
Eventually the code worked very well.
0 Kudos