Schema locks and join problems

1114
4
05-15-2012 10:51 AM
F__BenGrieger
New Contributor II
I'm writing a script to summarize data in a feature class in two different ways using Statistics_analysis, then join the two generated tables to do some calculations.  The problem is that the join fails due to a schema lock error. If I split the script into two scripts, closing out the geoprocessor after the statistics runs, then it works. But, I really want it all in one script. Anyone know how I can get Statistics_analysis to let go so I can continue my geoprocessing in the same script?

Here is the code:

# Make a table view containing only the impervious surfaces in the allSurfaces FC
arcpy.MakeTableView_management("Surfaces\\allSurfaces", "impsurfaces", """ "Material"= 'concrete' OR "Material" = 'asphalt' OR "Material" = 'wood' OR "Material" = 'rubber' OR "Material" = 'artificial' OR "Material" = 'greenasphalt' OR "Material" = 'blueasphalt' OR "Material" = 'redasphalt' """)


# Make a table view containing all surfaces.
arcpy.MakeTableView_management("Surfaces\\allSurfaces", "surfacetotals")


# Summarize to get total imp surface by property
arcpy.Statistics_analysis("impsurfaces", "Sewer", [["Shape.area", "SUM"]], "Property")
# Summarize to get total park area by property
arcpy.Statistics_analysis("surfacetotals", "Parksizes", [["Shape.area", "SUM"]], "Property")

#join the tables so we can do some calculations.
arcpy.JoinField_management("Sewer", "OBJECTID", "Parksizes", "OBJECTID", "SUM_Shape_area")



by the way, I don't want to join on OBJECTID (for obvious reasons), I want to use 'Property', but when I do only about 10% of the records match even though they were generated from the same feature class using the same Statistics_analysis method, and the entries in the field look IDENTICAL!  Any help on this problem would also be great

Thanks!
0 Kudos
4 Replies
F__BenGrieger
New Contributor II
I've solved part of the problem. I had an idea while looking at some of my old 9.3 scripts.  We used to always set a variable, usually called 'gp' to stand for the geoprocessor so that we wouldn't have to keep typing out 'arcgisscripting.create(9.3)'. Well, I figured why not do the same with arcpy, then delete the variable after the Statistics method runs (similar to how we delete cursor variable to get them to drop their locks)? So now the first part of my script runs with all methods called by gp where gp=arcpy, then after the Statistics method runs, I delete the gp variable and go back to using arcpy for the rest of the script. That fixed it- the schema lock no longer prevents the join. It's a silly thing to have to do to get it to work, but I guess I'm used to that by now... 

The problem with the join only matching a small number of the records still persists, but at least the schema lock problem is dealt with...
0 Kudos
JohnCobb1
New Contributor
Have you tried creating tables on disk from the the table views?

# Make a tableview of impervious surfaces from the query.
query = """"Material" IN ('concrete', 'asphalt', 'wood', 'rubber', 'artificial', 'greenasphalt', 'blueasphalt','redasphalt')"""
arcpy.MakeTableView_management("Surfaces\\allSurfaces", "impsurfaces", query)

 # Create a .dbf table in current workspace from the table view.
arcpy.CopyRows_management("impsurfaces", "impsurfaces.dbf")

# Make a table view containing all surfaces.
arcpy.MakeTableView_management("Surfaces\\allSurfaces", "surfacetotals")
arcpy.CopyRows_management("surfacetotals", "surfacetotals.dbf")

# Summarize to get total imp surface by property
arcpy.Statistics_analysis("impsurfaces.dbf", "Sewer", [["Shape.area", "SUM"]], "Property")
# Summarize to get total park area by property
arcpy.Statistics_analysis("surfacetotals.dbf", "Parksizes", [["Shape.area", "SUM"]], "Property")

#join the tables so we can do some calculations.
arcpy.JoinField_management("Sewer", "Property", "Parksizes", "Property", "SUM_Shape_area")
0 Kudos
markdenil
Occasional Contributor III
If you are using Property as a case field, then it is likely not unique, and thus not a good candidate for a join field.
quote:
If values in the Output Join Field are not unique, only the first occurrence of each value will be used.
unQuote.
0 Kudos
F__BenGrieger
New Contributor II
Sorry I'm so late getting back to this thread!

@jgcobb- thanks for showing me another approach; I'll play around with that.

@mdenil- Yeah, that's a reasonable suspicion, but I actually listed the values out so I could inspect them and they are unique and identical to values in the other table as far as I can tell. Something weird going on.
0 Kudos