In my project, I am using drivetime polygons to clip block group data to get the population in that drive time. The drive time shapefile I am testing on has 5 polygons. I want to update the population field for each polygon by summing the population in the clipped demographic data for that polygon.
I am using the Ratio Policy to make sure I don't take the whole block population but only the ratio of the overlap.
I have been able to execute this in ArcGIS desktop with a shapefile that only contained one polygon. I am now trying to execute this using python in a loop so that each polygon in the shapefile creates a temporary clipped feature layer to use for the population sum.
The ratio though doesn't seem to be honored in the code.
temp = 'temp_lyr' arcpy.MakeFeatureLayer_management(demographic, temp) # Create a describe object desc = arcpy.Describe(temp) print desc.dataType # Get the field index and set ratio policy if desc.dataType == "FeatureLayer": print ("is featurelayer") # Create a fieldinfo object field_info = desc.fieldInfo field_info.setSplitRule(field_info.findFieldByName("TOTPOP_CY"), "RATIO") #arcpy.MakeFeatureLayer_management(demographic, temp, '', '', field_info) print ("Next Phase") print field_info.getSplitRule(field_info.findFieldByName("TOTPOP_CY")) # iterate through drivetime polygons # use updateCusror because we will have to update the TotPop field # call for the shape@, totpop field with arcpy.da.UpdateCursor(drivetime, ['SHAPE@', 'TOTPOP_SUM']) as cursor: clipoutput = "ClipOutput_lyr" for row in cursor: summed_total = 0 #summed population #obtain the intersection between the demographics and drive time #output a temporary file that contains all the block groups that #intersect arcpy.Clip_analysis(temp , row, clipoutput) #create cursor to access data in intersection cursor_clipped = arcpy.da.SearchCursor(clipoutput['OBJECTID','TOTPOP_CY']) #loop through cursor and add together tot pop for the drivetime area for block in cursor_clipped: print "block",cursor_clipped summed_total = cursor_clipped+ summed_total row = summed_total print summed_total cursor.updateRow(row) arcpy.Delete_management(clipoutput)