Greetings,

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.

Thanks very much for your time,

David

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) try: f = open(logfile, "a") f.write(time.strftime('%c')) f.write("\n") f.write("------------------------------") f.write("\n") # 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 arcpy.management.AddField(int_output, "intersect", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") f.write("\n" + "Adding \"Intersect\" field to " + int_output) print "Adding \"intersect\" field to " + int_output # process: calculate field arcpy.management.CalculateField(int_output, "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 arcpy.management.DeleteIdentical(int_output, "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" + "------------------------------") 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

Thanks very much for your time,

David

I like to create functions, and then use them inside of models. You could do this and let the model take care of the iterations by setting the input for ou2 as a parameter, and setting its properties to "A list of values". Set an input parameter for ou1, drop the home range polygons of interest into the "ou2" parameter, and execute. It is efficient and flexible. I have a simple script to set the symbology of a raster dataset from a layer file, and use it this way often. Image of model attached.

Regards,

Jim