Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have some Python code that takes a shapefile, creates its centroids via FeatureToPoint, joins an auxillary field from the shapefile to the centroid via JoinField, and then goes on to do some more work with the centroids.

The relevant code is:

centroids = arcpy.FeatureToPoint_management(shapefile, "centroids", "CENTROID")
arcpy.JoinField_management(centroids, "ORIG_FID", shapefile, "FID", "EXTRA_FIELD")

When I execute this script the first time, I get an error for the JoinField line:

arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Table: Dataset centroids does not exist or is not supported
Failed to execute (JoinField).

However, checking for the generated centroids shows that it has been created and exists on disk.

When I then execute the script a second time around there is no error and the script proceeds as normal.

While I'm glad to continue executing it twice as far as getting results I need, I'd really like to debug this and figure out why it fails the first time through.

Update

I believe I am running into problems because of how I try to assign the results of FeatureToPoint to the variable centroids and then use centroids in the rest of the code. I added some sanity checks to the above snippet like so:

print(shapefile)
centroids = arcpy.FeatureToPoint_management(shapefile, "centroids", "CENTROID")
print(centroids)
arcpy.JoinField_management(centroids, "ORIG_FID", shapefile, "FID", "EXTRA_FIELD")

The first time through it reads (before failing on the JoinField of course):

D:/temp/boundary.shp
centroids

The second time through it reads (and continues on with rest of the script):

D:/temp/boundary.shp
D:/temp/centroids.shp
share|improve this question
1  
Try MakeFeatureLayer_management on centroids and pass that into JoinField instead. I believe join field expects feature layers or table views, not feature classes or tables. Also, are you setting your arcpy.env.workspace? –  blah238 Feb 8 '12 at 2:12
    
arcpy.env.workspace is set, in the above example to D:/temp/. Should I not be referring to a feature class by a variable and instead always by a path? –  mindless.panda Feb 8 '12 at 2:30
1  
I guess the moral of this story is to not rely on the return values for geoprocessing functions. Seems like a bug. –  blah238 Feb 8 '12 at 3:49
    
What's frustrating is often I want to know why this ends up working the way it does but because of ESRI/ARC quirkiness or lack of documentation, I'll probably be spinning my wheels unless someone can shed some light. –  mindless.panda Feb 8 '12 at 13:28
1  
There's some documentation about "Getting results from a tool" at help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//… That section and the whole document of a few pages are worth reading to help understand the difference between a tool's Output and its Result object. –  PolyGeo Feb 9 '12 at 10:31
show 1 more comment

2 Answers

I think you are on the right track. I just tried something like below with shapefiles, and it all worked just fine. FeatureToPoint isn't supposed to return anything, it creates your centroid FC that you specify, centroids.shp in my case below.

import arcpy
arcpy.env.workspace = r"c:\where ever shapes live"
arcpy.FeatureToPoint_management("shapefile.shp", "centroids.shp", "CENTROID")
arcpy.JoinField_management("centroids.shp", "ORIG_FID", "shapefile.shp", "FID", "EXTRA_FIELD"
share|improve this answer
    
So perhaps I shouldn't worry about inconsistency in its return value if I'm not even supposed to be using it? –  mindless.panda Feb 9 '12 at 1:10
add comment

Try arcpy.JoinField_management("centroids", "ORIG_FID", shapefile, "FID", "EXTRA_FIELD")

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.