Loop on Union process [ArcGis10/Python]

I work on ArcGIS 10 and I'd like to realize multiple unions between layers. But that union task is a little bit particular. Indeed as the beginning of my code shows, I have seven layers (these layers have a specific classification).

import arcpy
from arcpy import env

workspace_2 = "V:/DONNEES/1_referentiels/mnt/1_france/1_dep_17/ign/litto3d/Litto3D_livraison_2011_10_24/traitements_lienss/tests/Workspace_chev/"
M0 = workspace_2 + "0.shp"
M1 = workspace_2 + "1.shp"
M2 = workspace_2 + "2.shp"
M3 = workspace_2 + "3.shp"
M4 = workspace_2 + "4.shp"
M5 = workspace_2 + "5.shp"
M6 = workspace_2 + "6.shp"
M7 = workspace_2 + "7.shp"

And my goal is to make an union between : M0 - M4, M1 - M5, M2 - M6 and so on. That is to say the union have to made every four layers. So I decided to make a loop but I must admit I'm completely lost. I tried that but it didn't work :

Union_1 = {"M0":M0, "M1":M1, "M2":M2, "M3":M3}
Union_2 = {"M4":M4, "M5":M5, "M6":M6, "M7":M7}

for i in Union_1:
    for j in Union_2:
        InFeatures = [Union_1[i], Union_2[j]]
        arcpy.Union_analysis (InFeatures, i + "_" + j + ".shp", "NO_FID", 0.0003, "")
        print "ok"

Could you help me to loop that union process ?


One way this loop could be done is the following

r = [m0, m1, m2, ..... , mN]
for n in range(0, len(r), 4):
   InFeatures = r[n:n+4]
   arcpy.Union_analysis (InFeatures, str(n) + "_" + str(n+4) + ".shp", "NO_FID", 0.0003, "")

This is if you are always looking to perform union_analysis on four sequential shape files.

Need Your Help

Select rows which have a numeric value in the first cell (Column A)

excel-vba vba excel

I am using Excel VBA to try and select a range of rows on my spread sheet which are located below the last row with a numeric value in column A. Row 40 is where I need to select from, but this loca...

There is no Broadcast on android.intent.action.SIM_STATE_CHANGED?

android android-broadcast

I have an android application which is registers with current sim card, running with my device.There is some user(current sim card) setting in the application.