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 
        arcpy.Clip_analysis(temp , row[0], clipoutput)

        #create cursor to access data in intersection
        cursor_clipped = 
        #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[1]+ summed_total

    row[1] = summed_total
    print summed_total
  • Welcome to GIS SE! We're a little different from other sites. We're a Q&A site, not a discussion forum. For questions that involve code we ask that you show us where you are stuck with your own code by including a code snippet in your question. There is an edit button beneath your question which will enable you to do that and a {} button that enables you to format any highlighted code nicely. Please check out our short tour for more about how the site works. Thanks. – PolyGeo Jan 24 '19 at 0:13
  • It is clear that Clip tool doesn't honor the rule designed for editing session split. – FelixIP Jan 24 '19 at 6:34
  • But it honors is when I run it in Arcgis – LouiseJ Jan 29 '19 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.