Thanks very much for the response.However, I have managed to put together a loop in the script that will cycle through each shapefile and compare them all individually with one animal:#script to calculate home range overlap (hectares) between two individuals
# import modules
import arcpy
import time
import os
#import tabletoexcel
arcpy.ImportToolbox("xxx\Additional Conversion - Generic Tools.tbx")
from arcpy import env
env.overwriteOutput = True
# local variables
#hardcode test
ou1 = r"xxx\bbmmAnsPoly90.shp"
arcpy.env.workspace = r"xxx\ninety"
outputfolder = r"xxx\ninety\test"
#logfile = r"xxx\ansoverlap.txt"
#ou1 = arcpy.GetParameterAsText(0)
#arcpy.env.workspace = arcpy.GetParameterAsText(1)
#outputfolder = arcpy.GetParameterAsText(2)
#int_output_Statistics = arcpy.GetParameterAsText(3)
logfile = outputfolder + "\\" + ou1 + "_" + "overlaps.txt"
print logfile
try:
# process: intersect
#intersect_analysis (in_features, out_feature_class, {join_attributes}, {cluster_tolerance}, {output_type})
ou2s = arcpy.ListFeatureClasses()
for ou2 in ou2s:
fcname1 = arcpy.Describe(ou1).basename
fcname2 = arcpy.Describe(ou2).basename
int_output = os.path.join(outputfolder, str(fcname1 + fcname2) + ".shp")
#int_output = os.path.join(outputfolder, str(fcname1) + "_overlaps.shp")
int_output_Statistics = r"xxx\Default.gdb" + "\\" + str(fcname1 + fcname2)
#int_output_Statistics = r"xxx\Default.gdb" + "\\" + str(fcname1) + "_overlaps"
excel_output = outputfolder + "\\" + str(fcname1 + fcname2)
#excel_output = outputfolder + "\\" + str(fcname1) + "_overlaps"
logfile = outputfolder + "\\" + fcname1 + "_" + "overlaps.txt"
if arcpy.Exists(logfile):
f = open(logfile, "a")
else:
f = open(logfile, "w")
f.write(time.strftime('%c'))
f.write("\n")
f.write("------------------------------")
f.write("\n")
arcpy.analysis.Intersect([ou1, ou2], int_output)
f.write("\n" + "Calculating home range overlap between " + fcname1 + " & " + fcname2)
print "Calculating home range overlap between " + fcname1 + " & " + fcname2
# process: add field
arcpy.management.AddField(int_output, "Overlap", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
f.write("\n" + "Adding \"Overlap\" field to " + int_output)
print "Adding \"Overlap\" field to " + int_output
# process: calculate field
arcpy.management.CalculateField(int_output, "Overlap", "!shape.area@HECTARES!", "PYTHON_9.3", "")
f.write("\n" + "Calculating geometry of overlap between " + fcname1 + " " + fcname2)
print "Calculating geometry of overlap between " + fcname1 + " " + fcname2
# process: delete identical
arcpy.management.DeleteIdentical(int_output, "Overlap", "", "0")
f.write("\n" + "Deleting identical values from \"Overlap\" field")
print "Deleting identical values from \"Overlap\" field"
# process: summary statistics
f.write("\n" + "Determine overlap value in hectares")
print "Determine overlap value in hectares"
arcpy.analysis.Statistics(int_output, int_output_Statistics, "Overlap SUM", "")
arcpy.management.AddField(int_output_Statistics, 'orangutan1', 'TEXT')
arcpy.management.AddField(int_output_Statistics, 'isopleth1', 'DOUBLE')
arcpy.management.AddField(int_output_Statistics, 'orangutan2', 'TEXT')
arcpy.management.AddField(int_output_Statistics, 'isopleth2', 'DOUBLE')
search1 = arcpy.SearchCursor(ou1)
for scrap in search1:
ou1_name = scrap.getValue("ou")
ou1_iso = scrap.getValue("iso")
search2 = arcpy.SearchCursor(ou2)
for scrap in search2:
ou2_name = scrap.getValue("ou")
ou2_iso = scrap.getValue("iso")
#row_values = [(scrap.getValue("ou"), scrap.getValue("iso"))]
cursor = arcpy.UpdateCursor(int_output_Statistics)
for row in cursor:
row.setValue("orangutan1", ou1_name)
row.setValue("orangutan2", ou2_name)
row.setValue("isopleth1", ou1_iso)
row.setValue("isopleth2", ou2_iso)
cursor.updateRow(row)
f.write("\n" + "Writing to:" + " " + int_output_Statistics)
#export_to_xls(dataset, output):
arcpy.TableToExcel_conversion2(int_output_Statistics, excel_output, "XLS")
print "Writing to excel file"
f.write("\n" + "Writing to excel file:" + " " + excel_output)
f.write("\n" + "------------------------------")
f.write ("\n")
f.close
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
It's not perfect yet, but think it's getting there!Thanks again