<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Looping Intersection Analysis in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/looping-intersection-analysis/m-p/273662#M21142</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to create a loop that will allow me to intersect 50 files with each other.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My first input is a polygon layer resulting from coverage analysis (Analysis Network Layer) containing all the fire station&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My second input is a layer polygon layer resulting coverage analysis (Analysis Network Layer) containing &lt;/SPAN&gt;&lt;STRONG&gt;all the fire station - 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;From the result of the intersection, I compare two columns together from a condition and remove the selection will be my input to the next intersection operation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Until there everything goes well, the problem is that I want to create a loop to automate the process. I find it difficult to figure out how to use a layer resulting and input at the sametime to do an intersection analysis.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy
from arcpy import env
env.overwriteOutput = True

env.workspace = "S:\Travail\Zone_Support_mutuel_test\Test_temp\ServiceAreaV2"

j = 1
outIntersectGlobal = "in_memory" + "\\" + "IntersectGlobal"
outIntersect = outputPolygons + "\\" + "Intersect"
IntersectResult = "in_memory" + "\\" + "Intersect" + j

fcGlobal = arcpy.ListFeatureClasses("Global*","Polygons")
fclist = arcpy.ListFeatureClasses("C*","Polygons")
print fcGlobal[0]
print fclist[1]

#for fc in arcpy.ListFeatureClasses("C*","Polygons"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; #print fcGlobal
&amp;nbsp;&amp;nbsp;&amp;nbsp; #print fc.Nom
&amp;nbsp;&amp;nbsp; 
# Intersect Network analysis polygon( All fire Station coverage) with (All fire station minus 1)
arcpy.Intersect_analysis([fcGlobal,fclist[0]],"outIntersectGlobal")

codeblock = "def isSame(x, y):\n\n&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldA = str(x)\n\n&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldB = str(y)\n\n&amp;nbsp;&amp;nbsp;&amp;nbsp; if fieldA == fieldB:\n\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1\n\n&amp;nbsp;&amp;nbsp;&amp;nbsp; else:\n\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0\n"
isSameQuery = "isSame" = '1'

arcpy.AddField_management(outIntersectGlobal,"isSame","SHORT", "5", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management(outIntersectGlobal,"isSame","isSame( !Name!, !Name_1! )","Python_9.3",codeblock)
#arcpy.CopyFeatures_management(outIntersectGlobal, outputPolygons + "\\" + "Intersect")
arcpy.MakeFeatureLayer_management(outIntersectGlobal,"Intersect1",isSameQuery)

j+= 1

# Second intersection 
arcpy.Intersect_analysis([outIntersectGlobal,fclist[1]],IntersectResult)
arcpy.AddField_management(IntersectResult,"isSame","SHORT", "5", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management(IntersectResult,"isSame","isSame( !Name!, !Name_1! )","Python_9.3",codeblock)
arcpy.MakeFeatureLayer_management(outIntersectGlobal,IntersectResult,isSameQuery)

j+= 1

#########################
### Blocked with the ouput of the intersect result and still incrementing it to have it as input for the next loop ###

for i in range(fclist):
&amp;nbsp;&amp;nbsp;&amp;nbsp; print i
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Intersect_analysis(["IntersectResult","i"],
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(IntersectResult,"isSame","SHORT", "5", "", "", "", "NULLABLE", "NON_REQUIRED", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(IntersectResult,"isSame","isSame( !Name!, !Name_1! )","Python_9.3",codeblock)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(IntersectResult,"IntersectResult" + j,isSameQuery)

j+= 1&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks you for your help&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 07 Jan 2013 17:50:47 GMT</pubDate>
    <dc:creator>Pierre-LucBoivin</dc:creator>
    <dc:date>2013-01-07T17:50:47Z</dc:date>
    <item>
      <title>Looping Intersection Analysis</title>
      <link>https://community.esri.com/t5/python-questions/looping-intersection-analysis/m-p/273662#M21142</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to create a loop that will allow me to intersect 50 files with each other.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My first input is a polygon layer resulting from coverage analysis (Analysis Network Layer) containing all the fire station&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My second input is a layer polygon layer resulting coverage analysis (Analysis Network Layer) containing &lt;/SPAN&gt;&lt;STRONG&gt;all the fire station - 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;From the result of the intersection, I compare two columns together from a condition and remove the selection will be my input to the next intersection operation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Until there everything goes well, the problem is that I want to create a loop to automate the process. I find it difficult to figure out how to use a layer resulting and input at the sametime to do an intersection analysis.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy
from arcpy import env
env.overwriteOutput = True

env.workspace = "S:\Travail\Zone_Support_mutuel_test\Test_temp\ServiceAreaV2"

j = 1
outIntersectGlobal = "in_memory" + "\\" + "IntersectGlobal"
outIntersect = outputPolygons + "\\" + "Intersect"
IntersectResult = "in_memory" + "\\" + "Intersect" + j

fcGlobal = arcpy.ListFeatureClasses("Global*","Polygons")
fclist = arcpy.ListFeatureClasses("C*","Polygons")
print fcGlobal[0]
print fclist[1]

#for fc in arcpy.ListFeatureClasses("C*","Polygons"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; #print fcGlobal
&amp;nbsp;&amp;nbsp;&amp;nbsp; #print fc.Nom
&amp;nbsp;&amp;nbsp; 
# Intersect Network analysis polygon( All fire Station coverage) with (All fire station minus 1)
arcpy.Intersect_analysis([fcGlobal,fclist[0]],"outIntersectGlobal")

codeblock = "def isSame(x, y):\n\n&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldA = str(x)\n\n&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldB = str(y)\n\n&amp;nbsp;&amp;nbsp;&amp;nbsp; if fieldA == fieldB:\n\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1\n\n&amp;nbsp;&amp;nbsp;&amp;nbsp; else:\n\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0\n"
isSameQuery = "isSame" = '1'

arcpy.AddField_management(outIntersectGlobal,"isSame","SHORT", "5", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management(outIntersectGlobal,"isSame","isSame( !Name!, !Name_1! )","Python_9.3",codeblock)
#arcpy.CopyFeatures_management(outIntersectGlobal, outputPolygons + "\\" + "Intersect")
arcpy.MakeFeatureLayer_management(outIntersectGlobal,"Intersect1",isSameQuery)

j+= 1

# Second intersection 
arcpy.Intersect_analysis([outIntersectGlobal,fclist[1]],IntersectResult)
arcpy.AddField_management(IntersectResult,"isSame","SHORT", "5", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management(IntersectResult,"isSame","isSame( !Name!, !Name_1! )","Python_9.3",codeblock)
arcpy.MakeFeatureLayer_management(outIntersectGlobal,IntersectResult,isSameQuery)

j+= 1

#########################
### Blocked with the ouput of the intersect result and still incrementing it to have it as input for the next loop ###

for i in range(fclist):
&amp;nbsp;&amp;nbsp;&amp;nbsp; print i
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Intersect_analysis(["IntersectResult","i"],
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(IntersectResult,"isSame","SHORT", "5", "", "", "", "NULLABLE", "NON_REQUIRED", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(IntersectResult,"isSame","isSame( !Name!, !Name_1! )","Python_9.3",codeblock)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(IntersectResult,"IntersectResult" + j,isSameQuery)

j+= 1&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks you for your help&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Jan 2013 17:50:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-intersection-analysis/m-p/273662#M21142</guid>
      <dc:creator>Pierre-LucBoivin</dc:creator>
      <dc:date>2013-01-07T17:50:47Z</dc:date>
    </item>
  </channel>
</rss>

