Batch processing animal home range overlap data

Discussion created by dellatore on Apr 23, 2013
Latest reply on Apr 26, 2013 by dellatore

Am new to python, but even with rudimentary knowledge am already finding it incredibly useful.

Have put together the following script to calculate home range polygon overlap, at this point just between two user-set individuals.There's a lot more am planning on workout on, with for example the log/output system being wonky at the moment, but what I'd really like to do is set this up to iterate through various polygon shapefiles in a folder.

So if anyone could help me set it up so that ou1 (orangutan!) remains static, but then have the script iterate the ou2 variable across a set of other individuals (from polygon shapefiles all in one location), I'd really appreciate it. 

It'd be fantastic to have all of the results from ou1 output onto a single table, showing the overlap he/she has with each other ou2 - but at this point I'd be ecstatic with just having the loop figured out so that it outputs each pairing to its own table, and I can compile them manually later.

#script to calculate home range overlap (hectares) between two individuals

# import modules
import arcpy
import time
import os
from arcpy import env

env.overwriteOutput = True

# local variables
ou1 = arcpy.GetParameterAsText(0)
ou2 = arcpy.GetParameterAsText(1)
int_output = arcpy.GetParameterAsText(2)
int_output_Statistics = arcpy.GetParameterAsText(3)
logfile = arcpy.GetParameterAsText(4)

    f = open(logfile, "a")

    # process: intersect
    #intersect_analysis (in_features, out_feature_class, {join_attributes}, {cluster_tolerance}, {output_type})
    arcpy.analysis.Intersect([ou1, ou2], int_output, "ALL", "", "INPUT")
    f.write("\n" + "Calculating home range overlap between " + ou1 + " & " + ou2)
    print "Calculating home range overlap between " + ou1 + " & " + ou2

    # process: add field, "intersect", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    f.write("\n" + "Adding \"Intersect\" field to " + int_output)
    print "Adding \"intersect\" field to " + int_output

    # process: calculate field, "intersect", "!shape.area@HECTARES!", "PYTHON_9.3", "")
    f.write("\n" + "Calculating geometry of overlap between " + ou1 + " " + ou2)
    print "Calculating geometry of overlap between " + ou1 + " " + ou2

    # process: delete identical, "intersect", "", "0")
    f.write("\n" + "Deleting identical values from \"Intersect\" field")
    print "Deleting identical values from \"Intersect\" field"

    # process: summary statistics
    arcpy.analysis.Statistics(int_output, int_output_Statistics, "intersect SUM", "")
    f.write("\n" + "Determine overlap value in hectares")
    print "Determine overlap value in hectares"
    f.write("\n" + int_output_Statistics)
    f.write("\n" + "------------------------------")


except Exception, e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "Line %i" % tb.tb_lineno
    print e.message

Thanks very much for your time,